Class: Repo

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

Direct Known Subclasses

ActiveRepo, LazyRepo

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#shellObject (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_dirObject



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

Returns:

  • (Boolean)


13
14
15
# File 'lib/sfb_scripts/repositories/repo.rb', line 13

def changed?(file_path)
  files_changed.include? file_path
end

#current_branchObject



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_filesObject



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