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.



6
7
8
# File 'lib/chamber/context_resolver.rb', line 6

def initialize(options = {})
  self.options = Hashie::Mash.new(options)
end

Class Method Details

.resolve(options = {}) ⇒ Object



41
42
43
# File 'lib/chamber/context_resolver.rb', line 41

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

Instance Method Details

#resolveObject



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
38
39
# File 'lib/chamber/context_resolver.rb', line 10

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