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¶
- QUERY_PROXY_METHODS
- CACHED_RESULT_METHODS
Methods¶
#cache_query_proxy_result
def cache_query_proxy_result @query_proxy.to_a.tap do |result| cache_result(result) end end
#cache_result
def cache_result(result) @cached_result = result @enumerable = (@cached_result || @query_proxy) end
#cached?
def cached? !!@cached_result end
#clear_cache_result
def clear_cache_result cache_result(nil) end
#each
def each(&block) result.each(&block) end
#initialize
def initialize(query_proxy, cached_result = nil) @query_proxy = query_proxy cache_result(cached_result) # Represents the thing which can be enumerated # default to @query_proxy, but will be set to # @cached_result if that is set @enumerable = @query_proxy end
- #inspect
States: Default
def inspect if @cached_result @cached_result.inspect else "#<AssociationProxy @query_proxy=#{@query_proxy.inspect}>" end end
#method_missing
def method_missing(method_name, *args, &block) target = target_for_missing_method(method_name) super if target.nil? cache_query_proxy_result if !cached? && !target.is_a?(Neo4j::ActiveNode::Query::QueryProxy) clear_cache_result if target.is_a?(Neo4j::ActiveNode::Query::QueryProxy) target.public_send(method_name, *args, &block) end
#result
def result return @cached_result if @cached_result cache_query_proxy_result @cached_result end
#serializable_hash
def serializable_hash(options = {}) to_a.map { |record| record.serializable_hash(options) } end