Class: AnnotateRb::ModelAnnotator::ModelFilesGetter

Inherits:
Object
  • Object
show all
Defined in:
lib/annotate_rb/model_annotator/model_files_getter.rb

Class Method Summary collapse

Class Method Details

.call(options) ⇒ Object

Return a list of the model files to annotate. If we have command line arguments, they’re assumed to the path of model files from root dir. Otherwise we take all the model files in the model_dir directory.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/annotate_rb/model_annotator/model_files_getter.rb', line 11

def call(options)
  model_files = []

  # Note: This is currently broken as we don't set `is_rake` anywhere.
  # It's an artifact from the old Annotate gem and how it did control flow.
  model_files = list_model_files_from_argument(options) if !options[:is_rake]

  return model_files if !model_files.empty?

  options[:model_dir].each do |dir|
    Dir.chdir(dir) do
      list = if options[:ignore_model_sub_dir]
        Dir["*.rb"].map { |f| [dir, f] }
      else
        Dir["**/*.rb"]
          .reject { |f| f["concerns/"] }
          .map { |f| [dir, f] }
      end
      model_files.concat(list)
    end
  end

  model_files
rescue SystemCallError
  warn "No models found in directory '#{options[:model_dir].join("', '")}'."
  warn "Either specify models on the command line, or use the --model-dir option."
  warn "Call 'annotaterb --help' for more info."
  # exit 1 # TODO: Return exit code back to caller. Right now it messes up RSpec being able to run
end