Sha256: b1f0f34a6e6fb7a0ee1d05c3635baabd72ec4def5da3f3ae1984253eec6248ee

Contents?: true

Size: 843 Bytes

Versions: 17

Compression:

Stored size: 843 Bytes

Contents

require 'active_record_schema/field'
require 'active_record_schema/index'
require 'active_record_schema/join'
require 'active_record_schema/schema_diff'

module ActiveRecordSchema
  class Schema
    include ActiveRecordSchema::SchemaDiff

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

    def field_names
      fields.values.map(&:name).map(&:to_s)
    end
    
    def add_field(column, type, options)
      @fields[:"#{column}"]  = Field.new(column, type, options)
    end

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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
active_record_schema-0.5.6 lib/active_record_schema/schema.rb
active_record_schema-0.5.5 lib/active_record_schema/schema.rb
active_record_schema-0.5.4 lib/active_record_schema/schema.rb
active_record_schema-0.5.3 lib/active_record_schema/schema.rb
active_record_schema-0.5.2 lib/active_record_schema/schema.rb
active_record_schema-0.5.1 lib/active_record_schema/schema.rb
active_record_schema-0.5.0 lib/active_record_schema/schema.rb
active_record_schema-0.4.0 lib/active_record_schema/schema.rb
active_record_schema-0.3.5 lib/active_record_schema/schema.rb
active_record_schema-0.3.4 lib/active_record_schema/schema.rb
active_record_schema-0.3.3 lib/active_record_schema/schema.rb
active_record_schema-0.3.2 lib/active_record_schema/schema.rb
active_record_schema-0.2.5 lib/active_record_schema/schema.rb
active_record_schema-0.2.4 lib/active_record_schema/schema.rb
active_record_schema-0.2.2 lib/active_record_schema/schema.rb
active_record_schema-0.2.1 lib/active_record_schema/schema.rb
active_record_schema-0.2.0 lib/active_record_schema/schema.rb