Class: Statefully::State
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/statefully/state.rb
Defined Under Namespace
Classes: Missing
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
This method reeks of :reek:TooManyStatements.
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/statefully/state.rb', line 62
def method_missing(name, *args, &block)
sym_name = name.to_sym
return fetch(sym_name) if key?(sym_name)
str_name = name.to_s
modifier = str_name[-1]
return super unless %w[? !].include?(modifier)
base = str_name[0...-1].to_sym
known = key?(base)
return known if modifier == '?'
return fetch(base) if known
raise Missing, base
end
|
Instance Attribute Details
#previous ⇒ Object
Returns the value of attribute previous.
9
10
11
|
# File 'lib/statefully/state.rb', line 9
def previous
@previous
end
|
Class Method Details
.create(**values) ⇒ Object
12
13
14
|
# File 'lib/statefully/state.rb', line 12
def self.create(**values)
Success.send(:new, values, previous: None.instance).freeze
end
|
Instance Method Details
#diff ⇒ Object
16
17
18
|
# File 'lib/statefully/state.rb', line 16
def diff
Diff.create(self, previous)
end
|
#failure? ⇒ Boolean
28
29
30
|
# File 'lib/statefully/state.rb', line 28
def failure?
!success?
end
|
#finished? ⇒ Boolean
32
33
34
|
# File 'lib/statefully/state.rb', line 32
def finished?
false
end
|
#history ⇒ Object
20
21
22
|
# File 'lib/statefully/state.rb', line 20
def history
([diff] + previous.history).freeze
end
|
#inspect ⇒ Object
40
41
42
|
# File 'lib/statefully/state.rb', line 40
def inspect
_inspect_details({})
end
|
#resolve ⇒ Object
36
37
38
|
# File 'lib/statefully/state.rb', line 36
def resolve
self
end
|
#success? ⇒ Boolean
24
25
26
|
# File 'lib/statefully/state.rb', line 24
def success?
true
end
|