Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Additional options that work for annotating models and routes
--exclude Do not annotate fixtures, test files, factories, and/or serializers
-f [bare|rdoc|yard|markdown], Render Schema Information as plain/RDoc/Yard/Markdown
--format
--config_path [path] Path to configuration file (by default, .annotaterb.yml in the root of the project)
-p [before|top|after|bottom], Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)
--position
--pc, --position-in-class [before|top|after|bottom]
Expand Down
6 changes: 5 additions & 1 deletion lib/annotate_rb/config_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ class ConfigFinder
DOTFILE = ".annotaterb.yml"

class << self
attr_accessor :config_path

def find_project_root
# We should expect this method to be called from a Rails project root and returning it
# e.g. "/Users/drwl/personal/annotaterb/dummyapp"
Dir.pwd
end

def find_project_dotfile
return @config_path if @config_path && File.exist?(@config_path)

file_path = File.expand_path(DOTFILE, find_project_root)

return file_path if File.exist?(file_path)
file_path if File.exist?(file_path)
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/annotate_rb/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength
"Render Schema Information as plain/RDoc/Yard/Markdown") do |format_type|
@options["format_#{format_type}".to_sym] = true
end

option_parser.on("--config-path [path]",
"Path to configuration file (by default, .annotaterb.yml in the root of the project)") do |path|
@options[:config_path] = path
end
end
end
end
14 changes: 7 additions & 7 deletions lib/annotate_rb/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ def run(args)
end

def run(args)
config_file_options = ConfigLoader.load_config
parser = Parser.new(args, {})

parsed_options = parser.parse
remaining_args = parser.remaining_args

AnnotateRb::ConfigFinder.config_path = parsed_options[:config_path] if parsed_options[:config_path]
config_file_options = ConfigLoader.load_config
options = config_file_options.merge(parsed_options)

@options = Options.from(options, {working_args: remaining_args})
AnnotateRb::RakeBootstrapper.call(@options)

if @options[:command]
@options[:command].call(@options)
else
# TODO
raise "Didn't specify a command"
end
raise "Didn't specify a command" unless @options[:command]

@options[:command].call(@options)

# TODO
end
end
end
2 changes: 2 additions & 0 deletions lib/generators/annotate_rb/hook/templates/annotate_rb.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
if Rails.env.development? && ENV["ANNOTATERB_SKIP_ON_DB_TASKS"].nil?
require "annotate_rb"

# Can modify the config path here if needed - by default, it's .annotaterb.yml in the root of the project
# AnnotateRb::ConfigFinder.config_path = ""
AnnotateRb::Core.load_rake_tasks
end
33 changes: 33 additions & 0 deletions spec/lib/annotate_rb/config_finder_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

RSpec.describe AnnotateRb::ConfigFinder do
describe ".find_project_dotfile" do
subject { described_class.find_project_dotfile }

context "when the config path directory is set" do
before {
allow(File).to receive(:exist?).and_return(true)
described_class.config_path = "spec/fixtures/.annotaterb.yml"
}
after { described_class.config_path = nil }

it "returns the config path" do
expect(subject).to eq("spec/fixtures/.annotaterb.yml")
end
end

context "when the config path directory is not set" do
before { allow(File).to receive(:exist?).and_return(true) }

it "returns the default dotfile path" do
expect(subject).to eq(File.expand_path(".annotaterb.yml", Dir.pwd))
end
end

context "when the config path directory is not set and the dotfile does not exist" do
it "returns nil" do
expect(subject).to be_nil
end
end
end
end
9 changes: 9 additions & 0 deletions spec/lib/annotate_rb/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,15 @@ module AnnotateRb # rubocop:disable Metrics/ModuleLength
end
end

describe "--config-path" do
let(:option) { "--config-path=../annotaterb.yml" }
let(:args) { [option] }

it "sets config_path to the path" do
expect(result).to include(config_path: "../annotaterb.yml")
end
end

describe "--nested-position" do
let(:option) { "--nested-position" }
let(:args) { [option] }
Expand Down
Loading