Class: Pluckr::Result::Builder
- Inherits:
-
Object
- Object
- Pluckr::Result::Builder
- Defined in:
- lib/pluckr/result/builder.rb
Overview
Turns one flat database row into nested result objects.
Result classes and per-column casters are built once per schema level when the builder is created, so hydration itself is hash lookups plus a cast.
Defined Under Namespace
Classes: Caster
Constant Summary collapse
- BOOLEAN =
ActiveModel::Type::Boolean.new
- INTEGER =
ActiveModel::Type::Integer.new
- DECIMAL =
AVG of an integer column is not an integer; ActiveRecord answers a BigDecimal here and so does Pluckr.
ActiveRecord::Type::Decimal.new
Instance Method Summary collapse
- #build(row) ⇒ Object
-
#initialize(schema, label: "Pluckr::Result") ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(schema, label: "Pluckr::Result") ⇒ Builder
Returns a new instance of Builder.
27 28 29 30 31 32 |
# File 'lib/pluckr/result/builder.rb', line 27 def initialize(schema, label: "Pluckr::Result") @schema = schema @classes = {} @casters = {} prepare(schema, label) end |
Instance Method Details
#build(row) ⇒ Object
35 36 37 |
# File 'lib/pluckr/result/builder.rb', line 35 def build(row) hydrate(@schema, [], row) end |