Sha256: d946a1b710e57161448c755e30751731fef67f0a15d494344aa1ba31ac63b7b8

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

# encoding: UTF-8
require 'ostruct'

module Simulacrum
  # Configuration Class for managing config of the suite
  class Configuration
    COMPONENT_DEFAULTS = {
      delta_threshold:  1,
      window_size:      [1024, 768],
      capture_delay:    nil,
      capture_selector: :html
    }

    attr_reader :references_path, :reference_filename, :candidate_filename,
                :diff_filename, :delta_threshold, :capture_delay,
                :window_size, :capture_selector, :default_browser

    def initialize
      @config = OpenStruct.new(component: OpenStruct.new(COMPONENT_DEFAULTS))
    end

    def configure(config)
      @config = OpenStruct.new(@config.to_h.merge!(config))
    end

    def references_path
      if @config.references_path
        @config.references_path
      elsif defined?(Rails)
        File.join(Rails.root, 'spec/ui/references')
      else
        'spec/ui/references'
      end
    end

    def reference_filename
      @config.reference_filename || 'reference'
    end

    def candidate_filename
      @config.candidate_filename || 'candidate'
    end

    def diff_filename
      @config.diff_filename || 'diff'
    end

    def delta_threshold
      @config.component.delta_threshold || 0.0
    end

    def capture_selector
      @config.component.capture_selector || nil
    end

    def build_name
      @config.build_name || ''
    end

    def project_name
      @config.project_name || 'Simulacrum'
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
simulacrum-0.3.2 lib/simulacrum/configuration.rb
simulacrum-0.3.1 lib/simulacrum/configuration.rb
simulacrum-0.3.0 lib/simulacrum/configuration.rb