Class: Rodiff::Configuration

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

Defined Under Namespace

Classes: UnknownConfiguration

Constant Summary collapse

DOTFILE =
".rodiff.yml"
GEM_ROOT =
if RUBY_VERSION >= "3.1"
  File.dirname(__FILE__, 3).freeze
else
  File.expand_path(File.join(File.dirname(__FILE__), "..", "..")).freeze
end
DEFAULT_CONFIG =
File.join(GEM_ROOT, "config", "default.yml").freeze
SEARCH_ROOT =
Dir.home.freeze
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.



76
77
78
79
80
81
82
83
84
# File 'lib/rodiff/configuration.rb', line 76

def initialize
  @config_overrides = {}

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

  load_from_file(DEFAULT_CONFIG)
  load_from_file(config_file_override) if config_file_override
end

Class Method Details

.config_attribute(name, type:) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rodiff/configuration.rb', line 52

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



48
49
50
# File 'lib/rodiff/configuration.rb', line 48

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



86
87
88
# File 'lib/rodiff/configuration.rb', line 86

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

#odiff_exe_path=(path) ⇒ Object



90
91
92
# File 'lib/rodiff/configuration.rb', line 90

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

#overrides(opts = {}) ⇒ Object



94
95
96
97
# File 'lib/rodiff/configuration.rb', line 94

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