Class: Clickwrap::ActorProxy::ReceiptCollection

Inherits:
Object
  • Object
show all
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

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

#eachObject



138
# File 'lib/clickwrap/actor_proxy.rb', line 138

def each(&) = @scope.each { |event| yield Receipt.new(event) }

#empty?Boolean

Returns:

  • (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) }

#firstObject



140
# File 'lib/clickwrap/actor_proxy.rb', line 140

def first = @scope.first&.then { |event| Receipt.new(event) }

#lastObject



139
# File 'lib/clickwrap/actor_proxy.rb', line 139

def last = @scope.last&.then { |event| Receipt.new(event) }

#sizeObject Also known as: count



141
# File 'lib/clickwrap/actor_proxy.rb', line 141

def size = @scope.count