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(options = {}) ⇒ ContextResolver

Returns a new instance of ContextResolver.



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

def initialize(options = {})
  self.options = options.dup
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

.resolve(options = {}) ⇒ Object

rubocop:enable Metrics/AbcSize, Metrics/LineLength



49
50
51
# File 'lib/chamber/context_resolver.rb', line 49

def self.resolve(options = {})
  new(options).resolve
end

Instance Method Details

#resolveObject

rubocop:disable Metrics/AbcSize, Metrics/LineLength



19
20
21
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
# File 'lib/chamber/context_resolver.rb', line 19

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[: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
end