Class: Monet::Config

Inherits:
Object
  • Object
show all
Includes:
URLHelpers
Defined in:
lib/monet/config.rb

Constant Summary collapse

MissingBaseURL =
Class.new(Exception)
DEFAULT_OPTIONS =
{
  driver: :poltergeist,
  dimensions: [1024],
  base_url: nil,
  map: nil,
  compare_type: "ColorBlend",
  capture_dir: "./captures",
  baseline_dir: "./baselines",
  thumbnail_dir: "./thumbnails",
  thumbnail: false
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Config

configure via options



25
26
27
28
29
# File 'lib/monet/config.rb', line 25

def initialize(opts={})
  DEFAULT_OPTIONS.each do |opt, default|
    send "#{opt}=", opts[opt] || default
  end
end

Class Method Details

.config {|cfg| ... } ⇒ Object

configure via block

Yields:

  • (cfg)


32
33
34
35
36
37
# File 'lib/monet/config.rb', line 32

def self.config(&block)
  cfg = new
  yield cfg if block_given?

  cfg
end

.load(path = "./config.yaml") ⇒ Object

configure via YAML



40
41
42
43
# File 'lib/monet/config.rb', line 40

def self.load(path="./config.yaml")
  opts = YAML::load(File.open(path))
  new(opts)
end

Instance Method Details

#base_urlObject

Raises:



49
50
51
52
# File 'lib/monet/config.rb', line 49

def base_url
  raise MissingBaseURL, "Please set the base_url in the config" unless @base_url
  @base_url
end

#base_url=(url) ⇒ Object



45
46
47
# File 'lib/monet/config.rb', line 45

def base_url=(url)
  @base_url = parse_uri(url) unless url.nil?
end

#baseline_dir=(path) ⇒ Object



68
69
70
# File 'lib/monet/config.rb', line 68

def baseline_dir=(path)
  @baseline_dir = expand_path(path)
end

#capture_dir=(path) ⇒ Object



64
65
66
# File 'lib/monet/config.rb', line 64

def capture_dir=(path)
  @capture_dir = expand_path(path)
end

#map(type = :explicit) {|@map| ... } ⇒ Object

Yields:



82
83
84
85
86
87
# File 'lib/monet/config.rb', line 82

def map(type=:explicit, &block)
  @map ||= CaptureMap.new(base_url, type)
  yield @map if block_given?

  @map
end

#map=(paths) ⇒ Object



76
77
78
79
80
# File 'lib/monet/config.rb', line 76

def map=(paths)
  @map = nil
  return @map if paths.nil?
  paths == :spider ? map(paths) : (map.paths = paths)
end

#siteObject Also known as: host, root_dir



54
55
56
# File 'lib/monet/config.rb', line 54

def site
  parse_uri(base_url).host
end

#thumbnail?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/monet/config.rb', line 60

def thumbnail?
  !!thumbnail
end

#thumbnail_dir=(path) ⇒ Object



72
73
74
# File 'lib/monet/config.rb', line 72

def thumbnail_dir=(path)
  @thumbnail_dir = expand_path(path)
end