Class: ActiveRecordSchema::Schema

Inherits:
Object
  • Object
show all
Includes:
SchemaDiff
Defined in:
lib/active_record_schema/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SchemaDiff

#_column_names, #_connection, #_diff_fields_add, #_diff_indexes_add, #_diff_joins_add, #_index_names, #_table, #_table_names, #diff

Constructor Details

#initialize(model) ⇒ Schema

Returns a new instance of Schema.



12
13
14
15
16
17
# File 'lib/active_record_schema/schema.rb', line 12

def initialize(model)
  @model   = model
  @fields  = {}
  @indexes = {}
  @joins   = {}
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



10
11
12
# File 'lib/active_record_schema/schema.rb', line 10

def fields
  @fields
end

#indexesObject (readonly)

Returns the value of attribute indexes.



10
11
12
# File 'lib/active_record_schema/schema.rb', line 10

def indexes
  @indexes
end

#joinsObject (readonly)

Returns the value of attribute joins.



10
11
12
# File 'lib/active_record_schema/schema.rb', line 10

def joins
  @joins
end

#modelObject (readonly)

Returns the value of attribute model.



10
11
12
# File 'lib/active_record_schema/schema.rb', line 10

def model
  @model
end

Instance Method Details

#add_field(column, type, options) ⇒ Object



23
24
25
# File 'lib/active_record_schema/schema.rb', line 23

def add_field(column, type, options)
  @fields[:"#{column}"]  = Field.new(column, type, options)
end

#add_index(column, options = {}) ⇒ Object



27
28
29
# File 'lib/active_record_schema/schema.rb', line 27

def add_index(column, options = {})
  @indexes[:"#{column}"] = Index.new(column, options)
end

#add_join(table, key1, key2, index = true) ⇒ Object



31
32
33
# File 'lib/active_record_schema/schema.rb', line 31

def add_join(table, key1, key2, index = true)
  @joins[:"#{table}"] = Join.new(table, key1, key2) 
end

#field_namesObject



19
20
21
# File 'lib/active_record_schema/schema.rb', line 19

def field_names
  fields.values.map(&:name).map(&:to_s)
end