module Neo4j::ActiveNode::Scope::ClassMethods
Public Instance Methods
_call_scope_context(eval_context, query_params, proc)
click to toggle source
# File lib/neo4j/active_node/scope.rb 70 def _call_scope_context(eval_context, query_params, proc) 71 if proc.arity == 1 72 eval_context.instance_exec(query_params, &proc) 73 else 74 eval_context.instance_exec(&proc) 75 end 76 end
all(new_var = nil)
click to toggle source
# File lib/neo4j/active_node/scope.rb 87 def all(new_var = nil) 88 var = new_var || (current_scope ? current_scope.node_identity : :n) 89 if current_scope 90 current_scope.new_link(var) 91 else 92 self.as(var) 93 end 94 end
full_scopes()
click to toggle source
# File lib/neo4j/active_node/scope.rb 66 def full_scopes 67 scopes.merge(self.superclass.respond_to?(:scopes) ? self.superclass.scopes : {}) 68 end
has_scope?(name)
click to toggle source
rubocop:disable Style/PredicateName
# File lib/neo4j/active_node/scope.rb 51 def has_scope?(name) 52 ActiveSupport::Deprecation.warn 'has_scope? is deprecated and may be removed from future releases, use scope? instead.', caller 53 54 scope?(name) 55 end
scope(name, proc)
click to toggle source
Similar to ActiveRecord scope
@example without argument
class Person include Neo4j::ActiveNode property :name property :score has_many :out, :friends, type: :has_friend, model_class: self scope :top_students, -> { where(score: 42)}") } end Person.top_students.to_a a_person.friends.top_students.to_a a_person.friends.friends.top_students.to_a a_person.friends.top_students.friends.to_a
@example Argument for scopes
Person.scope :level, ->(num) { where(level_num: num)}
@example Argument as a cypher identifier
class Person include Neo4j::ActiveNode property :name property :score has_many :out, :friends, type: :has_friend, model_class: self scope :great_students, ->(identifier) { where("#{identifier}.score > 41") } end Person.as(:all_people).great_students(:all_people).to_a
@see guides.rubyonrails.org/active_record_querying.html#scopes
# File lib/neo4j/active_node/scope.rb 37 def scope(name, proc) 38 scopes[name.to_sym] = proc 39 40 klass = class << self; self; end 41 klass.instance_eval do 42 define_method(name) do |query_params = nil, _ = nil| 43 eval_context = ScopeEvalContext.new(self, current_scope || self.query_proxy) 44 proc = full_scopes[name.to_sym] 45 _call_scope_context(eval_context, query_params, proc) 46 end 47 end 48 end
scope?(name)
click to toggle source
rubocop:enable Style/PredicateName
# File lib/neo4j/active_node/scope.rb 58 def scope?(name) 59 full_scopes.key?(name.to_sym) 60 end
scopes()
click to toggle source
# File lib/neo4j/active_node/scope.rb 62 def scopes 63 @scopes ||= {} 64 end