Class: Arel::Nodes::BoundSqlLiteral
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
NodeExpression ,
Node
|
|
Instance Chain:
|
|
Inherits: |
Arel::Nodes::NodeExpression
|
Defined in: | activerecord/lib/arel/nodes/bound_sql_literal.rb |
Class Method Summary
Instance Attribute Summary
- #named_binds readonly
- #positional_binds readonly
- #sql_with_placeholders readonly
Node
- Inherited
Instance Method Summary
- #+(other)
-
#==(other)
Alias for #eql?.
- #eql?(other) ⇒ Boolean (also: #==)
- #hash
- #inspect
::Arel::Math
- Included
::Arel::OrderPredications
- Included
::Arel::AliasPredication
- Included
::Arel::Predications
- Included
::Arel::Expressions
- Included
Node
- Inherited
#and | Factory method to create an And node. |
#fetch_attribute, #invert, | |
#not | Factory method to create a |
#or | |
#to_sql | FIXME: this method should go away. |
::Arel::FactoryMethods
- Included
#cast, #coalesce, #create_and, #create_false, #create_join, #create_on, #create_string_join, #create_table_alias, #create_true, #grouping, | |
#lower | Create a LOWER() function. |
Constructor Details
.new(sql_with_placeholders, positional_binds, named_binds) ⇒ BoundSqlLiteral
# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 8
def initialize(sql_with_placeholders, positional_binds, named_binds) has_positional = !(positional_binds.nil? || positional_binds.empty?) has_named = !(named_binds.nil? || named_binds.empty?) if has_positional if has_named raise BindError.new("cannot mix positional and named binds", sql_with_placeholders) end if positional_binds.size != (expected = sql_with_placeholders.count("?")) raise BindError.new("wrong number of bind variables (#{positional_binds.size} for #{expected})", sql_with_placeholders) end elsif has_named tokens_in_string = sql_with_placeholders.scan(/:(?<!::)([a-zA-Z]\w*)/).flatten.map(&:to_sym).uniq tokens_in_hash = named_binds.keys.map(&:to_sym).uniq if !(missing = (tokens_in_string - tokens_in_hash)).empty? if missing.size == 1 raise BindError.new("missing value for #{missing.first.inspect}", sql_with_placeholders) else raise BindError.new("missing values for #{missing.inspect}", sql_with_placeholders) end end end @sql_with_placeholders = sql_with_placeholders if has_positional @positional_binds = positional_binds @named_binds = nil else @positional_binds = nil @named_binds = named_binds end end
Instance Attribute Details
#named_binds (readonly)
[ GitHub ]# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 6
attr_reader :sql_with_placeholders, :positional_binds, :named_binds
#positional_binds (readonly)
[ GitHub ]# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 6
attr_reader :sql_with_placeholders, :positional_binds, :named_binds
#sql_with_placeholders (readonly)
[ GitHub ]# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 6
attr_reader :sql_with_placeholders, :positional_binds, :named_binds
Instance Method Details
#+(other)
# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 54
def +(other) raise ArgumentError, "Expected Arel node" unless Arel.arel_node?(other) Fragments.new([self, other]) end
#==(other)
Alias for #eql?.
# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 52
alias :== :eql?
#eql?(other) ⇒ Boolean
Also known as: #==
# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 46
def eql?(other) self.class == other.class && sql_with_placeholders == other.sql_with_placeholders && positional_binds == other.positional_binds && named_binds == other.named_binds end
#hash
[ GitHub ]# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 42
def hash [self.class, sql_with_placeholders, positional_binds, named_binds].hash end
#inspect
[ GitHub ]# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 60
def inspect "#<#{self.class.name} #{sql_with_placeholders.inspect} #{(named_binds || positional_binds).inspect}>" end