Class: Typocop::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/typocop/repo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = '.') ⇒ Repo

Returns a new instance of Repo.



5
6
7
8
9
10
11
12
13
14
# File 'lib/typocop/repo.rb', line 5

def initialize(path = '.')
  @repo = Rugged::Repository.new(path)
  patch_additions = diff.select { |patch| patch.additions.positive? }
  @patch_additions = patch_additions.map do |patch|
    path = patch.delta.new_file[:path]
    lines = patch.hunks.flat_map(&:lines)
    added_lines = lines.select(&:addition?)
    Patch.new(path, lines, added_lines)
  end
end

Instance Attribute Details

#patch_additionsObject (readonly)

Returns the value of attribute patch_additions.



3
4
5
# File 'lib/typocop/repo.rb', line 3

def patch_additions
  @patch_additions
end

Instance Method Details

#diffObject



37
38
39
# File 'lib/typocop/repo.rb', line 37

def diff
  @repo.diff(merge_base, head_target)
end

#headObject



25
26
27
# File 'lib/typocop/repo.rb', line 25

def head
  @repo.head
end

#head_targetObject



29
30
31
# File 'lib/typocop/repo.rb', line 29

def head_target
  head.target
end

#merge_baseObject



33
34
35
# File 'lib/typocop/repo.rb', line 33

def merge_base
  @repo.merge_base(BASE_BRANCH, head_target)
end

#nameObject



16
17
18
19
# File 'lib/typocop/repo.rb', line 16

def name
  match = %r{(?:https?://)?(?:www\.)?github\.com[/:](?<repo_name>.*?)(?:\.git)?\z}.match(remote_url)
  match[:repo_name]
end

#remote_urlObject



21
22
23
# File 'lib/typocop/repo.rb', line 21

def remote_url
  @repo.remotes.first.url
end

#target_idObject



41
42
43
# File 'lib/typocop/repo.rb', line 41

def target_id
  head.target_id
end

#target_oidObject



45
46
47
# File 'lib/typocop/repo.rb', line 45

def target_oid
  head_target.oid
end