Class: Repo
- Inherits:
-
Object
- Object
- Repo
- Defined in:
- lib/repo.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#shell ⇒ Object
readonly
Returns the value of attribute shell.
Class Method Summary collapse
Instance Method Summary collapse
- #all_files ⇒ Object
- #changed?(file_path) ⇒ Boolean
- #current_branch ⇒ Object
- #files_changed ⇒ Object
- #find_files(pattern) ⇒ Object
- #grep(regex, file_pattern: '*') ⇒ Object
-
#initialize(shell: shell) ⇒ Repo
constructor
A new instance of Repo.
- #status_files ⇒ Object
Constructor Details
#initialize(shell: shell) ⇒ Repo
Returns a new instance of Repo.
9 10 11 |
# File 'lib/repo.rb', line 9 def initialize(shell: shell) @shell = shell end |
Instance Attribute Details
#shell ⇒ Object (readonly)
Returns the value of attribute shell.
7 8 9 |
# File 'lib/repo.rb', line 7 def shell @shell end |
Class Method Details
.root_dir ⇒ Object
3 4 5 |
# File 'lib/repo.rb', line 3 def self.root_dir @root_dir ||= %x[ git rev-parse --show-toplevel ].chomp end |
Instance Method Details
#all_files ⇒ Object
21 22 23 |
# File 'lib/repo.rb', line 21 def all_files @all_files ||= shell.run("git ls-tree --full-tree -r HEAD --name-only").split("\n") end |
#changed?(file_path) ⇒ Boolean
17 18 19 |
# File 'lib/repo.rb', line 17 def changed?(file_path) files_changed.include? file_path end |
#current_branch ⇒ Object
48 49 50 |
# File 'lib/repo.rb', line 48 def current_branch shell.run 'git rev-parse --abbrev-ref HEAD' end |
#files_changed ⇒ Object
13 14 15 |
# File 'lib/repo.rb', line 13 def files_changed @files_changed ||= (shell.run "git diff --name-only #{@old_sha}").split("\n") end |
#find_files(pattern) ⇒ Object
25 26 27 |
# File 'lib/repo.rb', line 25 def find_files(pattern) shell.run("git ls-files '*#{pattern}*'").split("\n") end |
#grep(regex, file_pattern: '*') ⇒ Object
41 42 43 44 45 46 |
# File 'lib/repo.rb', line 41 def grep(regex, file_pattern: '*') results = shell.run("git grep '#{regex}' -- '#{file_pattern}'").split("\n") results.map do |result| interpret_grep_result(result) end end |
#status_files ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/repo.rb', line 29 def status_files statii = shell.run("git status -s").split("\n") r = statii.map do |status| status.strip! if status[0] == 'D' nil else status.split(' ').last end end.compact end |