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"
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Config

Returns a new instance of Config.



22
23
24
25
26
# File 'lib/monet/config.rb', line 22

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

Class Method Details

.build_config(opts) ⇒ Object



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

def self.build_config(opts)
  (opts.is_a? Monet::Config) ? opts : new(opts)
end

.config(&block) ⇒ Object



28
29
30
31
32
# File 'lib/monet/config.rb', line 28

def self.config(&block)
  cfg = new
  block.call cfg
  cfg
end

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



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

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

Instance Method Details

#base_urlObject

Raises:



47
48
49
50
# File 'lib/monet/config.rb', line 47

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

#base_url=(url) ⇒ Object



43
44
45
# File 'lib/monet/config.rb', line 43

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

#baseline_dir=(path) ⇒ Object



56
57
58
# File 'lib/monet/config.rb', line 56

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

#capture_dir=(path) ⇒ Object



52
53
54
# File 'lib/monet/config.rb', line 52

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

#map(type = :explicit, &block) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/monet/config.rb', line 64

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

  block.call(@map) if block_given? && type == :explicit

  @map
end

#map=(paths) ⇒ Object



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

def map=(paths)
  map.paths = paths unless paths.nil?
end