Class: SeparateHistory::Generators::ScanGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/separate_history/scan/scan_generator.rb

Instance Method Summary collapse

Instance Method Details

#scan_modelsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/generators/separate_history/scan/scan_generator.rb', line 8

def scan_models
  Rails.application.eager_load!
  models = ActiveRecord::Base.descendants.select do |model|
    model.respond_to?(:separate_history_options)
  end

  if models.any?
    say "Models with has_separate_history:", :green
    models.each do |m|
      say "- #{m.name}", :cyan
      options = m.separate_history_options
      events = options[:events] || []
      if events.any?
        say "  Supported events: #{events.join(", ")}", :magenta
      else
        say "  Supported events: (none specified) [default is all]", :yellow
      end
    end
  else
    say "No models found with has_separate_history.", :yellow
  end
end