Class: Crystalball::SourceDiff::FileDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/crystalball/source_diff/file_diff.rb

Overview

Data object for single file in Git repo diff

Instance Method Summary collapse

Constructor Details

#initialize(git_diff) ⇒ FileDiff

Returns a new instance of FileDiff.

Parameters:

  • git_diff (Git::DiffFile)
    • raw diff for a single file made by ruby-git gem



8
9
10
# File 'lib/crystalball/source_diff/file_diff.rb', line 8

def initialize(git_diff)
  @git_diff = git_diff
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



40
41
42
# File 'lib/crystalball/source_diff/file_diff.rb', line 40

def method_missing(method, *args, &block)
  git_diff.public_send(method, *args, &block) || super
end

Instance Method Details

#deleted?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/crystalball/source_diff/file_diff.rb', line 20

def deleted?
  git_diff.type == 'deleted'
end

#modified?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/crystalball/source_diff/file_diff.rb', line 16

def modified?
  !moved? && git_diff.type == 'modified'
end

#moved?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/crystalball/source_diff/file_diff.rb', line 12

def moved?
  !(git_diff.patch =~ /rename from.*\nrename to/).nil?
end

#new?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/crystalball/source_diff/file_diff.rb', line 24

def new?
  git_diff.type == 'new'
end

#new_relative_pathObject

Returns new relative path to file if file was moved.

Returns:

  • new relative path to file if file was moved



34
35
36
37
38
# File 'lib/crystalball/source_diff/file_diff.rb', line 34

def new_relative_path
  return relative_path unless moved?

  git_diff.patch.match(/rename from.*\nrename to (.*)/)[1]
end

#relative_pathObject

Returns relative path to file.

Returns:

  • relative path to file



29
30
31
# File 'lib/crystalball/source_diff/file_diff.rb', line 29

def relative_path
  git_diff.path
end

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/crystalball/source_diff/file_diff.rb', line 44

def respond_to_missing?(method, *)
  git_diff.respond_to?(method, false) || super
end