class Statefully::Diff::Changed
{Changed} is a {Diff} which contains changes between two successful {State}s.
Attributes
Hash of added properties and their values
@return [Hash<Symbol, Object>] @api public @example
Statefully::Diff::Changed.new(added: {key: 7}).added => {:key => 7}
Hash of changed properties and their current and previous values
@return [Hash<Symbol, Change>] @api public @example
Statefully::Diff::Changed.new( changed: {key: Statefully::Change.new(current: 7, previous: 8)}, ) => {:key=>#<Statefully::Change current=7, previous=8>}
Public Class Methods
Constructor for {Diff::Changed}
@param added [Hash<Symbol, Object>] added fields @param changed [Hash<Symbol, Change>] [changed fields] @api public @example
Statefully::Diff::Changed.new(added: {key: 7}) => #<Statefully::Diff::Changed added={key: 7}>
# File lib/statefully/diff.rb, line 129 def initialize(added: {}, changed: {}) @added = added.freeze @changed = changed.freeze end
Public Instance Methods
Check if a {Diff} resulted from creating a {State}
@return [Boolean] @api public @example
Stateful::State.created.created? => true Stateful::State.created.succeed.created? => false
# File lib/statefully/diff.rb, line 144 def created? false end
Check if a {Diff} is empty
An empty {Diff} means that there are no changes in properties between current and previous {State}.
@return [Boolean] @api public @example
Statefully::Diff::Changed.new(added: {key: 7}).empty? => false
# File lib/statefully/diff.rb, line 158 def empty? added.empty? && changed.empty? end
Human-readable representation of the {Change} for console inspection
@return [String] @api semipublic @example
Statefully::Diff::Changed.new(added: {key: 7}) => #<Statefully::Diff::Changed added={key: 7}>
# File lib/statefully/diff.rb, line 169 def inspect details = [self.class.name] details << inspect_details unless empty? "#<#{details.join(' ')}>" end
Private Instance Methods
Helper method to print out added fields @return [String] @api private
# File lib/statefully/diff.rb, line 187 def inspect_added added.empty? ? nil : "added=#{Inspect.from_hash(added)}" end
Helper method to print out changed fields @return [String] @api private
# File lib/statefully/diff.rb, line 194 def inspect_changed changed.empty? ? nil : "changed=#{Inspect.from_hash(changed)}" end
Helper method to print out added and changed fields @return [String] @api private
# File lib/statefully/diff.rb, line 180 def inspect_details [inspect_added, inspect_changed].compact.join(', ') end