Class: Philiprehberger::FileWatcher::Change
- Inherits:
-
Object
- Object
- Philiprehberger::FileWatcher::Change
- Defined in:
- lib/philiprehberger/file_watcher/change.rb
Overview
Value object representing a single file system change.
Constant Summary collapse
- VALID_TYPES =
%i[created modified deleted].freeze
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
absolute path to the changed file.
-
#type ⇒ Symbol
readonly
one of :created, :modified, or :deleted.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
True if path and type match.
-
#hash ⇒ Integer
Hash code.
-
#initialize(path, type) ⇒ Change
constructor
A new instance of Change.
-
#to_s ⇒ String
Human-readable representation of the change.
Constructor Details
#initialize(path, type) ⇒ Change
Returns a new instance of Change.
17 18 19 20 21 22 23 24 |
# File 'lib/philiprehberger/file_watcher/change.rb', line 17 def initialize(path, type) unless VALID_TYPES.include?(type) raise ArgumentError, "invalid change type: #{type.inspect} (must be one of #{VALID_TYPES.join(', ')})" end @path = path @type = type end |
Instance Attribute Details
#path ⇒ String (readonly)
absolute path to the changed file
9 10 11 |
# File 'lib/philiprehberger/file_watcher/change.rb', line 9 def path @path end |
#type ⇒ Symbol (readonly)
one of :created, :modified, or :deleted
9 10 11 |
# File 'lib/philiprehberger/file_watcher/change.rb', line 9 def type @type end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Returns true if path and type match.
32 33 34 |
# File 'lib/philiprehberger/file_watcher/change.rb', line 32 def ==(other) other.is_a?(Change) && other.path == path && other.type == type end |
#hash ⇒ Integer
Returns hash code.
38 39 40 |
# File 'lib/philiprehberger/file_watcher/change.rb', line 38 def hash [path, type].hash end |
#to_s ⇒ String
Returns human-readable representation of the change.
27 28 29 |
# File 'lib/philiprehberger/file_watcher/change.rb', line 27 def to_s "#{type}: #{path}" end |