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.



13
14
15
# File 'lib/cascade/statistics.rb', line 13

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



40
41
42
# File 'lib/cascade/statistics.rb', line 40

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



23
24
25
26
27
# File 'lib/cascade/statistics.rb', line 23

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



33
34
35
# File 'lib/cascade/statistics.rb', line 33

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