Class: ActiveRecordSchema::Schema
- Inherits:
-
Object
- Object
- ActiveRecordSchema::Schema
- Includes:
- SchemaDiff
- Defined in:
- lib/active_record_schema/schema.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#indexes ⇒ Object
readonly
Returns the value of attribute indexes.
-
#joins ⇒ Object
readonly
Returns the value of attribute joins.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #add_field(column, type, options) ⇒ Object
- #add_index(column, options = {}) ⇒ Object
- #add_join(table, key1, key2, index = true) ⇒ Object
- #field_names ⇒ Object
-
#initialize(model) ⇒ Schema
constructor
A new instance of Schema.
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
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
10 11 12 |
# File 'lib/active_record_schema/schema.rb', line 10 def fields @fields end |
#indexes ⇒ Object (readonly)
Returns the value of attribute indexes.
10 11 12 |
# File 'lib/active_record_schema/schema.rb', line 10 def indexes @indexes end |
#joins ⇒ Object (readonly)
Returns the value of attribute joins.
10 11 12 |
# File 'lib/active_record_schema/schema.rb', line 10 def joins @joins end |
#model ⇒ Object (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, ) @fields[:"#{column}"] = Field.new(column, type, ) end |
#add_index(column, options = {}) ⇒ Object
27 28 29 |
# File 'lib/active_record_schema/schema.rb', line 27 def add_index(column, = {}) @indexes[:"#{column}"] = Index.new(column, ) 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_names ⇒ Object
19 20 21 |
# File 'lib/active_record_schema/schema.rb', line 19 def field_names fields.values.map(&:name).map(&:to_s) end |