Class: Watchly::Changeset

Inherits:
Object
  • Object
show all
Defined in:
lib/watchly/changeset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(added:, removed:, modified:) ⇒ Changeset

Returns a new instance of Changeset.



5
6
7
8
9
10
11
# File 'lib/watchly/changeset.rb', line 5

def initialize(added:, removed:, modified:)
  @added    = added.freeze
  @removed  = removed.freeze
  @modified = modified.freeze
  @files    = (added + modified).freeze
  freeze
end

Instance Attribute Details

#addedObject (readonly)

Returns the value of attribute added.



3
4
5
# File 'lib/watchly/changeset.rb', line 3

def added
  @added
end

#filesObject (readonly)

Returns the value of attribute files.



3
4
5
# File 'lib/watchly/changeset.rb', line 3

def files
  @files
end

#modifiedObject (readonly)

Returns the value of attribute modified.



3
4
5
# File 'lib/watchly/changeset.rb', line 3

def modified
  @modified
end

#removedObject (readonly)

Returns the value of attribute removed.



3
4
5
# File 'lib/watchly/changeset.rb', line 3

def removed
  @removed
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


14
# File 'lib/watchly/changeset.rb', line 14

def any? = !empty?

#eachObject



17
18
19
20
21
22
23
# File 'lib/watchly/changeset.rb', line 17

def each
  return enum_for(:each) unless block_given?

  added.each    { |path| yield :added, path }
  removed.each  { |path| yield :removed, path }
  modified.each { |path| yield :modified, path }
end

#empty?Boolean

Returns:

  • (Boolean)


13
# File 'lib/watchly/changeset.rb', line 13

def empty? = files.empty?

#to_hObject



15
# File 'lib/watchly/changeset.rb', line 15

def to_h = { added: added, removed: removed, modified: modified, files: files }