Class: DiffResource::GitInputer
- Inherits:
-
Object
- Object
- DiffResource::GitInputer
- Defined in:
- lib/diff_resource/inputer/git_inputer.rb
Instance Attribute Summary collapse
-
#reference ⇒ Object
Returns the value of attribute reference.
Instance Method Summary collapse
- #directory?(path) ⇒ Boolean
- #file?(path) ⇒ Boolean
- #parse_file(file_name, parser) ⇒ Object
- #parse_files(path, extension, parser) ⇒ Object
- #type?(path, type) ⇒ Boolean
Instance Attribute Details
#reference ⇒ Object
Returns the value of attribute reference.
4 5 6 |
# File 'lib/diff_resource/inputer/git_inputer.rb', line 4 def reference @reference end |
Instance Method Details
#directory?(path) ⇒ Boolean
29 30 31 |
# File 'lib/diff_resource/inputer/git_inputer.rb', line 29 def directory? path return type? path, "tree" end |
#file?(path) ⇒ Boolean
33 34 35 |
# File 'lib/diff_resource/inputer/git_inputer.rb', line 33 def file? path return type? path, "blob" end |
#parse_file(file_name, parser) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/diff_resource/inputer/git_inputer.rb', line 6 def parse_file file_name, parser ret = [] contents = `git show #{reference}:#{file_name}` ret = parser.parse contents if $?.exitstatus == 0 return ret end |
#parse_files(path, extension, parser) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/diff_resource/inputer/git_inputer.rb', line 14 def parse_files path, extension, parser resources = [] if directory? path contents = `git ls-tree --name-only #{reference}:#{path}` contents.split("\n").each do |file| resources += parse_files (path + "/" + file), extension, parser end elsif file? path resources += parse_file path, parser if %r{^.*\/#{extension}$} =~ path end return resources end |
#type?(path, type) ⇒ Boolean
37 38 39 40 41 |
# File 'lib/diff_resource/inputer/git_inputer.rb', line 37 def type? path, type type_str = `git cat-file -t #{reference}:#{path}` return type_str.delete("\n") == type if $?.exitstatus == 0 return false end |