Class: Clickwrap::ActorProxy::ReceiptCollection
- Inherits:
-
Object
- Object
- Clickwrap::ActorProxy::ReceiptCollection
- Includes:
- Enumerable
- Defined in:
- lib/clickwrap/actor_proxy.rb
Overview
A lazily-mapped collection so user.clickwraps.receipts.last reads
naturally without loading every event a person ever produced.
Instance Method Summary collapse
- #each ⇒ Object
- #empty? ⇒ Boolean
- #find(event_id) ⇒ Object
- #first ⇒ Object
-
#initialize(scope) ⇒ ReceiptCollection
constructor
A new instance of ReceiptCollection.
- #last ⇒ Object
- #size ⇒ Object (also: #count)
Constructor Details
#initialize(scope) ⇒ ReceiptCollection
Returns a new instance of ReceiptCollection.
134 135 136 |
# File 'lib/clickwrap/actor_proxy.rb', line 134 def initialize(scope) @scope = scope end |
Instance Method Details
#each ⇒ Object
138 |
# File 'lib/clickwrap/actor_proxy.rb', line 138 def each(&) = @scope.each { |event| yield Receipt.new(event) } |
#empty? ⇒ Boolean
143 |
# File 'lib/clickwrap/actor_proxy.rb', line 143 def empty? = @scope.empty? |
#find(event_id) ⇒ Object
144 |
# File 'lib/clickwrap/actor_proxy.rb', line 144 def find(event_id) = @scope.find_by(id: event_id)&.then { |event| Receipt.new(event) } |
#first ⇒ Object
140 |
# File 'lib/clickwrap/actor_proxy.rb', line 140 def first = @scope.first&.then { |event| Receipt.new(event) } |
#last ⇒ Object
139 |
# File 'lib/clickwrap/actor_proxy.rb', line 139 def last = @scope.last&.then { |event| Receipt.new(event) } |
#size ⇒ Object Also known as: count
141 |
# File 'lib/clickwrap/actor_proxy.rb', line 141 def size = @scope.count |