Class: Cascade::Statistics
- Inherits:
-
Object
- Object
- Cascade::Statistics
- Includes:
- Singleton
- Defined in:
- lib/cascade/statistics.rb
Constant Summary collapse
- STORES =
{ counter: StatisticsStores::CounterStore, array: StatisticsStores::ArrayStore }.freeze
Instance Method Summary collapse
-
#for(action) ⇒ Object
Returns statistics from store for passed action.
-
#initialize ⇒ Statistics
constructor
A new instance of Statistics.
-
#register_action(action, store, default_value = nil) ⇒ Object
Register statistics action with passed store.
-
#update(action, value = nil) ⇒ Object
Updates store action with passed value.
Constructor Details
#initialize ⇒ Statistics
Returns a new instance of Statistics.
15 16 17 |
# File 'lib/cascade/statistics.rb', line 15 def initialize @store_repository = {} end |
Instance Method Details
#for(action) ⇒ Object
Returns statistics from store for passed action
42 43 44 |
# File 'lib/cascade/statistics.rb', line 42 def for(action) @store_repository[action].store end |
#register_action(action, store, default_value = nil) ⇒ Object
Register statistics action with passed store
25 26 27 28 29 |
# File 'lib/cascade/statistics.rb', line 25 def register_action(action, store, default_value = nil) @store_repository[action] = defined_stores.fetch(store.to_sym) do default_store end.new(default_value) end |
#update(action, value = nil) ⇒ Object
Updates store action with passed value
35 36 37 |
# File 'lib/cascade/statistics.rb', line 35 def update(action, value = nil) @store_repository[action].update(value) end |