Class: Statefully::Diff Abstract
- Inherits:
-
Object
- Object
- Statefully::Diff
- Defined in:
- lib/statefully/diff.rb
Overview
Defined Under Namespace
Classes: Changed, Created, Failed, Finished, Unchanged
Class Method Summary collapse
-
.create(current:, previous:) ⇒ Statefully::Diff
Create is the only public interface to the Diff class.
Instance Method Summary collapse
-
#added ⇒ Hash<Symbol, Object>
Hash of added properties and their values.
-
#added?(key) ⇒ Boolean
Check if a key has been added.
-
#changed ⇒ Hash<Symbol, Statefully::Change>
Hash of changed properties and their current and previous values.
-
#changed?(key) ⇒ Boolean
Check if a key has been changed.
-
#empty? ⇒ Boolean
Check if a Diff is empty.
Class Method Details
.create(current:, previous:) ⇒ Statefully::Diff
Create is the only public interface to the Diff class
This method reeks of :reek:FeatureEnvy (of current).
23 24 25 26 27 28 |
# File 'lib/statefully/diff.rb', line 23 def self.create(current:, previous:) return current.diff if current.failed? || current.finished? changes = Builder.new(current: current, previous: previous).build return Created.new(**changes).freeze if previous.none? changes.empty? ? Unchanged.instance : Changed.new(**changes).freeze end |
Instance Method Details
#added ⇒ Hash<Symbol, Object>
Hash of added properties and their values
51 52 53 |
# File 'lib/statefully/diff.rb', line 51 def added {} end |
#added?(key) ⇒ Boolean
Check if a key has been added
77 78 79 |
# File 'lib/statefully/diff.rb', line 77 def added?(key) added.key?(key) end |
#changed ⇒ Hash<Symbol, Statefully::Change>
Hash of changed properties and their current and previous values
62 63 64 |
# File 'lib/statefully/diff.rb', line 62 def changed {} end |
#changed?(key) ⇒ Boolean
Check if a key has been changed
94 95 96 |
# File 'lib/statefully/diff.rb', line 94 def changed?(key) changed.key?(key) end |
#empty? ⇒ Boolean
Check if a Statefully::Diff is empty
An empty Statefully::Diff means that is there are no changes in properties between current and previous State.
40 41 42 |
# File 'lib/statefully/diff.rb', line 40 def empty? true end |