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
- #hierarchy_field_names ⇒ Object
- #hierarchy_fields ⇒ 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_exists?, #_table, #_table_exists?, #_table_names, #diff, #nothing_to_do?, #prefixed_table_name, #table_exists?
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 = ActiveSupport::OrderedHash.new @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
39 40 41 |
# File 'lib/active_record_schema/schema.rb', line 39 def add_field(column, type, ) @fields[:"#{column}"] = Field.new(column, type, ) end |
#add_index(column, options = {}) ⇒ Object
43 44 45 |
# File 'lib/active_record_schema/schema.rb', line 43 def add_index(column, = {}) @indexes[:"#{column}"] = Index.new(column, ) end |
#add_join(table, key1, key2, index = true) ⇒ Object
47 48 49 |
# File 'lib/active_record_schema/schema.rb', line 47 def add_join(table, key1, key2, index = true) @joins[:"#{table}"] = Join.new(table, key1, key2) end |
#field_names ⇒ Object
35 36 37 |
# File 'lib/active_record_schema/schema.rb', line 35 def field_names fields.values.map(&:name).map(&:to_s) end |
#hierarchy_field_names ⇒ Object
31 32 33 |
# File 'lib/active_record_schema/schema.rb', line 31 def hierarchy_field_names hierarchy_fields.values.map(&:name).map(&:to_s) end |
#hierarchy_fields ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_record_schema/schema.rb', line 19 def hierarchy_fields if @hierarchy_fields @hierarchy_fields else @hierarchy_fields ||= ActiveSupport::OrderedHash.new model.ancestors.select { |c| c < ActiveRecord::Base }.reverse_each do |klass| @hierarchy_fields = @hierarchy_fields.merge(klass.schema.fields) end @hierarchy_fields end end |