From 8784d70807cac9b40e6c445b5b66c3c4675e3bc0 Mon Sep 17 00:00:00 2001 From: VetheonGames Date: Fri, 14 Jun 2024 22:59:20 -0600 Subject: [PATCH] fix filesystem --- .rspec | 3 +++ Gemfile | 12 ++++++++++++ Rakefile | 12 ++++++++++++ bin/console | 11 +++++++++++ bin/setup | 8 ++++++++ bin/todo_marker | 18 ++++++++++++++++++ lib/todo_marker.rb | 38 ++++++++++++++++++++++++++++++++++++++ lib/todo_marker/version.rb | 6 ++++++ sig/todo_marker.rbs | 4 ++++ spec/spec_helper.rb | 15 +++++++++++++++ spec/todo_marker_spec.rb | 11 +++++++++++ todo_marker.gemspec | 26 ++++++++++++++++++++++++++ 12 files changed, 164 insertions(+) create mode 100644 .rspec create mode 100644 Gemfile create mode 100644 Rakefile create mode 100755 bin/console create mode 100755 bin/setup create mode 100755 bin/todo_marker create mode 100644 lib/todo_marker.rb create mode 100644 lib/todo_marker/version.rb create mode 100644 sig/todo_marker.rbs create mode 100644 spec/spec_helper.rb create mode 100644 spec/todo_marker_spec.rb create mode 100644 todo_marker.gemspec diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..34c5164 --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--format documentation +--color +--require spec_helper diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..fc71d90 --- /dev/null +++ b/Gemfile @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +# Specify your gem's dependencies in todo_marker.gemspec +gemspec + +gem "rake", "~> 13.0" + +gem "rspec", "~> 3.0" + +gem "rubocop", "~> 1.21" diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..cca7175 --- /dev/null +++ b/Rakefile @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require "bundler/gem_tasks" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) + +require "rubocop/rake_task" + +RuboCop::RakeTask.new + +task default: %i[spec rubocop] diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..11fb2c5 --- /dev/null +++ b/bin/console @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "bundler/setup" +require "todo_marker" + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +require "irb" +IRB.start(__FILE__) diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here diff --git a/bin/todo_marker b/bin/todo_marker new file mode 100755 index 0000000..7c57c37 --- /dev/null +++ b/bin/todo_marker @@ -0,0 +1,18 @@ +# bin/todo_marker +#!/usr/bin/env ruby + +require "todo_marker" + +if ARGV.empty? + puts "Usage: todo_marker " + exit 1 +end + +directory = ARGV[0] +unless Dir.exist?(directory) + puts "Directory #{directory} does not exist" + exit 1 +end + +TodoMarker.generate_todo_md(directory) +puts "TODO.md has been generated in the #{directory} directory." diff --git a/lib/todo_marker.rb b/lib/todo_marker.rb new file mode 100644 index 0000000..340a016 --- /dev/null +++ b/lib/todo_marker.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +# lib/todo_marker.rb +require "todo_marker/version" +require "find" + +module TodoMarker + TODO_REGEX = /# !!TODO!! "(.*?)"/ + + def self.generate_todo_md(directory) + todos = [] + + Find.find(directory) do |path| + next unless path.end_with?(".rb") + + File.readlines(path).each_with_index do |line, index| + next unless line.match(TODO_REGEX) + + todos << { + message: line.match(TODO_REGEX)[1], + file: path, + line: index + 1 + } + end + end + + create_todo_file(directory, todos) + end + + def self.create_todo_file(directory, todos) + File.open(File.join(directory, "TODO.md"), "w") do |file| + file.puts "# TODO List\n\n" + todos.each do |todo| + file.puts "- #{todo[:message]} (#{todo[:file]}:#{todo[:line]})" + end + end + end +end diff --git a/lib/todo_marker/version.rb b/lib/todo_marker/version.rb new file mode 100644 index 0000000..1f84b4a --- /dev/null +++ b/lib/todo_marker/version.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +# lib/todo_marker/version.rb +module TodoMarker + VERSION = "0.1.0" +end diff --git a/sig/todo_marker.rbs b/sig/todo_marker.rbs new file mode 100644 index 0000000..c3ba94f --- /dev/null +++ b/sig/todo_marker.rbs @@ -0,0 +1,4 @@ +module TodoMarker + VERSION: String + # See the writing guide of rbs: https://github.com/ruby/rbs#guides +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..51baa61 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require "todo_marker" + +RSpec.configure do |config| + # Enable flags like --only-failures and --next-failure + config.example_status_persistence_file_path = ".rspec_status" + + # Disable RSpec exposing methods globally on `Module` and `main` + config.disable_monkey_patching! + + config.expect_with :rspec do |c| + c.syntax = :expect + end +end diff --git a/spec/todo_marker_spec.rb b/spec/todo_marker_spec.rb new file mode 100644 index 0000000..3cd2cc0 --- /dev/null +++ b/spec/todo_marker_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +RSpec.describe TodoMarker do + it "has a version number" do + expect(TodoMarker::VERSION).not_to be nil + end + + it "does something useful" do + expect(false).to eq(true) + end +end diff --git a/todo_marker.gemspec b/todo_marker.gemspec new file mode 100644 index 0000000..6413682 --- /dev/null +++ b/todo_marker.gemspec @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require_relative "lib/todo_marker/version" + +Gem::Specification.new do |spec| + spec.name = "todo_marker" + spec.version = TodoMarker::VERSION + spec.authors = ["VetheonGames"] + spec.email = ["connor@pixelridgesoftworks.com"] + + spec.summary = "Standalone gem for generating TODO.md files" + spec.description = "This standalone gem takes in source code files written in Ruby, and generates a TODO.md file from + them. + mark things to add to the TODO.md with the `# !!TODO!!` magic comment" + spec.homepage = "https://git.pixelridgesoftworks.com/PixelRidge-Softworks/Todo_Marker" + spec.license = "MIT" + spec.required_ruby_version = ">= 3.2" + + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://git.pixelridgesoftworks.com/PixelRidge-Softworks/Todo_Marker" + + spec.files = Dir["lib/**/*.rb", "bin/*"] + spec.bindir = "bin" + spec.executables = ["todo_marker"] + spec.require_paths = ["lib"] +end