Class: ActiveSchema::SchemaFeeder

Inherits:
InAdvanceFeeder show all
Defined in:
lib/active_schema/schema_feeder.rb

Instance Attribute Summary

Attributes inherited from Feeder

#associations_generator, #table_hub, #validations_generator

Instance Method Summary collapse

Methods inherited from InAdvanceFeeder

#model_loaded

Methods inherited from Feeder

#add_model, #dispatch_attachments, #generate_assocations, #generate_associations_between, #generate_directed_associations_between, #generate_validations, #initialize

Constructor Details

This class inherits a constructor from ActiveSchema::Feeder

Instance Method Details

#add_foreign_key(from_table, to_table, options = {}) ⇒ Object



27
28
29
30
# File 'lib/active_schema/schema_feeder.rb', line 27

def add_foreign_key(from_table, to_table, options = {})
  column = options[:column] ? options[:column] : "#{to_table.singularize}_id"
  table_hub.add_foreign_key(from_table, to_table, column)
end

#add_index(table_name, column_name, options = {}) ⇒ Object



21
22
23
24
25
# File 'lib/active_schema/schema_feeder.rb', line 21

def add_index(table_name, column_name, options = {})
  index = ::ActiveRecord::ConnectionAdapters::IndexDefinition\
    .new(table_name, options[:name], options[:unique], Array(column_name), options[:lengths])
  table_hub.add_index(table_name, index)
end

#feed {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



36
37
38
# File 'lib/active_schema/schema_feeder.rb', line 36

def feed
  yield self
end

#read(schema) ⇒ Object



32
33
34
# File 'lib/active_schema/schema_feeder.rb', line 32

def read(schema)
  FilteredSchemaReader.new(self, schema).evaluate
end