class Neo4j::ActiveNode::HasN::AssociationProxy
Return this object from associations It uses a QueryProxy to get results But also caches results and can have results cached on it
Constants
- CACHED_RESULT_METHODS
- QUERY_PROXY_METHODS
Public Class Methods
new(query_proxy, deferred_objects = [], result_cache_proc = nil)
click to toggle source
# File lib/neo4j/active_node/has_n.rb 11 def initialize(query_proxy, deferred_objects = [], result_cache_proc = nil) 12 @query_proxy = query_proxy 13 @deferred_objects = deferred_objects 14 15 @result_cache_proc = result_cache_proc 16 17 # Represents the thing which can be enumerated 18 # default to @query_proxy, but will be set to 19 # @cached_result if that is set 20 @enumerable = @query_proxy 21 end
Public Instance Methods
+(other)
click to toggle source
# File lib/neo4j/active_node/has_n.rb 48 def +(other) 49 self.to_a + other 50 end
==(other)
click to toggle source
# File lib/neo4j/active_node/has_n.rb 44 def ==(other) 45 self.to_a == other.to_a 46 end
add_to_cache(object)
click to toggle source
# File lib/neo4j/active_node/has_n.rb 85 def add_to_cache(object) 86 @cached_result ||= [] 87 @cached_result << object 88 end
cache_query_proxy_result()
click to toggle source
# File lib/neo4j/active_node/has_n.rb 90 def cache_query_proxy_result 91 (result_cache_proc_cache || @query_proxy).to_a.tap { |result| cache_result(result) } 92 end
cache_result(result)
click to toggle source
# File lib/neo4j/active_node/has_n.rb 80 def cache_result(result) 81 @cached_result = result 82 @enumerable = (@cached_result || @query_proxy) 83 end
cached?()
click to toggle source
# File lib/neo4j/active_node/has_n.rb 102 def cached? 103 !!@cached_result 104 end
clear_cache_result()
click to toggle source
# File lib/neo4j/active_node/has_n.rb 98 def clear_cache_result 99 cache_result(nil) 100 end
each(&block)
click to toggle source
# File lib/neo4j/active_node/has_n.rb 40 def each(&block) 41 result_nodes.each(&block) 42 end
inspect()
click to toggle source
States: Default
# File lib/neo4j/active_node/has_n.rb 25 def inspect 26 if @cached_result 27 result_nodes.inspect 28 else 29 "#<AssociationProxy @query_proxy=#{@query_proxy.inspect}>" 30 end 31 end
method_missing(method_name, *args, &block)
click to toggle source
Calls superclass method
# File lib/neo4j/active_node/has_n.rb 122 def method_missing(method_name, *args, &block) 123 target = target_for_missing_method(method_name) 124 super if target.nil? 125 126 cache_query_proxy_result if !cached? && !target.is_a?(Neo4j::ActiveNode::Query::QueryProxy) 127 clear_cache_result if target.is_a?(Neo4j::ActiveNode::Query::QueryProxy) 128 129 target.public_send(method_name, *args, &block) 130 end
replace_with(*args)
click to toggle source
# File lib/neo4j/active_node/has_n.rb 106 def replace_with(*args) 107 @cached_result = nil 108 109 @query_proxy.public_send(:replace_with, *args) 110 end
result()
click to toggle source
# File lib/neo4j/active_node/has_n.rb 52 def result 53 (@deferred_objects || []) + result_without_deferred 54 end
result_cache_proc_cache()
click to toggle source
# File lib/neo4j/active_node/has_n.rb 94 def result_cache_proc_cache 95 @result_cache_proc_cache ||= @result_cache_proc.call if @result_cache_proc 96 end
result_ids()
click to toggle source
# File lib/neo4j/active_node/has_n.rb 74 def result_ids 75 result.map do |object| 76 object.is_a?(Neo4j::ActiveNode) ? object.id : object 77 end 78 end
result_nodes()
click to toggle source
# File lib/neo4j/active_node/has_n.rb 62 def result_nodes 63 return result_objects if !@query_proxy.model 64 65 result_objects.map do |object| 66 object.is_a?(Neo4j::ActiveNode) ? object : @query_proxy.model.find(object) 67 end 68 end
result_objects()
click to toggle source
# File lib/neo4j/active_node/has_n.rb 70 def result_objects 71 @deferred_objects + result_without_deferred 72 end
result_without_deferred()
click to toggle source
# File lib/neo4j/active_node/has_n.rb 56 def result_without_deferred 57 cache_query_proxy_result if !@cached_result 58 59 @cached_result 60 end
serializable_hash(options = {})
click to toggle source
# File lib/neo4j/active_node/has_n.rb 132 def serializable_hash(options = {}) 133 to_a.map { |record| record.serializable_hash(options) } 134 end
Private Instance Methods
target_for_missing_method(method_name)
click to toggle source
# File lib/neo4j/active_node/has_n.rb 138 def target_for_missing_method(method_name) 139 case method_name 140 when *CACHED_RESULT_METHODS 141 @cached_result 142 else 143 if @cached_result && @cached_result.respond_to?(method_name) 144 @cached_result 145 elsif @query_proxy.respond_to?(method_name) 146 @query_proxy 147 end 148 end 149 end