Class: Frostlake::Result
- Inherits:
-
Object
- Object
- Frostlake::Result
- Includes:
- Enumerable
- Defined in:
- lib/frostlake.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
values is every cell, positionally aligned with columns — the shape the wire actually delivered.
-
#row_count ⇒ Object
readonly
values is every cell, positionally aligned with columns — the shape the wire actually delivered.
-
#values ⇒ Object
readonly
values is every cell, positionally aligned with columns — the shape the wire actually delivered.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(columns, row_count, values = []) ⇒ Result
constructor
A new instance of Result.
-
#rows ⇒ Object
Each row keyed by column name, built on first use and kept.
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
#columns ⇒ Object (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_count ⇒ Object (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 |
#values ⇒ Object (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 |
#rows ⇒ Object
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 |