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

#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



47
48
49
50
51
52
53
54
55
56
# File 'lib/arel/nodes/homogeneous_in.rb', line 47

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

#column_nameObject



43
44
45
# File 'lib/arel/nodes/homogeneous_in.rb', line 43

def column_name
  attribute.name
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



62
63
64
65
66
67
68
# File 'lib/arel/nodes/homogeneous_in.rb', line 62

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



58
59
60
# File 'lib/arel/nodes/homogeneous_in.rb', line 58

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

#rightObject



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

def right
  attribute.quoted_array(values)
end

#table_nameObject



39
40
41
# File 'lib/arel/nodes/homogeneous_in.rb', line 39

def table_name
  attribute.relation.table_alias || attribute.relation.name
end