Class: Core::Watch::Diff
- Inherits:
-
Object
- Object
- Core::Watch::Diff
- 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.
12 13 14 |
# File 'lib/core/watch/diff.rb', line 12 def initialize @changes = {} end |
Instance Method Details
#changed? ⇒ Boolean
- public
-
Return ‘true` if the diff contains changes.
44 45 46 |
# File 'lib/core/watch/diff.rb', line 44 def changed? @changes.any? end |
#each_change(&block) ⇒ Object
- public
-
Call the given block once with each changed path and operation.
28 29 30 31 32 |
# File 'lib/core/watch/diff.rb', line 28 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.
36 37 38 39 40 |
# File 'lib/core/watch/diff.rb', line 36 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.
50 51 52 |
# File 'lib/core/watch/diff.rb', line 50 def include?(path) @changes.include?(Pathname(path)) end |
#operation(path) ⇒ Object
- public
-
Return the operation for the given path.
56 57 58 |
# File 'lib/core/watch/diff.rb', line 56 def operation(path) @changes[path] end |