lib/neo4j/active_node/scope.rb in neo4j-4.0.0 vs lib/neo4j/active_node/scope.rb in neo4j-4.1.0
- old
+ new
@@ -3,11 +3,10 @@
module Neo4j::ActiveNode
module Scope
extend ActiveSupport::Concern
module ClassMethods
-
# Similar to ActiveRecord scope
#
# @example without argument
# class Person
# include Neo4j::ActiveNode
@@ -36,31 +35,39 @@
#
# @see http://guides.rubyonrails.org/active_record_querying.html#scopes
def scope(name, proc)
_scope[name.to_sym] = proc
- module_eval(%Q{
+ module_eval(%{
def #{name}(query_params=nil, _=nil, query_proxy=nil)
eval_context = ScopeEvalContext.new(self, query_proxy || self.class.query_proxy)
proc = self.class._scope[:"#{name}"]
self.class._call_scope_context(eval_context, query_params, proc)
end
}, __FILE__, __LINE__)
- instance_eval(%Q{
+ instance_eval(%{
def #{name}(query_params=nil, _=nil, query_proxy=nil)
eval_context = ScopeEvalContext.new(self, query_proxy || self.query_proxy)
proc = _scope[:"#{name}"]
_call_scope_context(eval_context, query_params, proc)
end
}, __FILE__, __LINE__)
end
+ # rubocop:disable Style/PredicateName
def has_scope?(name)
- _scope.has_key?(name.to_sym)
+ ActiveSupport::Deprecation.warn 'has_scope? is deprecated and may be removed from future releases, use scope? instead.', caller
+
+ scope?(name)
end
+ # rubocop:enable Style/PredicateName
+ def scope?(name)
+ _scope.key?(name.to_sym)
+ end
+
def _scope
@_scope ||= {}
end
def _call_scope_context(eval_context, query_params, proc)
@@ -86,21 +93,20 @@
current_scope.clone
else
self.as(:n)
end
end
-
end
class ScopeEvalContext
def initialize(target, query_proxy)
@query_proxy = query_proxy
@target = target
end
Neo4j::ActiveNode::Query::QueryProxy::METHODS.each do |method|
- module_eval(%Q{
+ module_eval(%{
def #{method}(params={})
@target.all.scoping do
(@query_proxy || @target).#{method}(params)
end
end}, __FILE__, __LINE__)
@@ -133,12 +139,11 @@
private
def raise_invalid_scope_type!(scope_type)
if !VALID_SCOPE_TYPES.include?(scope_type)
- raise ArgumentError, "Invalid scope type '#{scope_type}' sent to the registry. Scope types must be included in VALID_SCOPE_TYPES"
+ fail ArgumentError, "Invalid scope type '#{scope_type}' sent to the registry. Scope types must be included in VALID_SCOPE_TYPES"
end
end
end
-
end
end