Class: Oinky::Model::Internal::TableBuilder
- Inherits:
-
Object
- Object
- Oinky::Model::Internal::TableBuilder
- Defined in:
- lib/oinky/dsl.rb
Instance Method Summary collapse
- #accessor(a) ⇒ Object
- #add_column(colname, type, h = {}) ⇒ Object
- #add_index(name, id = {:name=>name, :unique=>true, :columns=>[]}) ⇒ Object
-
#initialize(base = {}) ⇒ TableBuilder
constructor
A new instance of TableBuilder.
-
#name(newname) ⇒ Object
override name.
- #to_h ⇒ Object
Constructor Details
#initialize(base = {}) ⇒ TableBuilder
Returns a new instance of TableBuilder.
44 45 46 47 |
# File 'lib/oinky/dsl.rb', line 44 def initialize(base = {}) base = {:columns=>{}, :indices=>{}}.merge(base) @h = {:columns=>base[:columns].clone, :indices=>base[:indices].clone} end |
Instance Method Details
#accessor(a) ⇒ Object
79 80 81 |
# File 'lib/oinky/dsl.rb', line 79 def accessor(a) @h[:accessor] = a.to_s end |
#add_column(colname, type, h = {}) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/oinky/dsl.rb', line 53 def add_column(colname, type, h = {}) v = {:type=>type}.merge(h) k = colname.to_s v = Oinky::Model.normalize_column_def(k,v) @h[:columns][k] = v end |
#add_index(name, id = {:name=>name, :unique=>true, :columns=>[]}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/oinky/dsl.rb', line 59 def add_index(name, id = {:name=>name, :unique=>true, :columns=>[]}) k = name if block_given? s = IndexBuilder.new(name, id) s.instance_eval &Proc.new id = s.to_h k = id[:name] end id = Oinky::Model.normalize_index_def(k,id) id.delete(:name) @h[:indices][k] = id end |
#name(newname) ⇒ Object
override name
76 77 78 |
# File 'lib/oinky/dsl.rb', line 76 def name(newname) @h[:name] = newname.to_s end |
#to_h ⇒ Object
71 72 73 |
# File 'lib/oinky/dsl.rb', line 71 def to_h @h end |