Sha256: 177542ad1320fe6dc895521a5ae671b9136ec1a28280dd73cdd5e2f090863702
Contents?: true
Size: 947 Bytes
Versions: 3
Compression:
Stored size: 947 Bytes
Contents
module EdgeStateMachine class State attr_reader :name, :options def initialize(name, &block) @name = name @options = Hash.new instance_eval(&block) if block_given? end def enter(method = nil, &block) @options[:enter] = method.nil? ? block : method end def exit(method = nil, &block) @options[:exit] = method.nil? ? block : method end def execute_action(action, base) action = @options[action.to_sym] case action when Symbol, String base.send(action) when Proc action.call(base) end end def use_display_name(display_name) @display_name = display_name end def display_name @display_name ||= name.to_s.gsub(/_/, ' ').capitalize end def ==(st) if st.is_a? Symbol name == st elsif st.is_a? String name == st else name == st.name end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
edge-state-machine-1.0.1 | lib/edge-state-machine/state.rb |
edge-state-machine-1.0.0 | lib/edge-state-machine/state.rb |
edge-state-machine-0.9.1 | lib/edge-state-machine/state.rb |