Class: Dployr::Configuration

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/dployr/configuration.rb

Constant Summary

Constants included from Utils

Utils::MERGE_OPTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

deep_copy, deep_merge, get_by_key, get_real_key, has, merge, replace_env_vars, replace_placeholders, replace_vars, template, traverse_map, traverse_mapper

Constructor Details

#initialize(attributes = {}) {|_self| ... } ⇒ Configuration

Returns a new instance of Configuration.

Yields:

  • (_self)

Yield Parameters:



10
11
12
13
14
15
16
17
# File 'lib/dployr/configuration.rb', line 10

def initialize(attributes = {})
  @default = nil
  @config = nil
  @instances = []
  @merged = false
  @attributes = attributes.is_a?(Hash) ? attributes : {}
  yield self if block_given?
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



8
9
10
# File 'lib/dployr/configuration.rb', line 8

def default
  @default
end

#instancesObject (readonly)

Returns the value of attribute instances.



8
9
10
# File 'lib/dployr/configuration.rb', line 8

def instances
  @instances
end

Instance Method Details

#add_instance(name, config) ⇒ Object



27
28
29
30
# File 'lib/dployr/configuration.rb', line 27

def add_instance(name, config)
  @instances << create_instance(name, config) if config.is_a? Hash
  @instances.last
end

#each(type = :providers) ⇒ Object



74
75
76
77
# File 'lib/dployr/configuration.rb', line 74

def each(type = :providers)
  config = get_config_all
  config.each { |i| yield i if block_given? }
end

#exists?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/dployr/configuration.rb', line 19

def exists?
  (!@default.nil? or @instances.length >= 1)
end

#get_config(name, attributes = {}) ⇒ Object



37
38
39
40
41
42
# File 'lib/dployr/configuration.rb', line 37

def get_config(name, attributes = {})
  instance = get_instance name
  attributes = @attributes.merge (attributes or {})
  raise "Instance do not exists" if instance.nil?
  render_config name, instance, attributes
end

#get_config_all(attributes = {}) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/dployr/configuration.rb', line 44

def get_config_all(attributes = {})
  config = []
  @instances.each do |i|
    config << get_config(i.name, attributes)
  end
  config
end

#get_instance(name) ⇒ Object



32
33
34
35
# File 'lib/dployr/configuration.rb', line 32

def get_instance(name)
  @instances.each { |i| return i if i.name.to_s == name.to_s }
  nil
end

#get_provider(name, provider, attributes = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dployr/configuration.rb', line 52

def get_provider(name, provider, attributes = {})
  config = get_config name, attributes
  if config.is_a? Hash
    config = config[get_real_key(config, :providers)]
    if config.is_a? Hash
      provider_data = config[get_real_key(config, provider)]
      raise "Provider #{provider} for #{name} do not exists" unless provider_data
      provider_data
    end
  end
end

#get_region(name, provider, region, attributes = {}) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/dployr/configuration.rb', line 64

def get_region(name, provider, region, attributes = {})
  provider = get_provider name, provider, attributes
  if provider.is_a? Hash
    regions = get_by_key provider, :regions
    region_data = get_by_key regions, region
    raise "Region #{region} for #{name} do not exists" unless region_data
    region_data
  end
end

#set_default(config) ⇒ Object



23
24
25
# File 'lib/dployr/configuration.rb', line 23

def set_default(config)
  @default = create_instance 'default', config if config.is_a? Hash
end