Class: Ridgepole::DSLParser::Context::TableDefinition
- Inherits:
-
Object
- Object
- Ridgepole::DSLParser::Context::TableDefinition
- 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
-
#__definition ⇒ Object
readonly
Returns the value of attribute __definition.
Instance Method Summary collapse
- #column(name, type, options = {}) ⇒ Object
-
#initialize ⇒ TableDefinition
constructor
A new instance of TableDefinition.
- #references(*args) ⇒ Object (also: #belongs_to)
- #timestamps(*args) ⇒ Object
Constructor Details
#initialize ⇒ TableDefinition
Returns a new instance of TableDefinition.
12 13 14 |
# File 'lib/ridgepole/dsl_parser.rb', line 12 def initialize @__definition = {} end |
Instance Attribute Details
#__definition ⇒ Object (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, = {}) name = name.to_s @__definition[name] = { :type => type, :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) = args. polymorphic = .delete(:polymorphic) args.each do |col| column("#{col}_id", :integer, ) column("#{col}_type", :string, polymorphic.is_a?(Hash) ? polymorphic : ) unless polymorphic.nil? end end |
#timestamps(*args) ⇒ Object
47 48 49 50 51 |
# File 'lib/ridgepole/dsl_parser.rb', line 47 def (*args) = {:null => false}.merge(args.) column(:created_at, :datetime, ) column(:updated_at, :datetime, ) end |