Return this object from associations It uses a QueryProxy to get results But also caches results and can have results cached on it
- QUERY_PROXY_METHODS
- CACHED_RESULT_METHODS
#cache_query_proxy_result
ruby
- def cache_query_proxy_result
- @query_proxy.to_a.tap do
cache_result(result)
end
end
#cache_result
ruby
- def cache_result(result)
@cached_result = result @enumerable = (@cached_result || @query_proxy)
end
#cached?
ruby
- def cached?
!!@cached_result
end
#clear_cache_result
ruby
- def clear_cache_result
cache_result(nil)
end
#each
ruby
- def each(&block)
result.each(&block)
end
#initialize
ruby
- 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
ruby
- def inspect
- if @cached_result
@cached_result.inspect
- else
"#<AssociationProxy @query_proxy=#{@query_proxy.inspect}>"
end
end
#method_missing
ruby
- 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
ruby
- def result
return @cached_result if @cached_result
cache_query_proxy_result
@cached_result
end
#serializable_hash
ruby
- def serializable_hash(options = {})
to_a.map { record.serializable_hash(options) }
end