Class: Typocop::Repo
- Inherits:
-
Object
- Object
- Typocop::Repo
- Defined in:
- lib/typocop/repo.rb
Instance Attribute Summary collapse
-
#patch_additions ⇒ Object
readonly
Returns the value of attribute patch_additions.
Instance Method Summary collapse
- #diff ⇒ Object
- #head ⇒ Object
- #head_target ⇒ Object
-
#initialize(path = '.') ⇒ Repo
constructor
A new instance of Repo.
- #merge_base ⇒ Object
- #name ⇒ Object
- #remote_url ⇒ Object
- #target_id ⇒ Object
- #target_oid ⇒ Object
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_additions ⇒ Object (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
#diff ⇒ Object
37 38 39 |
# File 'lib/typocop/repo.rb', line 37 def diff @repo.diff(merge_base, head_target) end |
#head ⇒ Object
25 26 27 |
# File 'lib/typocop/repo.rb', line 25 def head @repo.head end |
#head_target ⇒ Object
29 30 31 |
# File 'lib/typocop/repo.rb', line 29 def head_target head.target end |
#merge_base ⇒ Object
33 34 35 |
# File 'lib/typocop/repo.rb', line 33 def merge_base @repo.merge_base(BASE_BRANCH, head_target) end |
#name ⇒ Object
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_url ⇒ Object
21 22 23 |
# File 'lib/typocop/repo.rb', line 21 def remote_url @repo.remotes.first.url end |
#target_id ⇒ Object
41 42 43 |
# File 'lib/typocop/repo.rb', line 41 def target_id head.target_id end |
#target_oid ⇒ Object
45 46 47 |
# File 'lib/typocop/repo.rb', line 45 def target_oid head_target.oid end |