Class: Terrazine::Result

Inherits:
Row
  • Object
show all
Defined in:
lib/terrazine/result.rb

Overview

inheritance from row for delegation methods to first row… may be method missing?

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Row

#method_missing, #respond_to_missing?, #to_h

Constructor Details

#initialize(result, options) ⇒ Result

TODO: as arguments keys, values and options? Future support of another db? arguments - PG::Result instance and hash of options



41
42
43
44
45
46
47
48
49
50
# File 'lib/terrazine/result.rb', line 41

def initialize(result, options)
  # how another db parsing data?
  TypeMap.update(result, options[:types]) if options[:types]

  @options = options
  @fields = result.fields
  @rows = []
  result.each_row { |i| @rows << Row.new(self, i) }
  result.clear # they advise to clear it, but maybe better to use it until presenter?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Terrazine::Row

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



37
38
39
# File 'lib/terrazine/result.rb', line 37

def fields
  @fields
end

#optionsObject (readonly)

Returns the value of attribute options.



37
38
39
# File 'lib/terrazine/result.rb', line 37

def options
  @options
end

#rowsObject (readonly)

Returns the value of attribute rows.



37
38
39
# File 'lib/terrazine/result.rb', line 37

def rows
  @rows
end

Instance Method Details

#pg_resultObject



62
63
64
# File 'lib/terrazine/result.rb', line 62

def pg_result
  self
end

#present(o = {}) ⇒ Object



52
53
54
55
# File 'lib/terrazine/result.rb', line 52

def present(o = {})
  options = @options[:presenter_options] ? o.merge(@options[:presenter_options]) : o
  Presenter.present(self, options)
end

#valuesObject

ResultRow inheritance support



58
59
60
# File 'lib/terrazine/result.rb', line 58

def values
  first&.values
end