Class: Emendate::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/emendate/options.rb

Overview

To add or update an option there are several places to edit:

  • Emendate (lib/emendate.rb) – register the options with dry-configurable

  • Emendate::OptionsContract – used to validate configs

  • docs/options.adoc

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opthash = {}) ⇒ Options

Returns a new instance of Options.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/emendate/options.rb', line 18

def initialize(opthash = {})
  return if opthash.empty?

  @opthash = opthash
  validation_errs = Emendate::OptionsContract.new
    .call(**opthash)
    .errors
    .to_h
  if validation_errs.empty?
    set_options
    handle_edtf_shortcut if Emendate.options.edtf
    handle_collectionspace if Emendate.options.dialect == :collectionspace
    if Emendate.options.dialect == :lyrasis_pseudo_edtf
      handle_lyrasis_pseudo_edtf
    end
  else
    report_errors_and_exit(validation_errs)
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/emendate/options.rb', line 12

def options
  @options
end

Class Method Details

.listObject



14
15
16
# File 'lib/emendate/options.rb', line 14

def self.list
  Emendate.config.options.values.each { |opt, val| puts "#{opt}: #{val}" }
end

Instance Method Details

#merge(opthash) ⇒ Object



38
39
40
41
# File 'lib/emendate/options.rb', line 38

def merge(opthash)
  @options = options.merge(opthash)
  verify
end