module ActiveRecordSchema::Dsl::ClassMethods

Public Instance Methods

add_index(column_name, options = {})
Alias for: index
belongs_to(name, options = {}) click to toggle source
Calls superclass method
# File lib/active_record_schema/dsl.rb, line 27
def belongs_to(name, options = {})
  options.symbolize_keys!
  skip_index = options.delete(:index) == false
      
  foreign_key  = options[:foreign_key] || "#{name}_id"
  field :"#{foreign_key}", :as => :integer
      
  if options[:polymorphic]
    foreign_type = options[:foreign_type] || "#{name}_type"
    field :"#{foreign_type}"
    add_index [:"#{foreign_key}", :"#{foreign_type}"] if !skip_index
  else
    add_index :"#{foreign_key}" if !skip_index
  end
      
  super(name, options)
end
field(name, *args) click to toggle source

field :name, :string, :default => “Joe”

# File lib/active_record_schema/dsl.rb, line 14
def field(name, *args)
  options    = args.extract_options!
  type       = options.delete(:as) || options.delete(:type) || args.first || :string
  type       = type.name.underscore.to_sym if (type.class == Class) 
  index      = options.delete(:index)
  
  schema.add_field(name, type, options)

  if index
    schema.add_index(name)
  end       
end
has_and_belongs_to_many(name, options = {}, &extension) click to toggle source
Calls superclass method
# File lib/active_record_schema/dsl.rb, line 45
def has_and_belongs_to_many(name, options = {}, &extension)
  options.symbolize_keys!

  self_class_name = self.name
  association_class_name = options[:class_name] || "#{name}".singularize.camelize

  table = options[:join_table] || [self_class_name, association_class_name].sort.map(&:tableize).join("_")
  key1  = options[:foreign_key] || "#{self_class_name.underscore}_id"
  key2  = options[:association_foreign_key] || "#{association_class_name.underscore}_id"
  skip_index = options.delete(:index) == false

  schema.add_join(table, key1, key2, !skip_index)
  super(name, options, &extension)
end
index(column_name, options = {}) click to toggle source
# File lib/active_record_schema/dsl.rb, line 60
def index(column_name, options = {})
  schema.add_index(column_name, options)
end
Also aliased as: add_index
inheritable() click to toggle source
# File lib/active_record_schema/dsl.rb, line 70
def inheritable
  field :"#{inheritance_column}"
end
schema() click to toggle source
# File lib/active_record_schema/dsl.rb, line 8
def schema
  @active_record_schema_schema ||= ActiveRecordSchema::Schema.new(self)
  
end
timestamps() click to toggle source
# File lib/active_record_schema/dsl.rb, line 65
def timestamps
  field :created_at, :datetime
  field :updated_at, :datetime
end