class Flounder::Result::Descriptor

Attributes

accessor_root[R]

Root of the accessor tree. @api private

connection[R]
entity[R]

Entity to use for field resolution

name_resolver[R]

@api private

pg_result[R]

Result obtained from the connection

Public Class Methods

new(connection, entity, pg_result, &name_resolver) click to toggle source
# File lib/flounder/result/descriptor.rb, line 21
def initialize connection, entity, pg_result, &name_resolver
  @entity = entity
  @pg_result = pg_result
  @connection = connection
  @name_resolver = name_resolver || -> (name) {}

  build_accessors
end

Public Instance Methods

build_accessors() click to toggle source

Parses and builds accessor structure for the result stored here.

@api private

# File lib/flounder/result/descriptor.rb, line 42
def build_accessors
  @accessor_root = Accessor::Node.new
  each_field(entity, pg_result) do |idx, entity, field, type, binary|
    processed_entity, processed_name = name_resolver.call(field)
    entity = processed_entity if processed_entity
    field  = processed_name if processed_name

    # JOIN tables are available from the result using their singular names.
    if entity
      accessor_root[entity.singular].add_field(field, self, idx, type)
    end

    # The main entity and custom fields (AS something) are available on the
    # top-level of the result.
    if field && (!entity || entity == self.entity)
      raise ::Flounder::DuplicateField, 
        "#{field.inspect} already defined in result set, aliasing occurs." \
        if accessor_root.has_obj? field

      accessor_root.add_field(field, self, idx, type)
    end

  end
end
row(idx) click to toggle source
# File lib/flounder/result/descriptor.rb, line 30
def row idx
  Row.new(accessor_root, idx)
end
value(type, row_idx, col_idx) click to toggle source
# File lib/flounder/result/descriptor.rb, line 34
def value type, row_idx, col_idx
  access_value(connection, pg_result, type, row_idx, col_idx)
end