Skip to content

Commit 4db90ef

Browse files
sashabelozerovctran
authored andcommitted
[Fix #438] model_dir option should allow multiple dirs with comma as described in README
1 parent f1fe52e commit 4db90ef

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/annotate/annotate_models.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,10 +740,14 @@ def get_loaded_model(model_path)
740740
end
741741

742742
def parse_options(options = {})
743-
self.model_dir = options[:model_dir] if options[:model_dir]
743+
self.model_dir = split_model_dir(options[:model_dir]) if options[:model_dir]
744744
self.root_dir = options[:root_dir] if options[:root_dir]
745745
end
746746

747+
def split_model_dir(option_value)
748+
option_value.split(',').map(&:strip).reject(&:empty?)
749+
end
750+
747751
# We're passed a name of things that might be
748752
# ActiveRecord models. If we can find the class, and
749753
# if its a subclass of ActiveRecord::Base,

spec/annotate/annotate_models_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,31 @@ def mock_column(name, type, options = {})
7272
it { expect(AnnotateModels.quote(BigDecimal.new('1.2'))).to eql('1.2') }
7373
it { expect(AnnotateModels.quote([BigDecimal.new('1.2')])).to eql(['1.2']) }
7474

75+
describe '#parse_options' do
76+
let(:options) do
77+
{
78+
root_dir: '/root',
79+
model_dir: 'app/models,app/one, app/two ,,app/three'
80+
}
81+
end
82+
83+
it 'sets @root_dir' do
84+
AnnotateModels.send(:parse_options, options)
85+
expect(AnnotateModels.instance_variable_get(:@root_dir)).to eq('/root')
86+
end
87+
88+
it 'sets @model_dir separated with a comma' do
89+
AnnotateModels.send(:parse_options, options)
90+
expected = [
91+
'app/models',
92+
'app/one',
93+
'app/two',
94+
'app/three'
95+
]
96+
expect(AnnotateModels.instance_variable_get(:@model_dir)).to eq(expected)
97+
end
98+
end
99+
75100
it 'should get schema info with default options' do
76101
klass = mock_class(:users,
77102
:id,

0 commit comments

Comments
 (0)