Class: Effective::Annotator

Inherits:
Object
  • Object
show all
Defined in:
app/models/effective/annotator.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource: 'All', folders: 'app/models/') ⇒ Annotator

Returns a new instance of Annotator.



5
6
7
8
# File 'app/models/effective/annotator.rb', line 5

def initialize(resource: 'All', folders: 'app/models/')
  @resources = Array(resource).map { |resource| resource.to_s.classify }
  @folders = Array(folders)
end

Instance Method Details

#annotate!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/effective/annotator.rb', line 10

def annotate!
  @folders.each do |folder|
    Dir.glob(folder + '**/*').each do |path|
      next if File.directory?(path)

      name = path.sub(folder, '').split('.')[0...-1].join('.')
      resource = Effective::Resource.new(name)
      klass = resource.klass

      next if klass.blank?
      next unless klass.ancestors.include?(ActiveRecord::Base)
      next if klass.abstract_class?
      next unless @resources.include?('All') || @resources.include?(klass.name)

      annotate(resource, path)
    end
  end

  puts 'All Done. Have a great day.'
  true
end