Module: Stateology

Defined in:
lib/stateology.rb

Defined Under Namespace

Modules: SM_Class_Methods

Constant Summary collapse

VERSION =
"0.2.0"
Default =

alternative to ‘nil’

nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(c) ⇒ Object

bring in class methods on include



21
22
23
# File 'lib/stateology.rb', line 21

def self.included(c)
    c.extend(SM_Class_Methods)
end

Instance Method Details

#state(*state_args, &block) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/stateology.rb', line 167

def state(*state_args, &block)

    # behave as getter
    if state_args.empty? then
        return __state_getter
    end

    new_state = __validate_state_name(state_args.first)

    __state_transition(new_state, state_args, &block)

    # return value is the current state
    __current_state

rescue NameError
    raise NameError, "#{new_state} not a valid state"

end

#state?(state_name) ⇒ Boolean

is the current state equal to state_name?

Returns:

  • (Boolean)


187
188
189
190
191
192
193
194
195
196
197
# File 'lib/stateology.rb', line 187

def state?(state_name)

    state_name = __validate_state_name(state_name)

    # compare
    state_name == __current_state

rescue NameError
    raise NameError, "#{state_name} not a valid state"

end

#state_modObject

return the current state as a module



200
201
202
# File 'lib/stateology.rb', line 200

def state_mod
    __current_state
end