Class: Chamber::ContextResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/chamber/context_resolver.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ ContextResolver

Returns a new instance of ContextResolver.



17
18
19
# File 'lib/chamber/context_resolver.rb', line 17

def initialize(**args)
  self.options = args
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



11
12
13
# File 'lib/chamber/context_resolver.rb', line 11

def options
  @options
end

Class Method Details

.resolve(**args) ⇒ Object



13
14
15
# File 'lib/chamber/context_resolver.rb', line 13

def self.resolve(**args)
  new(**args).resolve
end

Instance Method Details

#resolveObject

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Layout/LineLength, Lint/SelfAssignment



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/chamber/context_resolver.rb', line 22

def resolve
  options[:rootpath]   ||= Pathname.pwd
  options[:rootpath]     = Pathname.new(options[:rootpath])
  options[:namespaces] ||= []
  options[:preset]     ||= resolve_preset

  if %w{rails rails-engine}.include?(options[:preset])
    options[:rootpath]     = detect_engine_root                                if options[:preset]     == 'rails-engine'
    options[:namespaces]   = load_rails_default_namespaces(options[:rootpath]) if options[:namespaces] == []
    options[:basepath]   ||= options[:rootpath] + 'config'
  else
    options[:basepath]   ||= options[:rootpath]
  end

  options[:namespaces]        = resolve_namespaces(options[:namespaces])
  options[:encryption_keys]   = Keys::Encryption.resolve(filenames:  options[:encryption_keys],
                                                         namespaces: options[:namespaces],
                                                         rootpath:   options[:rootpath])
  options[:decryption_keys]   = Keys::Decryption.resolve(filenames:  options[:decryption_keys],
                                                         namespaces: options[:namespaces],
                                                         rootpath:   options[:rootpath])
  options[:basepath]          = Pathname.new(options[:basepath])
  options[:files]           ||= [
                                  options[:basepath] + 'settings*.yml',
                                  options[:basepath] + 'settings',
                                ]

  options[:signature_name]    = options[:signature_name]

  options
end