Class: CapybaraScreenshotDiff::Snap

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara_screenshot_diff/snap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pathObject (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_countObject (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_pathObject (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

#formatObject (readonly)

Returns the value of attribute format.



5
6
7
# File 'lib/capybara_screenshot_diff/snap.rb', line 5

def format
  @format
end

#full_nameObject (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

#managerObject (readonly)

Returns the value of attribute manager.



5
6
7
# File 'lib/capybara_screenshot_diff/snap.rb', line 5

def manager
  @manager
end

#pathObject (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_pathObject (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_screenshotObject



22
23
24
# File 'lib/capybara_screenshot_diff/snap.rb', line 22

def checkout_base_screenshot
  @manager.checkout_file(path, base_path)
end

#cleanup_attemptsObject



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_attemptObject



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_pathsObject



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