Class: DeployChanges::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/deploy_changes/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, last_sha1) ⇒ Path

Returns a new instance of Path.



7
8
9
10
# File 'lib/deploy_changes/path.rb', line 7

def initialize(repo, last_sha1)
  @repo = repo
  @last_sha1 = last_sha1
end

Instance Attribute Details

#last_sha1Object (readonly)

Returns the value of attribute last_sha1.



5
6
7
# File 'lib/deploy_changes/path.rb', line 5

def last_sha1
  @last_sha1
end

#repoObject (readonly)

Returns the value of attribute repo.



5
6
7
# File 'lib/deploy_changes/path.rb', line 5

def repo
  @repo
end

Instance Method Details

#changed?(path) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/deploy_changes/path.rb', line 12

def changed?(path)
  return true if last_sha1.nil?

  diff = repo.index.diff(last_commit)

  diff.each_delta do |delta|
    files = [delta.old_file[:path], delta.new_file[:path]]
    return true if files.any? { |diff_path| diff_path =~ /^#{path}/ }
  end

  false
end