Module: SassListen::FSM

Included in:
Listener
Defined in:
lib/sass-listen/fsm.rb

Defined Under Namespace

Modules: ClassMethods Classes: State

Constant Summary collapse

DEFAULT_STATE =

Default state name unless one is explicitly set

:default

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#stateObject (readonly)

Obtain the current state of the FSM


52
53
54
# File 'lib/sass-listen/fsm.rb', line 52

def state
  @state
end

Class Method Details

.included(klass) ⇒ Object

Included hook to extend class methods


7
8
9
# File 'lib/sass-listen/fsm.rb', line 7

def self.included(klass)
  klass.send :extend, ClassMethods
end

Instance Method Details

#initializeObject

Be kind and call super if you must redefine initialize


47
48
49
# File 'lib/sass-listen/fsm.rb', line 47

def initialize
  @state = self.class.default_state
end

#transition(state_name) ⇒ Object


54
55
56
57
58
# File 'lib/sass-listen/fsm.rb', line 54

def transition(state_name)
  new_state = validate_and_sanitize_new_state(state_name)
  return unless new_state
  transition_with_callbacks!(new_state)
end

#transition!(state_name) ⇒ Object

Immediate state transition with no checks, or callbacks. “Dangerous!”


61
62
63
# File 'lib/sass-listen/fsm.rb', line 61

def transition!(state_name)
  @state = state_name
end