Class: Stateful::State
- Inherits:
-
Object
show all
- Defined in:
- lib/stateful.rb
Instance Method Summary
(collapse)
Constructor Details
- (State) initialize(model)
3
4
5
|
# File 'lib/stateful.rb', line 3
def initialize(model)
@model = model
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(predicate, *args)
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/stateful.rb', line 20
def method_missing(predicate, *args)
if predicate.to_s.last == '?'
self.class.to_s.demodulize.underscore == predicate.to_s.chop
else
if block_given?
super(predicate, *args) { |*block_args| yield(*block_args) }
else
super(predicate, *args)
end
end
end
|
Instance Method Details
- (Object) ==(other_state)
32
33
34
|
# File 'lib/stateful.rb', line 32
def ==(other_state)
self.class == other_state.class
end
|
- (Object) enter_hook
15
16
17
|
# File 'lib/stateful.rb', line 15
def enter_hook
::Rails.logger.debug("#{model} entering state #{self}")
end
|
- (Object) exit_hook(target_state)
11
12
13
|
# File 'lib/stateful.rb', line 11
def exit_hook(target_state)
::Rails.logger.debug("#{model} leaving state #{self}")
end
|
- (Object) hash
36
37
38
|
# File 'lib/stateful.rb', line 36
def hash
self.class.hash
end
|
- (Object) to_s
7
8
9
|
# File 'lib/stateful.rb', line 7
def to_s
self.class.to_s.demodulize
end
|