class Flounder::Result::Row
Public Class Methods
new(node, row_idx)
click to toggle source
# File lib/flounder/result/row.rb, line 3 def initialize node, row_idx @root = node @row_idx = row_idx @attributes = {} end
Public Instance Methods
==(other)
click to toggle source
Calls superclass method
# File lib/flounder/result/row.rb, line 36 def == other if other.kind_of?(Row) other_root = other.instance_variable_get('@root') __columns__ == other.__columns__ && __columns__.all? { |name| my_value = self[name] other_value = other[name] my_value == other_value } else super end end
[](name)
click to toggle source
# File lib/flounder/result/row.rb, line 50 def [] name if @root.has_obj?(name) value_for(name) end end
__columns__()
click to toggle source
Returns all column names.
# File lib/flounder/result/row.rb, line 64 def __columns__ @root.names end
inspect()
click to toggle source
# File lib/flounder/result/row.rb, line 32 def inspect "flounder/Row(#{__columns__.inspect})" end
method_missing(sym, *args, &block)
click to toggle source
Primary resolution mechanism: Lazy lookup of fields.
Calls superclass method
# File lib/flounder/result/row.rb, line 11 def method_missing sym, *args, &block if @root.has_obj?(sym) return cache_attribute(sym) end if sym.to_s.end_with?(??) stripped = sym.to_s[0..-2] return @root.has_obj?(stripped) && !value_for(stripped).nil? end super end
methods(regular=true)
click to toggle source
Calls superclass method
# File lib/flounder/result/row.rb, line 28 def methods regular=true (__columns__ + super).uniq end
respond_to?(sym, include_all=false)
click to toggle source
Calls superclass method
# File lib/flounder/result/row.rb, line 23 def respond_to? sym, include_all=false @attributes.has_key?(sym) || @root.has_obj?(sym) || super end
to_h()
click to toggle source
Turns this row into a hash, performing deep conversion of all field names. Use this to go into the Hash world and never come back.
# File lib/flounder/result/row.rb, line 71 def to_h __columns__.map { |name| [name, value_for(name)] }.to_h end
values_at(*keys)
click to toggle source
Returns values of given keys as an array.
# File lib/flounder/result/row.rb, line 58 def values_at *keys keys.map { |key| self[key] } end
Private Instance Methods
cache_attribute(name)
click to toggle source
# File lib/flounder/result/row.rb, line 88 def cache_attribute name value = value_for(name) # Produce a local accessor via Virtus self.define_singleton_method(name) { value } value end
value_for(name)
click to toggle source
# File lib/flounder/result/row.rb, line 77 def value_for name if @attributes.has_key?(name) return @attributes[name] end node = @root[name] @attributes[name] = node && node.produce_value(@row_idx) { |node| Row.new(node, @row_idx) } end