Class: Dployr::Config::Instance

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/dployr/config/instance.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 {|_self| ... } ⇒ Instance

Returns a new instance of Instance.

Yields:

  • (_self)

Yield Parameters:



12
13
14
15
16
17
18
19
# File 'lib/dployr/config/instance.rb', line 12

def initialize
  @name = 'unnamed'
  @attributes = {}
  @scripts = {}
  @providers = {}
  @parents = []
  yield self if block_given?
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



9
10
11
# File 'lib/dployr/config/instance.rb', line 9

def attributes
  @attributes
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/dployr/config/instance.rb', line 10

def name
  @name
end

#parentsObject (readonly)

Returns the value of attribute parents.



9
10
11
# File 'lib/dployr/config/instance.rb', line 9

def parents
  @parents
end

#providersObject (readonly)

Returns the value of attribute providers.



9
10
11
# File 'lib/dployr/config/instance.rb', line 9

def providers
  @providers
end

#scriptsObject (readonly)

Returns the value of attribute scripts.



9
10
11
# File 'lib/dployr/config/instance.rb', line 9

def scripts
  @scripts
end

Instance Method Details

#add_provider(name, provider) ⇒ Object



55
56
57
# File 'lib/dployr/config/instance.rb', line 55

def add_provider(name, provider)
  @providers[name] = provider if provider.is_a? Hash
end

#add_script(script) ⇒ Object



51
52
53
# File 'lib/dployr/config/instance.rb', line 51

def add_script(script)
  @scripts.merge! script if script.is_a? Hash
end

#configure(config) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/dployr/config/instance.rb', line 21

def configure(config)
  if config.is_a? Hash
    set_attributes get_by_key config, :attributes if has config, :attributes
    set_providers get_by_key config, :providers if has config, :providers
    set_scripts get_by_key config, :scripts if has config, :scripts
    set_parents get_by_key config, :extends if has config, :extends
  end
end

#get_attribute(key) ⇒ Object



43
44
45
# File 'lib/dployr/config/instance.rb', line 43

def get_attribute(key)
  @attributes[key]
end

#get_provider(index) ⇒ Object



59
60
61
# File 'lib/dployr/config/instance.rb', line 59

def get_provider(index)
  @providers[index]
end

#get_valuesObject



30
31
32
33
34
35
36
37
# File 'lib/dployr/config/instance.rb', line 30

def get_values
  deep_copy({
    attributes: @attributes,
    scripts: @scripts,
    providers: @providers,
    parents: @parents
  })
end

#remove_attribute(key) ⇒ Object



47
48
49
# File 'lib/dployr/config/instance.rb', line 47

def remove_attribute(key)
  @attributes.remove key
end

#remove_provider(provider) ⇒ Object



63
64
65
# File 'lib/dployr/config/instance.rb', line 63

def remove_provider(provider)
  @providers.delete provider
end

#set_attribute(key, value) ⇒ Object



39
40
41
# File 'lib/dployr/config/instance.rb', line 39

def set_attribute(key, value)
  @attributes[key] = value
end