Class: StubFile
Overview
A simple object we can use in place of a GithubFile as a test mock or for debugging
Instance Attribute Summary collapse
-
#blob ⇒ Object
Returns the value of attribute blob.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(_opts = {}) ⇒ Object
-
#initialize(path:, blob:, patch: nil) ⇒ StubFile
constructor
A new instance of StubFile.
- #patch ⇒ Object
- #patch_from_blob ⇒ Object
Methods inherited from FileLike
#basename, #extname, #first_line_of_patch
Constructor Details
#initialize(path:, blob:, patch: nil) ⇒ StubFile
Returns a new instance of StubFile.
17 18 19 20 21 |
# File 'app/models/stub_file.rb', line 17 def initialize(path:, blob:, patch: nil) @path = path @blob = blob @patch = patch end |
Instance Attribute Details
#blob ⇒ Object
Returns the value of attribute blob.
6 7 8 |
# File 'app/models/stub_file.rb', line 6 def blob @blob end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'app/models/stub_file.rb', line 6 def path @path end |
Class Method Details
Instance Method Details
#as_json(_opts = {}) ⇒ Object
33 34 35 36 37 38 39 |
# File 'app/models/stub_file.rb', line 33 def as_json(_opts = {}) { path: @path, blob: @blob, patch: patch.body, } end |
#patch ⇒ Object
29 30 31 |
# File 'app/models/stub_file.rb', line 29 def patch @patch || Patch.new(patch_from_blob) end |
#patch_from_blob ⇒ Object
23 24 25 26 27 |
# File 'app/models/stub_file.rb', line 23 def patch_from_blob lines = @blob.lines "@@ -0,0 +1,#{lines.length}\n" + lines.map { |l| "+#{l}" }.join('') end |