Class: Spree::Reporting::Counters
- Inherits:
-
Object
- Object
- Spree::Reporting::Counters
- Defined in:
- lib/spree/reporting/counters.rb
Overview
Evaluates the registered counters for one store, filtered to those the caller may read. Carries no copy: a counter is identified by its key and the client owns every string it shows, so an interface in one language never renders a number labelled in another.
Instance Method Summary collapse
-
#initialize(store:, channel: nil, registry: Spree.reporting, allowed: ->(_counter) { true }) ⇒ Counters
constructor
A new instance of Counters.
-
#to_a ⇒ Array<CounterResult>
In registration order.
Constructor Details
#initialize(store:, channel: nil, registry: Spree.reporting, allowed: ->(_counter) { true }) ⇒ Counters
Returns a new instance of Counters.
13 14 15 16 17 18 |
# File 'lib/spree/reporting/counters.rb', line 13 def initialize(store:, channel: nil, registry: Spree.reporting, allowed: ->(_counter) { true }) @store = store @channel = channel @registry = registry @allowed = allowed end |
Instance Method Details
#to_a ⇒ Array<CounterResult>
Returns in registration order.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/spree/reporting/counters.rb', line 21 def to_a @registry.counters.values.select { |counter| @allowed.call(counter) }.map do |counter| CounterResult.new( key: counter.name, value: counter.count.call(@store, channel: @channel), link: counter.link&.deep_stringify_keys, nav: counter.nav ) end end |