Class: Rodiff::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rodiff/configuration.rb

Defined Under Namespace

Classes: UnknownConfiguration

Constant Summary collapse

ATTRS =
Module.new.tap { |mod| include mod }
READER_ATTRS =
{
  default_dir: "/"
}.freeze
ACCESSOR_ATTRS =
{
  include_pattern:       "{*,**/*}.jpg",
  exclude_pattern:       "",
  compare_pattern:       "",

  ignore_antialiasing:   false,
  color_threshold:       0.1,
  output_diff_mask:      false,

  exit_code_odiff:       ->(code) { code },
  exit_code_error:       1,
  fail_if_no_comparison: false
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



65
66
67
68
69
70
# File 'lib/rodiff/configuration.rb', line 65

def initialize
  @config_overrides = {}

  READER_ATTRS.each { |key, value| instance_variable_set("@#{key}", value) }
  ACCESSOR_ATTRS.each { |key, value| instance_variable_set("@#{key}", value) }
end

Class Method Details

.config_attribute(name, type:) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rodiff/configuration.rb', line 41

def self.config_attribute(name, type:)
  case type
  when :reader, :writer, :accessor then "attr_#{type} :#{name}"
  when :proxy
    <<-RUBY
      def #{name}
        value_for(:#{name}) { super() }
      end
    RUBY
  else
    raise ArgumentError, "unsupported type #{type.inspect}"
  end
end

.generate_config(mod, path, line, attrs) ⇒ Object



37
38
39
# File 'lib/rodiff/configuration.rb', line 37

def self.generate_config(mod, path, line, attrs)
  mod.module_eval(Array(attrs).join(";").to_s, path, line)
end

Instance Method Details

#odiff_exe_pathObject



72
73
74
# File 'lib/rodiff/configuration.rb', line 72

def odiff_exe_path
  @odiff_exe_path ||= Rodiff::Executable.resolve
end

#odiff_exe_path=(path) ⇒ Object



76
77
78
# File 'lib/rodiff/configuration.rb', line 76

def odiff_exe_path=(path)
  @odiff_exe_path = Rodiff::Executable.resolve(exe_path: path)
end

#overrides(opts = {}) ⇒ Object



80
81
82
83
# File 'lib/rodiff/configuration.rb', line 80

def overrides(opts = {})
  opts.each_key { |key| validate_config_key!(key) }
  @config_overrides.merge!(opts.transform_keys(&:to_sym))
end