class Wraith::Wraith

Attributes

config[RW]

Public Class Methods

new(config, options = {}) click to toggle source
# File lib/wraith/wraith.rb, line 9
def initialize(config, options = {})
  options = {
    yaml_passed: false,
    imports_must_resolve: true,
  }.merge(options)

  if options[:yaml_passed]
    @config = config
  else
    filepath = determine_config_path config
    @config = YAML.load_file filepath
    if !@config
      fail InvalidYamlError, "could not parse \"#{config}\" as YAML"
    end
  end

  if @config['imports']
    @config = apply_imported_config(@config['imports'], @config, options[:imports_must_resolve])
  end

  logger.level = verbose ? Logger::DEBUG : Logger::INFO
end

Public Instance Methods

apply_imported_config(config_to_import, config, imports_must_resolve) click to toggle source
# File lib/wraith/wraith.rb, line 55
def apply_imported_config(config_to_import, config, imports_must_resolve)
  path_to_config = "#{config_dir}/#{config_to_import}"
  if File.exist?(path_to_config)
    yaml = YAML.load_file path_to_config
    return yaml.merge(config)
  end

  if imports_must_resolve
    fail ConfigFileDoesNotExistError, "unable to find referenced imported config \"#{config_to_import}\""
  else
    config # return original config
  end
end
base_domain() click to toggle source
# File lib/wraith/wraith.rb, line 119
def base_domain
  domains[base_domain_label]
end
base_domain_label() click to toggle source
# File lib/wraith/wraith.rb, line 127
def base_domain_label
  domains.keys[0]
end
before_capture() click to toggle source
# File lib/wraith/wraith.rb, line 102
def before_capture
  @config["before_capture"] ? convert_to_absolute(@config["before_capture"]) : false
end
comp_domain() click to toggle source
# File lib/wraith/wraith.rb, line 123
def comp_domain
  domains[comp_domain_label]
end
comp_domain_label() click to toggle source
# File lib/wraith/wraith.rb, line 131
def comp_domain_label
  domains.keys[1]
end
config_dir() click to toggle source
# File lib/wraith/wraith.rb, line 51
def config_dir
  @calculated_config_dir
end
determine_config_path(config_name) click to toggle source
# File lib/wraith/wraith.rb, line 32
def determine_config_path(config_name)
  possible_filenames = [
    config_name,
    "#{config_name}.yml",
    "#{config_name}.yaml",
    "configs/#{config_name}.yml",
    "configs/#{config_name}.yaml"
  ]

  possible_filenames.each do |filepath|
    if File.exist?(filepath)
      @calculated_config_dir = absolute_path_of_dir(convert_to_absolute filepath)
      return convert_to_absolute filepath
    end
  end

  fail ConfigFileDoesNotExistError, "unable to find config \"#{config_name}\""
end
directory() click to toggle source
# File lib/wraith/wraith.rb, line 69
def directory
  # Legacy support for those using array configs
  @config["directory"].is_a?(Array) ? @config["directory"].first : @config["directory"]
end
domains() click to toggle source
# File lib/wraith/wraith.rb, line 115
def domains
  @config["domains"]
end
engine() click to toggle source
# File lib/wraith/wraith.rb, line 78
def engine
  engine = @config["browser"]
  # Legacy support for those using the old style "browser: \n phantomjs: 'casperjs'" configs
  engine = engine.values.first if engine.is_a? Hash
  engine
end
fuzz() click to toggle source
# File lib/wraith/wraith.rb, line 163
def fuzz
  @config["fuzz"]
end
highlight_color() click to toggle source
# File lib/wraith/wraith.rb, line 167
def highlight_color
  @config.fetch('highlight_color', 'blue')
end
history_dir() click to toggle source
# File lib/wraith/wraith.rb, line 74
def history_dir
  @config.fetch('history_dir', false)
end
imports() click to toggle source
# File lib/wraith/wraith.rb, line 199
def imports
  @config.fetch('imports', false)
end
mode() click to toggle source
# File lib/wraith/wraith.rb, line 171
def mode
  if %w(diffs_only diffs_first alphanumeric).include?(@config["mode"])
    @config["mode"]
  else
    "alphanumeric"
  end
end
paths() click to toggle source
# File lib/wraith/wraith.rb, line 159
def paths
  @config["paths"]
end
phantomjs_options() click to toggle source
# File lib/wraith/wraith.rb, line 195
def phantomjs_options
  @config["phantomjs_options"]
end
resize() click to toggle source
# File lib/wraith/wraith.rb, line 110
def resize
  # @TODO make this default to true, once it's been tested a bit more thoroughly
  @config.fetch('resize_or_reload', 'reload') == "resize"
end
settle() click to toggle source
# File lib/wraith/wraith.rb, line 135
def settle
  @config.fetch('settle', 10)
end
sitemap() click to toggle source
# File lib/wraith/wraith.rb, line 151
def sitemap
  @config["sitemap"]
end
snap_file() click to toggle source
# File lib/wraith/wraith.rb, line 85
def snap_file
  @config["snap_file"] ? convert_to_absolute(@config["snap_file"]) : snap_file_from_engine(engine)
end
snap_file_from_engine(engine) click to toggle source
# File lib/wraith/wraith.rb, line 89
def snap_file_from_engine(engine)
  path_to_js_templates = File.dirname(__FILE__) + "/javascript"
  case engine
  when "phantomjs"
    path_to_js_templates + "/phantom.js"
  when "casperjs"
    path_to_js_templates + "/casper.js"
  # @TODO - add a SlimerJS option
  else
    logger.error "Wraith does not recognise the browser engine '#{engine}'"
  end
end
spider_days() click to toggle source
# File lib/wraith/wraith.rb, line 147
def spider_days
  @config["spider_days"]
end
spider_file() click to toggle source
# File lib/wraith/wraith.rb, line 143
def spider_file
  @config.fetch('spider_file', 'spider.txt')
end
spider_skips() click to toggle source
# File lib/wraith/wraith.rb, line 155
def spider_skips
  @config["spider_skips"]
end
threads() click to toggle source
# File lib/wraith/wraith.rb, line 139
def threads
  @config.fetch('threads', '8').to_i
end
threshold() click to toggle source
# File lib/wraith/wraith.rb, line 179
def threshold
  @config.fetch('threshold', 0)
end
thumb_height() click to toggle source
# File lib/wraith/wraith.rb, line 187
def thumb_height
  @config.fetch('gallery', {}).fetch('thumb_height', 200)
end
thumb_width() click to toggle source
# File lib/wraith/wraith.rb, line 191
def thumb_width
  @config.fetch('gallery', {}).fetch('thumb_width', 200)
end
verbose() click to toggle source
# File lib/wraith/wraith.rb, line 203
def verbose
  # @TODO - also add a `--verbose` CLI flag which overrides whatever you have set in the config
  @config.fetch('verbose', false)
end
widths() click to toggle source
# File lib/wraith/wraith.rb, line 106
def widths
  @config["screen_widths"]
end