Module: MotionFlux::Store::ClassMethods
- Included in:
- MotionFlux::Store
- Defined in:
- lib/motion_flux/store.rb
Instance Method Summary collapse
- #attributes ⇒ Object
- #emit(event) ⇒ Object
- #handlers ⇒ Object
- #instance ⇒ Object
- #on(event, &proc) ⇒ Object
- #store_attribute(*attrs) ⇒ Object
- #subscribe(action) ⇒ Object
- #wait_for(*stores) ⇒ Object
Instance Method Details
#attributes ⇒ Object
32 33 34 |
# File 'lib/motion_flux/store.rb', line 32 def attributes @attributes ||= [] end |
#emit(event) ⇒ Object
48 49 50 |
# File 'lib/motion_flux/store.rb', line 48 def emit event handlers[event].each(&:call) end |
#handlers ⇒ Object
40 41 42 |
# File 'lib/motion_flux/store.rb', line 40 def handlers @handlers ||= Hash.new { |hash, key| hash[key] = [] } end |
#instance ⇒ Object
36 37 38 |
# File 'lib/motion_flux/store.rb', line 36 def instance @instance ||= new end |
#on(event, &proc) ⇒ Object
44 45 46 |
# File 'lib/motion_flux/store.rb', line 44 def on event, &proc handlers[event] << proc end |
#store_attribute(*attrs) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/motion_flux/store.rb', line 16 def store_attribute *attrs = attrs. attrs.each do |attr| attributes << attr attr_reader attr define_singleton_method attr do instance.send attr end if [:default] instance.instance_variable_set "@#{attr}", [:default] end end end |
#subscribe(action) ⇒ Object
8 9 10 |
# File 'lib/motion_flux/store.rb', line 8 def subscribe action MotionFlux::Dispatcher.register instance, action end |
#wait_for(*stores) ⇒ Object
12 13 14 |
# File 'lib/motion_flux/store.rb', line 12 def wait_for *stores MotionFlux::Dispatcher.add_dependency instance, stores.map(&:instance) end |