Class: 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
Methods inherited from Inputer
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
31 32 33 |
# File 'lib/diff_resource/inputer/git_inputer.rb', line 31 def directory? path return type? path, "tree" end |
#file?(path) ⇒ Boolean
35 36 37 |
# File 'lib/diff_resource/inputer/git_inputer.rb', line 35 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 28 29 |
# File 'lib/diff_resource/inputer/git_inputer.rb', line 14 def parse_files path, extension, parser resources = [] base = Pathname.getwd if directory? path contents = `git ls-tree --name-only #{reference}:#{path}` # ls-tree command bad work on non root dir contents.split("\n").each do |file| relative_file_path = Pathname(File.(file, path)).relative_path_from(base).to_s resources += parse_files relative_file_path, extension, parser end elsif file? path resources += parse_file path, parser if match? extension, path end return resources end |
#type?(path, type) ⇒ Boolean
39 40 41 42 43 |
# File 'lib/diff_resource/inputer/git_inputer.rb', line 39 def type? path, type type_str = `git cat-file -t #{reference}:#{path}` return type_str.delete("\n") == type if $?.exitstatus == 0 return false end |