Class: Frostlake::Result

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/frostlake.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(columns, row_count, values = []) ⇒ Result

Returns a new instance of Result.



98
99
100
101
102
103
104
105
# File 'lib/frostlake.rb', line 98

def initialize(columns, row_count, values = [])
  @columns = columns
  @row_count = row_count
  @values = values
  # A Result outlives the statement that made it and can be handed between
  # threads, so the memoisation below must not be two half-built copies.
  @rows_lock = Mutex.new
end

Instance Attribute Details

#columnsObject (readonly)

values is every cell, positionally aligned with columns — the shape the wire actually delivered.



96
97
98
# File 'lib/frostlake.rb', line 96

def columns
  @columns
end

#row_countObject (readonly)

values is every cell, positionally aligned with columns — the shape the wire actually delivered.



96
97
98
# File 'lib/frostlake.rb', line 96

def row_count
  @row_count
end

#valuesObject (readonly)

values is every cell, positionally aligned with columns — the shape the wire actually delivered.



96
97
98
# File 'lib/frostlake.rb', line 96

def values
  @values
end

Instance Method Details

#each(&block) ⇒ Object



115
116
117
# File 'lib/frostlake.rb', line 115

def each(&block)
  rows.each(&block)
end

#rowsObject

Each row keyed by column name, built on first use and kept. A hash cannot represent two columns called the same thing — a self-join reports ID twice and the later one wins — so values is the lossless view. Building these lazily keeps a caller that only reads values from paying for them.



111
112
113
# File 'lib/frostlake.rb', line 111

def rows
  @rows_lock.synchronize { @rows ||= build_rows }
end