Class: CouchbaseOrm::ResultsProxy
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- CouchbaseOrm::ResultsProxy
- Defined in:
- lib/couchbase-orm/proxies/results_proxy.rb
Overview
Lazily materializes to Array once, then delegates all calls to that Array.
Instance Method Summary collapse
-
#initialize(source) ⇒ ResultsProxy
constructor
A new instance of ResultsProxy.
-
#to_a ⇒ Object
Ensure callers that explicitly want an Array get the materialized one.
Constructor Details
#initialize(source) ⇒ ResultsProxy
Returns a new instance of ResultsProxy.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/couchbase-orm/proxies/results_proxy.rb', line 8 def initialize(source) # Contract: a source must at least respond_to?(:to_a) unless source.respond_to?(:to_a) raise ArgumentError.new('Proxyfied object must respond to :to_a') end @source = source @__getobj__ = nil # SimpleDelegator needs an initial obj; we’ll supply it lazily via __getobj__ super(nil) end |
Instance Method Details
#to_a ⇒ Object
Ensure callers that explicitly want an Array get the materialized one.
21 22 23 |
# File 'lib/couchbase-orm/proxies/results_proxy.rb', line 21 def to_a __getobj__ end |