提交 f854b46a 编写于 作者: R Ryuta Kamizono

Refactor query methods not to depend on internal `DEFAULT_VALUES` constant

This constant is no longer useful since 58df9a45.
上级 0c2bb348
......@@ -90,7 +90,7 @@ def not_behaves_as_nor?(opts)
when *Relation::SINGLE_VALUE_METHODS
["#{name}_value", name == :create_with ? "FROZEN_EMPTY_HASH" : "nil"]
when *Relation::CLAUSE_METHODS
["#{name}_clause", "DEFAULT_VALUES[:#{name}]"]
["#{name}_clause", name == :from ? "Relation::FromClause.empty" : "Relation::WhereClause.empty"]
end
class_eval <<-CODE, __FILE__, __LINE__ + 1
......@@ -447,7 +447,7 @@ def unscope!(*args) # :nodoc:
raise ArgumentError, "Called unscope() with invalid unscoping argument ':#{scope}'. Valid arguments are :#{VALID_UNSCOPING_VALUES.to_a.join(", :")}."
end
assert_mutability!
@values[scope] = DEFAULT_VALUES[scope]
@values.delete(scope)
when Hash
scope.each do |key, target_value|
if key != :where
......@@ -1361,8 +1361,8 @@ def check_if_method_has_arguments!(method_name, args)
def structurally_incompatible_values_for_or(other)
values = other.values
STRUCTURAL_OR_METHODS.reject do |method|
default = DEFAULT_VALUES[method]
@values.fetch(method, default) == values.fetch(method, default)
v1, v2 = @values[method], values[method]
v1 == v2 || (!v1 || v1.empty?) && (!v2 || v2.empty?)
end
end
......@@ -1370,16 +1370,5 @@ def where_clause_factory
@where_clause_factory ||= Relation::WhereClauseFactory.new(klass, predicate_builder)
end
alias having_clause_factory where_clause_factory
DEFAULT_VALUES = {
create_with: FROZEN_EMPTY_HASH,
where: Relation::WhereClause.empty,
having: Relation::WhereClause.empty,
from: Relation::FromClause.empty
}
Relation::MULTI_VALUE_METHODS.each do |value|
DEFAULT_VALUES[value] ||= FROZEN_EMPTY_ARRAY
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册