1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Extract Arel.arel_node? helper method

This commit is contained in:
Ryuta Kamizono 2018-09-28 04:53:43 +09:00
parent ae406cd633
commit d0d1cd3d45
3 changed files with 7 additions and 4 deletions

View file

@ -194,9 +194,7 @@ module ActiveRecord
def disallow_raw_sql!(args, permit: COLUMN_NAME) # :nodoc:
unexpected = args.reject do |arg|
arg.kind_of?(Arel::Node) ||
arg.is_a?(Arel::Nodes::SqlLiteral) ||
arg.is_a?(Arel::Attributes::Attribute) ||
Arel.arel_node?(arg) ||
arg.to_s.split(/\s*,\s*/).all? { |part| permit.match?(part) }
end

View file

@ -635,7 +635,7 @@ module ActiveRecord
def _substitute_values(values)
values.map do |name, value|
attr = arel_attribute(name)
unless value.is_a?(Arel::Node) || value.is_a?(Arel::Attribute) || value.is_a?(Arel::Nodes::SqlLiteral)
unless Arel.arel_node?(value)
type = klass.type_for_attribute(attr.name)
value = predicate_builder.build_bind_attribute(attr.name, type.cast(value))
end

View file

@ -35,6 +35,11 @@ module Arel # :nodoc: all
def self.star
sql "*"
end
def self.arel_node?(value)
value.is_a?(Arel::Node) || value.is_a?(Arel::Attribute) || value.is_a?(Arel::Nodes::SqlLiteral)
end
## Convenience Alias
Node = Arel::Nodes::Node
end