Class: Chamber::ContextResolver

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ContextResolver

Returns a new instance of ContextResolver.



4
5
6
# File 'lib/chamber/context_resolver.rb', line 4

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

Class Method Details

.resolve(options = {}) ⇒ Object



39
40
41
# File 'lib/chamber/context_resolver.rb', line 39

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

Instance Method Details

#resolveObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chamber/context_resolver.rb', line 8

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

  if options[:preset] == 'rails'
    options[:basepath]     ||= options[:rootpath] + 'config'

    if options[:namespaces] == []
      require options[:rootpath].join('config', 'application')

      options[:namespaces]   = [::Rails.env]
    end
  else
    options[:basepath]     ||= options[:rootpath]
  end

  options[:basepath]         = Pathname.new(options[:basepath])

  options[:files]          ||= [ options[:basepath] + 'credentials*.yml',
                                 options[:basepath] + 'settings*.yml',
                                 options[:basepath] + 'settings' ]

  options
rescue LoadError
  options
end