Class: Core::Watch::Diff
- Inherits:
-
Object
- Object
- Core::Watch::Diff
- Includes:
- Is::Inspectable
- Defined in:
- lib/core/watch/diff.rb
Overview
- public
-
Contains changes to a watched system, organized by operation.
Constant Summary collapse
- OPERATIONS =
%i[added changed removed].freeze
Instance Method Summary collapse
-
#changed? ⇒ Boolean
- public
-
Return ‘true` if the diff contains changes.
-
#each_change(&block) ⇒ Object
- public
-
Call the given block once with each changed path and operation.
-
#each_changed_path(&block) ⇒ Object
- public
-
Call the given block once with each changed path.
-
#include?(path) ⇒ Boolean
- public
-
Return ‘true` if `path` is included in the changes.
-
#initialize ⇒ Diff
constructor
A new instance of Diff.
-
#operation(path) ⇒ Object
- public
-
Return the operation for the given path.
Constructor Details
#initialize ⇒ Diff
Returns a new instance of Diff.
15 16 17 |
# File 'lib/core/watch/diff.rb', line 15 def initialize @changes = {} end |
Instance Method Details
#changed? ⇒ Boolean
- public
-
Return ‘true` if the diff contains changes.
47 48 49 |
# File 'lib/core/watch/diff.rb', line 47 def changed? @changes.any? end |
#each_change(&block) ⇒ Object
- public
-
Call the given block once with each changed path and operation.
31 32 33 34 35 |
# File 'lib/core/watch/diff.rb', line 31 def each_change(&block) return to_enum(:each_change) unless block @changes.each_pair(&block) end |
#each_changed_path(&block) ⇒ Object
- public
-
Call the given block once with each changed path.
39 40 41 42 43 |
# File 'lib/core/watch/diff.rb', line 39 def each_changed_path(&block) return to_enum(:each_changed_path) unless block @changes.each_key(&block) end |
#include?(path) ⇒ Boolean
- public
-
Return ‘true` if `path` is included in the changes.
53 54 55 |
# File 'lib/core/watch/diff.rb', line 53 def include?(path) @changes.include?(Pathname(path)) end |
#operation(path) ⇒ Object
- public
-
Return the operation for the given path.
59 60 61 |
# File 'lib/core/watch/diff.rb', line 59 def operation(path) @changes[path] end |