module MotionFlux::Store::ClassMethods

Public Instance Methods

attributes() click to toggle source
# File lib/motion_flux/store.rb, line 32
def attributes
  @attributes ||= []
end
emit(event) click to toggle source
# File lib/motion_flux/store.rb, line 48
def emit event
  handlers[event].each(&:call)
end
handlers() click to toggle source
# File lib/motion_flux/store.rb, line 40
def handlers
  @handlers ||= Hash.new { |hash, key| hash[key] = [] }
end
instance() click to toggle source
# File lib/motion_flux/store.rb, line 36
def instance
  @instance ||= new
end
on(event, &proc) click to toggle source
# File lib/motion_flux/store.rb, line 44
def on event, &proc
  handlers[event] << proc
end
store_attribute(*attrs) click to toggle source
# File lib/motion_flux/store.rb, line 16
def store_attribute *attrs
  options = attrs.extract_options!
  attrs.each do |attr|
    attributes << attr

    attr_reader attr
    define_singleton_method attr do
      instance.send attr
    end

    if options[:default]
      instance.instance_variable_set "@#{attr}", options[:default]
    end
  end
end
subscribe(action) click to toggle source
# File lib/motion_flux/store.rb, line 8
def subscribe action
  MotionFlux::Dispatcher.register instance, action
end
wait_for(*stores) click to toggle source
# File lib/motion_flux/store.rb, line 12
def wait_for *stores
  MotionFlux::Dispatcher.add_dependency instance, stores.map(&:instance)
end