Class: Lookbook::HookStore

Inherits:
Object
  • Object
show all
Defined in:
lib/lookbook/stores/hook_store.rb

Constant Summary collapse

CONFIG_FILE =
"config/hooks.yml"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ HookStore

Returns a new instance of HookStore.



8
9
10
# File 'lib/lookbook/stores/hook_store.rb', line 8

def initialize(config = nil)
  @store = {}
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



5
6
7
# File 'lib/lookbook/stores/hook_store.rb', line 5

def store
  @store
end

Class Method Details

.default_configObject



24
25
26
# File 'lib/lookbook/stores/hook_store.rb', line 24

def self.default_config
  ConfigLoader.call(CONFIG_FILE)
end

.init_from_configObject



20
21
22
# File 'lib/lookbook/stores/hook_store.rb', line 20

def self.init_from_config
  new(default_config)
end

Instance Method Details

#add_hook(event_name, callback) ⇒ Object



12
13
14
# File 'lib/lookbook/stores/hook_store.rb', line 12

def add_hook(event_name, callback)
  for_event(event_name) << callback
end

#for_event(event_name) ⇒ Object



16
17
18
# File 'lib/lookbook/stores/hook_store.rb', line 16

def for_event(event_name)
  store[event_name.to_sym] ||= []
end