Class: CapybaraScreenshotDiff::Snap
- Inherits:
-
Object
- Object
- CapybaraScreenshotDiff::Snap
- Defined in:
- lib/capybara_screenshot_diff/snap.rb
Instance Attribute Summary collapse
-
#attempt_path ⇒ Object
readonly
Returns the value of attribute attempt_path.
-
#attempts_count ⇒ Object
readonly
Returns the value of attribute attempts_count.
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#prev_attempt_path ⇒ Object
readonly
Returns the value of attribute prev_attempt_path.
Instance Method Summary collapse
- #checkout_base_screenshot ⇒ Object
- #cleanup_attempts ⇒ Object
- #commit_last_attempt ⇒ Object
- #delete! ⇒ Object
- #find_attempts_paths ⇒ Object
-
#initialize(full_name, format, manager: SnapManager.instance) ⇒ Snap
constructor
A new instance of Snap.
- #next_attempt_path! ⇒ Object
- #path_for(version = :actual) ⇒ Object
Constructor Details
#initialize(full_name, format, manager: SnapManager.instance) ⇒ Snap
Returns a new instance of Snap.
7 8 9 10 11 12 13 14 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 7 def initialize(full_name, format, manager: SnapManager.instance) @full_name = full_name @format = format @path = manager.abs_path_for(Pathname.new(@full_name).sub_ext(".#{@format}")) @base_path = @path.sub_ext(".base.#{@format}") @manager = manager @attempts_count = 0 end |
Instance Attribute Details
#attempt_path ⇒ Object (readonly)
Returns the value of attribute attempt_path.
5 6 7 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 5 def attempt_path @attempt_path end |
#attempts_count ⇒ Object (readonly)
Returns the value of attribute attempts_count.
5 6 7 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 5 def attempts_count @attempts_count end |
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
5 6 7 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 5 def base_path @base_path end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
5 6 7 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 5 def format @format end |
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
5 6 7 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 5 def full_name @full_name end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
5 6 7 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 5 def manager @manager end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 5 def path @path end |
#prev_attempt_path ⇒ Object (readonly)
Returns the value of attribute prev_attempt_path.
5 6 7 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 5 def prev_attempt_path @prev_attempt_path end |
Instance Method Details
#checkout_base_screenshot ⇒ Object
22 23 24 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 22 def checkout_base_screenshot @manager.checkout_file(path, base_path) end |
#cleanup_attempts ⇒ Object
46 47 48 49 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 46 def cleanup_attempts @manager.cleanup_attempts!(self) @attempts_count = 0 end |
#commit_last_attempt ⇒ Object
42 43 44 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 42 def commit_last_attempt @manager.move(attempt_path, path) end |
#delete! ⇒ Object
16 17 18 19 20 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 16 def delete! path.delete if path.exist? base_path.delete if base_path.exist? cleanup_attempts end |
#find_attempts_paths ⇒ Object
51 52 53 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 51 def find_attempts_paths Dir[@manager.abs_path_for "**/#{full_name}.attempt_*.#{format}"] end |
#next_attempt_path! ⇒ Object
35 36 37 38 39 40 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 35 def next_attempt_path! @prev_attempt_path = @attempt_path @attempt_path = path.sub_ext(sprintf(".attempt_%02i.#{format}", @attempts_count)) ensure @attempts_count += 1 end |
#path_for(version = :actual) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/capybara_screenshot_diff/snap.rb', line 26 def path_for(version = :actual) case version when :base base_path else path end end |