Module: Transitions

Defined in:
lib/transitions/state.rb,
lib/transitions.rb,
lib/transitions/event.rb,
lib/transitions/version.rb,
lib/transitions/machine.rb,
lib/transitions/state_transition.rb

Overview

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Defined Under Namespace

Modules: ClassMethods Classes: Event, InvalidTransition, Machine, State, StateTransition

Constant Summary

VERSION =
"0.0.11"

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) included(base)



65
66
67
# File 'lib/transitions.rb', line 65

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

- (Object) current_state(name = nil, new_state = nil, persist = false)



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/transitions.rb', line 69

def current_state(name = nil, new_state = nil, persist = false)
  sm   = self.class.state_machine(name)
  ivar = sm.current_state_variable
  if name && new_state
    if persist && respond_to?(:write_state)
      write_state(sm, new_state)
    end

    if respond_to?(:write_state_without_persistence)
      write_state_without_persistence(sm, new_state)
    end

    instance_variable_set(ivar, new_state)
  else
    instance_variable_set(ivar, nil) unless instance_variable_defined?(ivar)
    value = instance_variable_get(ivar)
    return value if value

    if respond_to?(:read_state)
      value = instance_variable_set(ivar, read_state(sm))
    end

    value || sm.initial_state
  end
end