Class: Arel::Nodes::BoundSqlLiteral
- Inherits:
-
NodeExpression
- Object
- Node
- NodeExpression
- Arel::Nodes::BoundSqlLiteral
- Defined in:
- activerecord/lib/arel/nodes/bound_sql_literal.rb
Instance Attribute Summary collapse
-
#named_binds ⇒ Object
readonly
Returns the value of attribute named_binds.
-
#positional_binds ⇒ Object
readonly
Returns the value of attribute positional_binds.
-
#sql_with_placeholders ⇒ Object
readonly
Returns the value of attribute sql_with_placeholders.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(sql_with_placeholders, positional_binds, named_binds) ⇒ BoundSqlLiteral
constructor
A new instance of BoundSqlLiteral.
- #inspect ⇒ Object
Methods included from Math
#&, #*, #-, #/, #<<, #>>, #^, #|, #~@
Methods included from OrderPredications
Methods included from AliasPredication
Methods included from Predications
#between, #concat, #contains, #does_not_match, #does_not_match_all, #does_not_match_any, #does_not_match_regexp, #eq, #eq_all, #eq_any, #gt, #gt_all, #gt_any, #gteq, #gteq_all, #gteq_any, #in, #in_all, #in_any, #is_distinct_from, #is_not_distinct_from, #lt, #lt_all, #lt_any, #lteq, #lteq_all, #lteq_any, #matches, #matches_all, #matches_any, #matches_regexp, #not_between, #not_eq, #not_eq_all, #not_eq_any, #not_in, #not_in_all, #not_in_any, #overlaps, #quoted_array, #when
Methods included from Expressions
#average, #count, #extract, #maximum, #minimum, #sum
Methods inherited from Node
#and, #equality?, #fetch_attribute, #invert, #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(sql_with_placeholders, positional_binds, named_binds) ⇒ BoundSqlLiteral
Returns a new instance of BoundSqlLiteral.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 8 def initialize(sql_with_placeholders, positional_binds, named_binds) if !positional_binds.empty? && !named_binds.empty? raise BindError.new("cannot mix positional and named binds", sql_with_placeholders) elsif !positional_binds.empty? 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 !named_binds.empty? 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 !positional_binds.empty? @positional_binds = positional_binds @named_binds = nil else @positional_binds = nil @named_binds = named_binds end end |
Instance Attribute Details
#named_binds ⇒ Object (readonly)
Returns the value of attribute named_binds
6 7 8 |
# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 6 def named_binds @named_binds end |
#positional_binds ⇒ Object (readonly)
Returns the value of attribute positional_binds
6 7 8 |
# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 6 def positional_binds @positional_binds end |
#sql_with_placeholders ⇒ Object (readonly)
Returns the value of attribute sql_with_placeholders
6 7 8 |
# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 6 def sql_with_placeholders @sql_with_placeholders end |
Instance Method Details
#+(other) ⇒ Object
50 51 52 53 54 |
# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 50 def +(other) raise ArgumentError, "Expected Arel node" unless Arel.arel_node?(other) Fragments.new([self, other]) end |
#eql?(other) ⇒ Boolean Also known as: ==
42 43 44 45 46 47 |
# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 42 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 ⇒ Object
38 39 40 |
# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 38 def hash [self.class, sql_with_placeholders, positional_binds, named_binds].hash end |
#inspect ⇒ Object
56 57 58 |
# File 'activerecord/lib/arel/nodes/bound_sql_literal.rb', line 56 def inspect "#<#{self.class.name} #{sql_with_placeholders.inspect} #{(named_binds || positional_binds).inspect}>" end |