Class: Aperitiiif::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/aperitiiif/config.rb

Overview

has smell :reek:Attribute TO DO COMMENT

Constant Summary collapse

DELEGATE =
%i[puts p].freeze
DEFAULT_VALUES =
{
  'build_dir' => './build',
  'source_dir' => './src/data',
  'service_namespace' => 'aperitiiif-batch'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seed = {}) ⇒ Config

Returns a new instance of Config.



17
18
19
20
21
22
# File 'lib/aperitiiif/config.rb', line 17

def initialize(seed = {})
  @hash       = DEFAULT_VALUES.merge(seed)
  @namespace  = batch_namespace

  validate
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



24
25
26
27
28
# File 'lib/aperitiiif/config.rb', line 24

def method_missing(method, *args, &block)
  return super if DELEGATE.include? method

  @hash.fetch method.to_s, ''
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



8
9
10
# File 'lib/aperitiiif/config.rb', line 8

def hash
  @hash
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



8
9
10
# File 'lib/aperitiiif/config.rb', line 8

def namespace
  @namespace
end

Instance Method Details

#batch_namespace(dir = nil) ⇒ Object



40
41
42
43
44
# File 'lib/aperitiiif/config.rb', line 40

def batch_namespace(dir = nil)
  dir ||= FileUtils.pwd
  name = dir.split(service_namespace).last
  Utils.slugify name
end

#html_build_dirObject



48
# File 'lib/aperitiiif/config.rb', line 48

def html_build_dir          = "#{build_dir}/html"

#image_build_dirObject



47
# File 'lib/aperitiiif/config.rb', line 47

def image_build_dir         = "#{build_dir}/image"

#presentation_build_dirObject



46
# File 'lib/aperitiiif/config.rb', line 46

def presentation_build_dir  = "#{build_dir}/presentation"

#records_defaultsObject



50
# File 'lib/aperitiiif/config.rb', line 50

def records_defaults        = @hash.dig('records', 'defaults') || {}

#records_fileObject



49
# File 'lib/aperitiiif/config.rb', line 49

def records_file            = @hash.dig('records', 'file') || ''

#respond_to_missing?(method, _args) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/aperitiiif/config.rb', line 30

def respond_to_missing?(method, _args)
  DELEGATE.include?(method) or super
end

#validateObject

should check for more reqs

Raises:



35
36
37
38
# File 'lib/aperitiiif/config.rb', line 35

def validate
  raise Aperitiiif::Error, "Config is missing a valid 'namespace' for the batch." if namespace.empty?
  raise Aperitiiif::Error, "Config is missing 'label' for the batch." if label.empty?
end