Class: Ridgepole::DSLParser::Context::TableDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/ridgepole/dsl_parser.rb

Constant Summary collapse

TYPES =
[
  :string,
  :text,
  :integer,
  :float,
  :decimal,
  :datetime,
  :timestamp,
  :time,
  :date,
  :binary,
  :boolean
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTableDefinition

Returns a new instance of TableDefinition.



12
13
14
# File 'lib/ridgepole/dsl_parser.rb', line 12

def initialize
  @__definition = {}
end

Instance Attribute Details

#__definitionObject (readonly)

Returns the value of attribute __definition.



10
11
12
# File 'lib/ridgepole/dsl_parser.rb', line 10

def __definition
  @__definition
end

Instance Method Details

#column(name, type, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/ridgepole/dsl_parser.rb', line 16

def column(name, type, options = {})
  name = name.to_s

  @__definition[name] = {
    :type => type,
    :options => options,
  }
end

#references(*args) ⇒ Object Also known as: belongs_to



53
54
55
56
57
58
59
60
# File 'lib/ridgepole/dsl_parser.rb', line 53

def references(*args)
  options = args.extract_options!
  polymorphic = options.delete(:polymorphic)
  args.each do |col|
    column("#{col}_id", :integer, options)
    column("#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : options) unless polymorphic.nil?
  end
end

#timestamps(*args) ⇒ Object



47
48
49
50
51
# File 'lib/ridgepole/dsl_parser.rb', line 47

def timestamps(*args)
  options = {:null => false}.merge(args.extract_options!)
  column(:created_at, :datetime, options)
  column(:updated_at, :datetime, options)
end