Class: Pluckr::Result::Builder::Caster

Inherits:
Struct
  • Object
show all
Defined in:
lib/pluckr/result/builder.rb

Overview

Casts one column of a row. default covers SQL returning NULL where the equivalent ActiveRecord call would not: SUM over no rows is NULL in SQL and 0 in relation.sum(:column).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaultObject

Returns the value of attribute default

Returns:

  • (Object)

    the current value of default



19
20
21
# File 'lib/pluckr/result/builder.rb', line 19

def default
  @default
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



19
20
21
# File 'lib/pluckr/result/builder.rb', line 19

def type
  @type
end

Instance Method Details

#call(value) ⇒ Object



20
21
22
23
24
# File 'lib/pluckr/result/builder.rb', line 20

def call(value)
  return default if value.nil?

  type ? type.deserialize(value) : value
end