Class: Statefully::State
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Defined in:
- lib/statefully/state.rb
Defined Under Namespace
Classes: Failure, 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.
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/statefully/state.rb', line 53
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.
8
9
10
|
# File 'lib/statefully/state.rb', line 8
def previous
@previous
end
|
Class Method Details
.create(**values) ⇒ Object
11
12
13
|
# File 'lib/statefully/state.rb', line 11
def self.create(**values)
Success.send(:new, values, previous: None.instance).freeze
end
|
Instance Method Details
#diff ⇒ Object
15
16
17
|
# File 'lib/statefully/state.rb', line 15
def diff
Diff.create(self, previous)
end
|
#history ⇒ Object
19
20
21
|
# File 'lib/statefully/state.rb', line 19
def history
([diff] + previous.history).freeze
end
|
#inspect ⇒ Object
31
32
33
|
# File 'lib/statefully/state.rb', line 31
def inspect
inspect_details({})
end
|
#resolve ⇒ Object
27
28
29
|
# File 'lib/statefully/state.rb', line 27
def resolve
self
end
|
#success? ⇒ Boolean
23
24
25
|
# File 'lib/statefully/state.rb', line 23
def success?
true
end
|