Class: Ratbug::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/ratbug/runner.rb

Class Method Summary collapse

Class Method Details

.execute(table_names, options) ⇒ Object

Parameters:



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
# File 'lib/ratbug/runner.rb', line 12

def execute(table_names, options)
  unless defined? Rails
    fail 'this gem is to be used in rails context'
  end
  # scan schema
  monkey = eval(File.open(Rails.root.join('db', 'schema.rb')).read)
  tables = monkey.tables.slice(*table_names)
  tables.values.each do |table|
    unless options[:use_only_schema]
      model = table_name_to_model(table.name, options[:table_name_to_model_converter])
      if model.present?
        table.load_enums(model)
        table.load_presence_validators(model)
      end
    end

    if options[:enabled_outputs].include?('jbuilder')
      Ratbug::Generators::JbuilderGenerator.new(table, options).generate
    end

    if options[:enabled_outputs].include?('typescript')
      Ratbug::Generators::TypescriptGenerator.new(table, options).generate
    end
  end
end