Class: Cascade::Statistics

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/cascade/statistics.rb

Constant Summary collapse

STORES =
{
  counter: StatisticsStores::CounterStore,
  array: StatisticsStores::ArrayStore
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeStatistics

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

Parameters:

  • action (Symbol)

    action name that will be used to access it



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

Parameters:

  • action (Symbol)

    action name that will be used to access it

  • store (Symbol)

    type of using store

  • default_value (Object) (defaults to: nil)

    value that will be used as default for store

Returns:

  • (Object)

    instance of 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

Parameters:

  • action (Symbol)

    action name that will be used to access it

  • value (Object) (defaults to: nil)

    for updating store



35
36
37
# File 'lib/cascade/statistics.rb', line 35

def update(action, value = nil)
  @store_repository[action].update(value)
end