Module: Neo4j::ActiveNode::Scope::ClassMethods
- Defined in:
- lib/neo4j/active_node/scope.rb
Instance Method Summary collapse
- #_call_scope_context(eval_context, query_params, proc) ⇒ Object
- #all(new_var = nil) ⇒ Object
-
#current_scope ⇒ Object
:nodoc:.
-
#current_scope=(scope) ⇒ Object
:nodoc:.
- #full_scopes ⇒ Object
-
#has_scope?(name) ⇒ Boolean
rubocop:disable Style/PredicateName.
-
#scope(name, proc) ⇒ Object
Similar to ActiveRecord scope.
-
#scope?(name) ⇒ Boolean
rubocop:enable Style/PredicateName.
- #scopes ⇒ Object
Instance Method Details
#_call_scope_context(eval_context, query_params, proc) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/neo4j/active_node/scope.rb', line 70 def _call_scope_context(eval_context, query_params, proc) if proc.arity == 1 eval_context.instance_exec(query_params, &proc) else eval_context.instance_exec(&proc) end end |
#all(new_var = nil) ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/neo4j/active_node/scope.rb', line 87 def all(new_var = nil) var = new_var || (current_scope ? current_scope.node_identity : :n) if current_scope current_scope.new_link(var) else self.as(var) end end |
#current_scope ⇒ Object
:nodoc:
79 80 81 |
# File 'lib/neo4j/active_node/scope.rb', line 79 def current_scope #:nodoc: ScopeRegistry.value_for(:current_scope, base_class.to_s) end |
#current_scope=(scope) ⇒ Object
:nodoc:
83 84 85 |
# File 'lib/neo4j/active_node/scope.rb', line 83 def current_scope=(scope) #:nodoc: ScopeRegistry.set_value_for(:current_scope, base_class.to_s, scope) end |
#full_scopes ⇒ Object
66 67 68 |
# File 'lib/neo4j/active_node/scope.rb', line 66 def full_scopes scopes.merge(self.superclass.respond_to?(:scopes) ? self.superclass.scopes : {}) end |
#has_scope?(name) ⇒ Boolean
rubocop:disable Style/PredicateName
51 52 53 54 55 |
# File 'lib/neo4j/active_node/scope.rb', line 51 def has_scope?(name) ActiveSupport::Deprecation.warn 'has_scope? is deprecated and may be removed from future releases, use scope? instead.', caller scope?(name) end |
#scope(name, proc) ⇒ Object
Similar to ActiveRecord scope
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/neo4j/active_node/scope.rb', line 37 def scope(name, proc) scopes[name.to_sym] = proc klass = class << self; self; end klass.instance_eval do define_method(name) do |query_params = nil, _ = nil| eval_context = ScopeEvalContext.new(self, current_scope || self.query_proxy) proc = full_scopes[name.to_sym] _call_scope_context(eval_context, query_params, proc) end end end |
#scope?(name) ⇒ Boolean
rubocop:enable Style/PredicateName
58 59 60 |
# File 'lib/neo4j/active_node/scope.rb', line 58 def scope?(name) full_scopes.key?(name.to_sym) end |
#scopes ⇒ Object
62 63 64 |
# File 'lib/neo4j/active_node/scope.rb', line 62 def scopes @scopes ||= {} end |