Class: Torque::PostgreSQL::Arel::Nodes::Property

Inherits:
Arel::Nodes::Binary
  • Object
show all
Includes:
Arel::AliasPredication, Arel::Expressions, Arel::Math, Arel::OrderPredications, Arel::Predications
Defined in:
lib/torque/postgresql/arel/nodes.rb,
sig/torque/postgresql/arel/nodes.rbs

Overview

Accessing a single property of a document, at any depth, casted to the type that the class declares for it

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, key, type_caster, cast = nil) ⇒ Property

Reaching a property of another one simply adds up to the path, so that a single node always holds the whole way to it

Parameters:

  • source (arel_node)
  • key (path_key)
  • type_caster (type_caster, nil)
  • cast (column_ref, nil) (defaults to: nil)


63
64
65
66
67
68
69
# File 'lib/torque/postgresql/arel/nodes.rb', line 63

def initialize(source, key, type_caster, cast = nil)
  @type_caster = type_caster
  @cast = cast

  return super(source.left, source.path + [key.to_s]) if source.is_a?(Property)
  super(source, [key.to_s])
end

Instance Attribute Details

#cast ⇒ column_ref? (readonly)

Returns the value of attribute cast.

Returns:

  • (column_ref, nil)


57
58
59
# File 'lib/torque/postgresql/arel/nodes.rb', line 57

def cast
  @cast
end

#type_caster ⇒ type_caster? (readonly)

Returns the value of attribute type_caster.

Returns:



57
58
59
# File 'lib/torque/postgresql/arel/nodes.rb', line 57

def type_caster
  @type_caster
end

Instance Method Details

#able_to_type_cast? ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/torque/postgresql/arel/nodes.rb', line 75

def able_to_type_cast?
  true
end

#name ⇒ String

Returns:

  • (String)


71
72
73
# File 'lib/torque/postgresql/arel/nodes.rb', line 71

def name
  right.last
end

#type_cast_for_database(value) ⇒ Object

Parameters:

  • value (Object)

Returns:

  • (Object)


79
80
81
# File 'lib/torque/postgresql/arel/nodes.rb', line 79

def type_cast_for_database(value)
  type_caster.serialize(value)
end