Module: Photographer

Defined in:
lib/photographer.rb,
lib/photographer/version.rb

Defined Under Namespace

Modules: DSL

Constant Summary collapse

VERSION =
"0.0.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.max_differenceObject

Returns the value of attribute max_difference.



6
7
8
# File 'lib/photographer.rb', line 6

def max_difference
  @max_difference
end

Class Method Details

.camera(&block) ⇒ Object



21
22
23
# File 'lib/photographer.rb', line 21

def camera(&block)
  @camera = block
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Photographer)

    the object that the method was called on



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

def configure
  yield self
end

.dir=(path) ⇒ Object



16
17
18
19
# File 'lib/photographer.rb', line 16

def dir=(path)
  @dir = File.join path, "snaps"
  FileUtils.mkpath @dir
end

.initializeObject



8
9
10
# File 'lib/photographer.rb', line 8

def initialize
  @max_difference = 0.1
end

.snap(name) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/photographer.rb', line 29

def snap(name)
  path = File.join @dir, name + ".png"
  unless File.exists?(path) || update?
    raise "Snap missing. Run test with PHOTOGRAPHER=update to update."
  end

  path_new = File.join @dir, name + ".new.png"
  @camera.call path_new

  if update?
    File.delete path if File.exists? path
    File.rename path_new, path
  elsif compare(path, path_new) > @max_difference
    raise "New snap too different! Run test with PHOTOGRAPHER=update to update."
  end
end

.update?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/photographer.rb', line 25

def update?
  ENV["PHOTOGRAPHER"] == "update"
end