Class: Highlander::Dsl::Component

Inherits:
DslBase
  • Object
show all
Defined in:
lib/highlander.dsl.component.rb

Instance Attribute Summary collapse

Attributes inherited from DslBase

#config

Instance Method Summary collapse

Methods inherited from DslBase

#method_missing

Constructor Details

#initialize(parent, name, template, param_values, component_sources = [], config = {}, export_config = {}, distribution_format = 'yaml') ⇒ Component

Returns a new instance of Component.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/highlander.dsl.component.rb', line 35

def initialize(parent,
    name,
    template,
    param_values,
    component_sources = [],
    config = {},
    export_config = {},
    distribution_format = 'yaml')

  @parent = parent
  @config = config
  @export_config = export_config
  @component_sources = component_sources

  template_name = template
  template_version = 'latest'
  if template.include?('@') and not (template.start_with? 'git')
    template_name = template.split('@')[0]
    template_version = template.split('@')[1]
  end

  @template = template_name
  @template_version = template_version
  @name = name
  @param_values = param_values

  # distribution settings
  @distribution_format = distribution_format
  # by default components located at same location as master stack
  @distribution_location = '.'
  build_distribution_url

  # load component
  factory = Highlander::Factory::ComponentFactory.new(@component_sources)
  @component_loaded = factory.findComponent(
      @template,
      @template_version
  )
  @component_loaded.config.extend @config

  @parameters = []
  # load_parameters
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Highlander::Dsl::DslBase

Instance Attribute Details

#component_config_override ⇒ Object

Returns the value of attribute component_config_override.



21
22
23
# File 'lib/highlander.dsl.component.rb', line 21

def component_config_override
  @component_config_override
end

#component_loaded ⇒ Object

Returns the value of attribute component_loaded.



21
22
23
# File 'lib/highlander.dsl.component.rb', line 21

def component_loaded
  @component_loaded
end

#distribution_format ⇒ Object

Returns the value of attribute distribution_format.



21
22
23
# File 'lib/highlander.dsl.component.rb', line 21

def distribution_format
  @distribution_format
end

#distribution_location ⇒ Object

Returns the value of attribute distribution_location.



21
22
23
# File 'lib/highlander.dsl.component.rb', line 21

def distribution_location
  @distribution_location
end

#distribution_url ⇒ Object

Returns the value of attribute distribution_url.



21
22
23
# File 'lib/highlander.dsl.component.rb', line 21

def distribution_url
  @distribution_url
end

#export_config ⇒ Object

Returns the value of attribute export_config.



21
22
23
# File 'lib/highlander.dsl.component.rb', line 21

def export_config
  @export_config
end

#name ⇒ Object

Returns the value of attribute name.



21
22
23
# File 'lib/highlander.dsl.component.rb', line 21

def name
  @name
end

#param_values ⇒ Object

Returns the value of attribute param_values.



21
22
23
# File 'lib/highlander.dsl.component.rb', line 21

def param_values
  @param_values
end

#parameters ⇒ Object

Returns the value of attribute parameters.



21
22
23
# File 'lib/highlander.dsl.component.rb', line 21

def parameters
  @parameters
end

#parent ⇒ Object

Returns the value of attribute parent.



21
22
23
# File 'lib/highlander.dsl.component.rb', line 21

def parent
  @parent
end

#template ⇒ Object

Returns the value of attribute template.



21
22
23
# File 'lib/highlander.dsl.component.rb', line 21

def template
  @template
end

#template_version ⇒ Object

Returns the value of attribute template_version.



21
22
23
# File 'lib/highlander.dsl.component.rb', line 21

def template_version
  @template_version
end

Instance Method Details

#build_distribution_url ⇒ Object



96
97
98
99
# File 'lib/highlander.dsl.component.rb', line 96

def build_distribution_url
  @distribution_location = @parent.distribute_url unless @parent.distribute_url.nil?
  @distribution_url = "#{@distribution_location}/#{@name}.compiled.#{@distribution_format}"
end

#distribute_bucket=(value) ⇒ Object



83
84
85
# File 'lib/highlander.dsl.component.rb', line 83

def distribute_bucket=(value)
  @component_loaded.distribution_bucket = value
end

#distribute_prefix=(value) ⇒ Object



87
88
89
# File 'lib/highlander.dsl.component.rb', line 87

def distribute_prefix=(value)
  @component_loaded.distribution_prefix = value
end

#load(component_config_override = {}) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/highlander.dsl.component.rb', line 101

def load(component_config_override = {})
  # check for component config on parent
  parent = @parent

  # Highest priority is DSL defined configuration
  component_config_override.extend @config

  @component_config_override = component_config_override

  @component_loaded.load @component_config_override
end

#load_parameters ⇒ Object

Parameters should be lazy loaded, that is late-binding should happen once all parameters and mappings are known



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/highlander.dsl.component.rb', line 115

def load_parameters
  component_dsl = @component_loaded.highlander_dsl
  component_dsl.parameters.param_list.each do |component_param|
    param = Highlander::Dsl::SubcomponentParameter.new
    param.name = component_param.name
    param.cfndsl_value = SubcomponentParamValueResolver.resolveValue(
        @parent,
        self,
        component_param)
    @parameters << param
  end
end

#version=(value) ⇒ Object



79
80
81
# File 'lib/highlander.dsl.component.rb', line 79

def version=(value)
  @component_loaded.version = value
end