Class: AnnotateModel::Finder
- Inherits:
-
Object
- Object
- AnnotateModel::Finder
- Defined in:
- lib/annotate_model/finder.rb
Class Method Summary collapse
- .all_model_files ⇒ Object
- .find_model_file(model_name) ⇒ Object
- .find_model_file!(model_name) ⇒ Object
- .model_files!(model_names) ⇒ Object
Class Method Details
.all_model_files ⇒ Object
9 10 11 12 13 14 |
# File 'lib/annotate_model/finder.rb', line 9 def self.all_model_files files = Dir.glob(Rails.root.join("app", "models", "**", "*.rb")).reject { |file_path| file_path.include?('application_record.rb') } files.map do |file| ModelFile.new(Pathname.new(file)) end end |
.find_model_file(model_name) ⇒ Object
16 17 18 19 |
# File 'lib/annotate_model/finder.rb', line 16 def self.find_model_file(model_name) model_path = Rails.root.join("app", "models", "#{model_name.underscore}.rb") ModelFile.new(model_path) if File.exist?(model_path) end |
.find_model_file!(model_name) ⇒ Object
21 22 23 |
# File 'lib/annotate_model/finder.rb', line 21 def self.find_model_file!(model_name) find_model_file(model_name) || raise(ModelFileNotFoundError, "#{model_name}") end |
.model_files!(model_names) ⇒ Object
3 4 5 6 7 |
# File 'lib/annotate_model/finder.rb', line 3 def self.model_files!(model_names) model_names.map do |model_name| find_model_file!(model_name) end end |