Class: DohDb::ReadOnlyRow

Inherits:
AbstractRow show all
Defined in:
lib/doh/mysql/readonly_row.rb

Instance Attribute Summary

Attributes inherited from AbstractRow

#keys, #values

Instance Method Summary collapse

Methods inherited from AbstractRow

#at, #each_pair, #empty_field?, #get, #inspect, #key?, #record_id, #size, #to_a, #to_h

Constructor Details

#initialize(*args) ⇒ ReadOnlyRow

can accept 2 arguments: keys array, values array or 1 argument: a hash



8
9
10
11
12
13
# File 'lib/doh/mysql/readonly_row.rb', line 8

def initialize(*args)
  keys, values = parse_initialize_args(*args)
  @keys = keys.freeze
  @values = values.freeze
  freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *ignore) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/doh/mysql/readonly_row.rb', line 15

def method_missing(sym, *ignore)
  key = sym.to_s
  index = @keys.index(key)
  if index
    @values.at(index)
  else
    raise RuntimeError.new("unknown field: " + key)
  end
end