Class: Arel::Nodes::HomogeneousIn

Inherits:
Node
  • Object
show all
Defined in:
lib/arel/nodes/homogeneous_in.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#and, #not, #or, #to_sql

Methods included from FactoryMethods

#cast, #coalesce, #create_and, #create_false, #create_join, #create_on, #create_string_join, #create_table_alias, #create_true, #grouping, #lower

Constructor Details

#initialize(values, attribute, type) ⇒ HomogeneousIn

Returns a new instance of HomogeneousIn.



8
9
10
11
12
# File 'lib/arel/nodes/homogeneous_in.rb', line 8

def initialize(values, attribute, type)
  @values = values
  @attribute = attribute
  @type = type
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



6
7
8
# File 'lib/arel/nodes/homogeneous_in.rb', line 6

def attribute
  @attribute
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/arel/nodes/homogeneous_in.rb', line 6

def type
  @type
end

#valuesObject (readonly)

Returns the value of attribute values.



6
7
8
# File 'lib/arel/nodes/homogeneous_in.rb', line 6

def values
  @values
end

Instance Method Details

#casted_valuesObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/arel/nodes/homogeneous_in.rb', line 39

def casted_values
  type = attribute.type_caster

  casted_values = values.map do |raw_value|
    type.serialize(raw_value) if type.serializable?(raw_value)
  end

  casted_values.compact!
  casted_values
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


18
19
20
# File 'lib/arel/nodes/homogeneous_in.rb', line 18

def eql?(other)
  super || (self.class == other.class && self.ivars == other.ivars)
end

#equality?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/arel/nodes/homogeneous_in.rb', line 23

def equality?
  type == :in
end

#fetch_attribute(&block) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/arel/nodes/homogeneous_in.rb', line 54

def fetch_attribute(&block)
  if attribute
    yield attribute
  else
    expr.fetch_attribute(&block)
  end
end

#hashObject



14
15
16
# File 'lib/arel/nodes/homogeneous_in.rb', line 14

def hash
  ivars.hash
end

#invertObject



27
28
29
# File 'lib/arel/nodes/homogeneous_in.rb', line 27

def invert
  Arel::Nodes::HomogeneousIn.new(values, attribute, type == :in ? :notin : :in)
end

#leftObject



31
32
33
# File 'lib/arel/nodes/homogeneous_in.rb', line 31

def left
  attribute
end

#proc_for_bindsObject



50
51
52
# File 'lib/arel/nodes/homogeneous_in.rb', line 50

def proc_for_binds
  -> value { ActiveModel::Attribute.with_cast_value(attribute.name, value, ActiveModel::Type.default_value) }
end

#rightObject



35
36
37
# File 'lib/arel/nodes/homogeneous_in.rb', line 35

def right
  attribute.quoted_array(values)
end