omf_oml 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,7 +50,10 @@ module OMF::OML
50
50
  # Return the col name at a specific index
51
51
  #
52
52
  def name_at(index)
53
- @schema[index][:name]
53
+ unless d = @schema[index]
54
+ raise "Index '#{index}' out of bounds"
55
+ end
56
+ d[:name]
54
57
  end
55
58
 
56
59
  # Return the col index for column named +name+
@@ -143,23 +146,27 @@ module OMF::OML
143
146
  end
144
147
 
145
148
  # Translate a record described in a hash of 'col_name => value'
146
- # to a row array
149
+ # to a row array. Note: Will suppress column '__id__'
147
150
  #
148
151
  # hrow - Hash describing a row
149
152
  # set_nil_when_missing - If true, set any columns not described in hrow to nil
150
153
  #
151
154
  def hash_to_row(hrow, set_nil_when_missing = false, call_type_conversion = true)
152
155
  #puts "HASH2A => #{hrow.inspect}"
156
+ remove_first_col = false
153
157
  r = @schema.collect do |cdescr|
154
158
  cname = cdescr[:name]
155
- next nil if cname == :__id__
159
+ if cname == :__id__
160
+ remove_first_col = true
161
+ next nil
162
+ end
156
163
  unless (v = hrow[cname]) || (v = hrow[cname.to_sym])
157
164
  next nil if set_nil_when_missing
158
165
  raise "Missing record element '#{cname}' in record '#{hrow}'"
159
166
  end
160
167
  call_type_conversion ? cdescr[:type_conversion].call(v) : v
161
168
  end
162
- r.shift # remove __id__ columns
169
+ r.shift if remove_first_col # remove __id__ columns
163
170
  #puts "#{r.inspect} -- #{@schema.map {|c| c[:name]}.inspect}"
164
171
  r
165
172
  end
@@ -187,6 +194,12 @@ module OMF::OML
187
194
  describe.to_json(*opt)
188
195
  end
189
196
 
197
+ def clone()
198
+ c = self.dup
199
+ c.instance_variable_set('@schema', @schema.clone)
200
+ c
201
+ end
202
+
190
203
  protected
191
204
 
192
205
  # schema_description - Array containing [name, type*] for every column in table
@@ -50,7 +50,14 @@ module OMF::OML
50
50
  # by it's name, or its col index
51
51
  #
52
52
  def [](name_or_index)
53
- @vprocs[name_or_index].call(@raw)
53
+ if name_or_index.is_a? Integer
54
+ @row[@schema.name_at_index(name_or_index)]
55
+ else
56
+ unless @row.key? name_or_index
57
+ raise "Unknown column name '#{name_or_index}'"
58
+ end
59
+ @row[name_or_index]
60
+ end
54
61
  end
55
62
 
56
63
  # Return the elements of the vector as an array
@@ -180,7 +187,7 @@ module OMF::OML
180
187
  {:name => name, :type => opts[:db_type]}
181
188
  end
182
189
  # Query we are using is adding the 'oml_sender_name' to the front of the table
183
- sd.insert(0, :name => 'oml_sender', :type => :string)
190
+ sd.insert(0, :name => :oml_sender, :type => :string)
184
191
  OmlSchema.new(sd)
185
192
  end
186
193
 
@@ -191,6 +198,7 @@ module OMF::OML
191
198
  schema.each_column do |col|
192
199
  name = col[:name]
193
200
  j = i + 0
201
+ puts "SCHEMA: '#{name.inspect}'-#{j}"
194
202
  l = @vprocs[name] = lambda do |r| r[j] end
195
203
  @vprocs[i - 4] = l if i > 4
196
204
  i += 1
@@ -1,6 +1,6 @@
1
1
 
2
2
  module OMF
3
3
  module OML
4
- VERSION = '0.9.4'
4
+ VERSION = '0.9.5'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omf_oml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: