Class: Repo
- Inherits:
-
Object
- Object
- Repo
- Defined in:
- lib/sfb_scripts/repositories/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
- #changed?(file_path) ⇒ Boolean
- #current_branch ⇒ 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/sfb_scripts/repositories/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/sfb_scripts/repositories/repo.rb', line 7 def shell @shell end |
Class Method Details
.root_dir ⇒ Object
3 4 5 |
# File 'lib/sfb_scripts/repositories/repo.rb', line 3 def self.root_dir @root_dir ||= %x[ git rev-parse --show-toplevel ].chomp end |
Instance Method Details
#changed?(file_path) ⇒ Boolean
13 14 15 |
# File 'lib/sfb_scripts/repositories/repo.rb', line 13 def changed?(file_path) files_changed.include? file_path end |
#current_branch ⇒ Object
40 41 42 |
# File 'lib/sfb_scripts/repositories/repo.rb', line 40 def current_branch shell.run 'git rev-parse --abbrev-ref HEAD' end |
#find_files(pattern) ⇒ Object
17 18 19 |
# File 'lib/sfb_scripts/repositories/repo.rb', line 17 def find_files(pattern) shell.run("git ls-files '*#{pattern}*'").split("\n") end |
#grep(regex, file_pattern: '*') ⇒ Object
33 34 35 36 37 38 |
# File 'lib/sfb_scripts/repositories/repo.rb', line 33 def grep(regex, file_pattern: '*') results = shell.run("git grep --untracked '#{regex}' -- '#{file_pattern}'").split("\n") results.map do |result| interpret_grep_result(result) end end |
#status_files ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sfb_scripts/repositories/repo.rb', line 21 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 |