Class: CapybaraScreenshotDiff::SnapManager

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ SnapManager

Returns a new instance of SnapManager.



12
13
14
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 12

def initialize(root)
  @root = Pathname.new(root)
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



10
11
12
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 10

def root
  @root
end

Class Method Details

.cleanup!Object



48
49
50
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 48

def self.cleanup!
  instance.cleanup!
end

.instanceObject



72
73
74
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 72

def self.instance
  Capybara::Screenshot::Diff.manager.new(Capybara::Screenshot.screenshot_area_abs)
end

.rootObject



68
69
70
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 68

def self.root
  instance.root
end

.screenshotsObject



64
65
66
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 64

def self.screenshots
  instance.screenshots
end

.snapshot(screenshot_full_name, screenshot_format = "png") ⇒ Object



20
21
22
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 20

def self.snapshot(screenshot_full_name, screenshot_format = "png")
  instance.snapshot(screenshot_full_name, screenshot_format)
end

Instance Method Details

#abs_path_for(relative_path) ⇒ Object



24
25
26
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 24

def abs_path_for(relative_path)
  @root / relative_path
end

#checkout_file(path, as_path) ⇒ Object



28
29
30
31
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 28

def checkout_file(path, as_path)
  create_output_directory_for(as_path) unless as_path.exist?
  Capybara::Screenshot::Diff::Vcs.checkout_vcs(root, path, as_path)
end

#cleanup!Object

TODO: rename to delete!



44
45
46
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 44

def cleanup!
  FileUtils.rm_rf root, secure: true
end

#cleanup_attempts!(snapshot) ⇒ Object



52
53
54
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 52

def cleanup_attempts!(snapshot)
  FileUtils.rm_rf snapshot.find_attempts_paths, secure: true
end

#create_output_directory_for(path = nil) ⇒ Object



39
40
41
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 39

def create_output_directory_for(path = nil)
  path ? path.dirname.mkpath : root.mkpath
end

#move(new_screenshot_path, screenshot_path) ⇒ Object



56
57
58
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 56

def move(new_screenshot_path, screenshot_path)
  FileUtils.mv(new_screenshot_path, screenshot_path, force: true)
end

#provision_snap_with(snap, path, version: :actual) ⇒ Object



33
34
35
36
37
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 33

def provision_snap_with(snap, path, version: :actual)
  managed_path = snap.path_for(version)
  create_output_directory_for(managed_path) unless managed_path.exist?
  FileUtils.cp(path, managed_path)
end

#screenshotsObject



60
61
62
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 60

def screenshots
  root.children.map { |f| f.basename.to_s }
end

#snapshot(screenshot_full_name, screenshot_format = "png") ⇒ Object



16
17
18
# File 'lib/capybara_screenshot_diff/snap_manager.rb', line 16

def snapshot(screenshot_full_name, screenshot_format = "png")
  Snap.new(screenshot_full_name, screenshot_format, manager: self)
end