Class: Oinky::Model::Internal::SchemaBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/oinky/dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, base = {}) ⇒ SchemaBuilder

Returns a new instance of SchemaBuilder.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/oinky/dsl.rb', line 85

def initialize(name, base = {})
  @h = {}
  name = name.to_s
  # clone 2 levels deep.  tabledef, not just tableset
  base.each{|k,v|
    if v.is_a? Hash

      nv = {}
      v.each{|k2,v2|
        nv[k2] = v2.clone
      }
      @h[k] = nv
    else
      @h[k] = v
    end
  }
  @h[:name] = name
  @h[:version] ||= 1
  @h[:tables] ||= {}
end

Instance Method Details

#classname(cn) ⇒ Object



133
134
135
# File 'lib/oinky/dsl.rb', line 133

def classname(cn)
  @h[:classname] = cn
end

#create_table(tn, base = {}) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/oinky/dsl.rb', line 106

def create_table(tn, base = {})
  if tn.is_a? Hash
    base = tn
    tn = tn[:name]
  end
  tn = tn.to_s
  t = TableBuilder.new(base)
  t.name tn
  if block_given?
    t.instance_eval &Proc.new
  end
  th = t.to_h
  name = th[:name]
  th = Oinky::Model.normalize_table_schema(name, th)
  @h[:tables][name] = th
  th
end

#name(newname) ⇒ Object

override name



125
126
127
# File 'lib/oinky/dsl.rb', line 125

def name(newname)
  @h[:name] = newname.to_s
end

#to_hObject



137
138
139
# File 'lib/oinky/dsl.rb', line 137

def to_h
  @h
end

#version(v) ⇒ Object



129
130
131
# File 'lib/oinky/dsl.rb', line 129

def version(v)
  @h[:version] = v
end