class ActiveRecordSchema::Schema
Attributes
fields[R]
indexes[R]
joins[R]
model[R]
Public Class Methods
new(model)
click to toggle source
# File lib/active_record_schema/schema.rb, line 12 def initialize(model) @model = model @fields = ActiveSupport::OrderedHash.new @indexes = {} @joins = {} end
Public Instance Methods
add_field(column, type, options)
click to toggle source
# File lib/active_record_schema/schema.rb, line 39 def add_field(column, type, options) @fields[:"#{column}"] = Field.new(column, type, options) end
add_index(column, options = {})
click to toggle source
# File lib/active_record_schema/schema.rb, line 43 def add_index(column, options = {}) @indexes[:"#{column}"] = Index.new(column, options) end
add_join(table, key1, key2, index = true)
click to toggle source
# 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()
click to toggle source
# File lib/active_record_schema/schema.rb, line 35 def field_names fields.values.map(&:name).map(&:to_s) end
hierarchy_field_names()
click to toggle source
# File lib/active_record_schema/schema.rb, line 31 def hierarchy_field_names hierarchy_fields.values.map(&:name).map(&:to_s) end
hierarchy_fields()
click to toggle source
# 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