Class: Stator::Transition
- Inherits:
-
Object
- Object
- Stator::Transition
- Defined in:
- lib/stator/transition.rb
Constant Summary collapse
- ANY =
'__any__'
Instance Attribute Summary collapse
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #any ⇒ Object
- #can?(current_state) ⇒ Boolean
- #conditional(options = {}, &block) ⇒ Object
- #evaluate ⇒ Object
- #from(*froms) ⇒ Object
- #from_states ⇒ Object
-
#initialize(class_name, name, namespace = nil) ⇒ Transition
constructor
A new instance of Transition.
- #to(to) ⇒ Object
- #to_state ⇒ Object
- #valid?(from, to) ⇒ Boolean
Constructor Details
#initialize(class_name, name, namespace = nil) ⇒ Transition
Returns a new instance of Transition.
9 10 11 12 13 14 15 16 17 |
# File 'lib/stator/transition.rb', line 9 def initialize(class_name, name, namespace = nil) @class_name = class_name @name = name @namespace = namespace @full_name = [@namespace, @name].compact.join('_') if @name @froms = [] @to = nil @callbacks = {} end |
Instance Attribute Details
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
7 8 9 |
# File 'lib/stator/transition.rb', line 7 def full_name @full_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/stator/transition.rb', line 6 def name @name end |
Instance Method Details
#any ⇒ Object
48 49 50 |
# File 'lib/stator/transition.rb', line 48 def any ANY end |
#can?(current_state) ⇒ Boolean
35 36 37 |
# File 'lib/stator/transition.rb', line 35 def can?(current_state) @froms.include?(current_state) || @froms.include?(ANY) || current_state == ANY end |
#conditional(options = {}, &block) ⇒ Object
44 45 46 |
# File 'lib/stator/transition.rb', line 44 def conditional( = {}, &block) klass.instance_exec(conditional_block(), &block) end |
#evaluate ⇒ Object
52 53 54 |
# File 'lib/stator/transition.rb', line 52 def evaluate generate_methods unless @full_name.blank? end |
#from(*froms) ⇒ Object
19 20 21 |
# File 'lib/stator/transition.rb', line 19 def from(*froms) @froms |= froms.map{|f| f.try(:to_s) } # nils are ok end |
#from_states ⇒ Object
31 32 33 |
# File 'lib/stator/transition.rb', line 31 def from_states @froms end |
#to(to) ⇒ Object
23 24 25 |
# File 'lib/stator/transition.rb', line 23 def to(to) @to = to.to_s end |
#to_state ⇒ Object
27 28 29 |
# File 'lib/stator/transition.rb', line 27 def to_state @to end |