Class: Highlander::Factory::Component
- Inherits:
-
Object
- Object
- Highlander::Factory::Component
- Defined in:
- lib/highlander.factory.rb
Instance Attribute Summary collapse
-
#cfndsl_content ⇒ Object
Returns the value of attribute cfndsl_content.
-
#cfndsl_ext_files ⇒ Object
Returns the value of attribute cfndsl_ext_files.
-
#cfndsl_path ⇒ Object
Returns the value of attribute cfndsl_path.
-
#component_dir ⇒ Object
Returns the value of attribute component_dir.
-
#component_files ⇒ Object
Returns the value of attribute component_files.
-
#config ⇒ Object
Returns the value of attribute config.
-
#distribution_bucket ⇒ Object
Returns the value of attribute distribution_bucket.
-
#distribution_prefix ⇒ Object
Returns the value of attribute distribution_prefix.
-
#highlander_dsl ⇒ Object
Returns the value of attribute highlander_dsl.
-
#highlander_dsl_path ⇒ Object
Returns the value of attribute highlander_dsl_path.
-
#lambda_src_files ⇒ Object
Returns the value of attribute lambda_src_files.
-
#mappings ⇒ Object
Returns the value of attribute mappings.
-
#name ⇒ Object
Returns the value of attribute name.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(component_name, component_dir) ⇒ Component
constructor
A new instance of Component.
- #load(config_override = nil) ⇒ Object
- #load_config ⇒ Object
- #loadDepandantExt ⇒ Object
Constructor Details
#initialize(component_name, component_dir) ⇒ Component
Returns a new instance of Component.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/highlander.factory.rb', line 28 def initialize(component_name, component_dir) @name = component_name @component_dir = component_dir @mappings = {} @version = nil @distribution_bucket = nil @distribution_prefix = nil @component_files = [] @cfndsl_ext_files = [] @lambda_src_files = [] end |
Instance Attribute Details
#cfndsl_content ⇒ Object
Returns the value of attribute cfndsl_content.
13 14 15 |
# File 'lib/highlander.factory.rb', line 13 def cfndsl_content @cfndsl_content end |
#cfndsl_ext_files ⇒ Object
Returns the value of attribute cfndsl_ext_files.
13 14 15 |
# File 'lib/highlander.factory.rb', line 13 def cfndsl_ext_files @cfndsl_ext_files end |
#cfndsl_path ⇒ Object
Returns the value of attribute cfndsl_path.
13 14 15 |
# File 'lib/highlander.factory.rb', line 13 def cfndsl_path @cfndsl_path end |
#component_dir ⇒ Object
Returns the value of attribute component_dir.
13 14 15 |
# File 'lib/highlander.factory.rb', line 13 def component_dir @component_dir end |
#component_files ⇒ Object
Returns the value of attribute component_files.
13 14 15 |
# File 'lib/highlander.factory.rb', line 13 def component_files @component_files end |
#config ⇒ Object
Returns the value of attribute config.
13 14 15 |
# File 'lib/highlander.factory.rb', line 13 def config @config end |
#distribution_bucket ⇒ Object
Returns the value of attribute distribution_bucket.
13 14 15 |
# File 'lib/highlander.factory.rb', line 13 def distribution_bucket @distribution_bucket end |
#distribution_prefix ⇒ Object
Returns the value of attribute distribution_prefix.
13 14 15 |
# File 'lib/highlander.factory.rb', line 13 def distribution_prefix @distribution_prefix end |
#highlander_dsl ⇒ Object
Returns the value of attribute highlander_dsl.
13 14 15 |
# File 'lib/highlander.factory.rb', line 13 def highlander_dsl @highlander_dsl end |
#highlander_dsl_path ⇒ Object
Returns the value of attribute highlander_dsl_path.
13 14 15 |
# File 'lib/highlander.factory.rb', line 13 def highlander_dsl_path @highlander_dsl_path end |
#lambda_src_files ⇒ Object
Returns the value of attribute lambda_src_files.
13 14 15 |
# File 'lib/highlander.factory.rb', line 13 def lambda_src_files @lambda_src_files end |
#mappings ⇒ Object
Returns the value of attribute mappings.
13 14 15 |
# File 'lib/highlander.factory.rb', line 13 def mappings @mappings end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/highlander.factory.rb', line 13 def name @name end |
#version ⇒ Object
Returns the value of attribute version.
13 14 15 |
# File 'lib/highlander.factory.rb', line 13 def version @version end |
Instance Method Details
#load(config_override = nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/highlander.factory.rb', line 61 def load(config_override = nil) if @component_dir.start_with? 'http' raise StandardError, 'http(s) sources not supported yet' end @highlander_dsl_path = "#{@component_dir}/#{@name}.highlander.rb" @cfndsl_path = "#{@component_dir}/#{@name}.cfndsl.rb" candidate_config_path = "#{@component_dir}/#{@name}.config.yaml" candidate_mappings_path = "#{@component_dir}/*.mappings.yaml" candidate_dynamic_mappings_path = "#{@component_dir}/#{@name}.mappings.rb" @cfndsl_ext_files += Dir["#{@component_dir}/ext/cfndsl/*.rb"] @lambda_src_files += Dir["#{@component_dir}/lambdas/**/*"].find_all {|p| not File.directory? p} @component_files += @cfndsl_ext_files @component_files += @lambda_src_files @config = {} if @config.nil? @config.extend config_override unless config_override.nil? @config['component_version'] = @version unless @version.nil? # allow override of components # config_override.each do |key, value| # @config[key] = value # end unless config_override.nil? Dir[candidate_mappings_path].each do |mapping_file| mappings = YAML.load(File.read(mapping_file)) @component_files << mapping_file mappings.each do |name, map| @mappings[name] = map end unless mappings.nil? end if File.exist? candidate_dynamic_mappings_path require candidate_dynamic_mappings_path @component_files << candidate_dynamic_mappings_path end # 1st pass - parse the file @component_files << @highlander_dsl_path @highlander_dsl = eval(File.read(@highlander_dsl_path), binding) # set version if not defined @highlander_dsl.ComponentVersion(@version) unless @version.nil? # Handle name and description defaults if they are not specified # in template itself if @highlander_dsl.name.nil? @highlander_dsl.name = @name end if @highlander_dsl.description.nil? @highlander_dsl.Description("#{@highlander_dsl.name} - #{@highlander_dsl.version}") end # set (override) distribution options @highlander_dsl.DistributionBucket(@distribution_bucket) unless @distribution_bucket.nil? @highlander_dsl.DistributionPrefix(@distribution_prefix) unless @distribution_prefix.nil? if File.exist? @cfndsl_path @component_files << @cfndsl_path @cfndsl_content = File.read(@cfndsl_path) @cfndsl_content.strip! # if there is CloudFormation do [content] end extract only contents ### Regex \s is whitespace match_data = /^CloudFormation do\s(.*)end\s?$/m.match(@cfndsl_content) if not match_data.nil? @cfndsl_content = match_data[1] end else @cfndsl_content = '' end loadDepandantExt() end |
#load_config ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/highlander.factory.rb', line 40 def load_config() @config = {} if @config.nil? Dir["#{@component_dir}/*.config.yaml"].each do |config_file| partial_config = YAML.load(File.read(config_file)) unless partial_config.nil? @config.extend(partial_config) @component_files << config_file end end end |
#loadDepandantExt ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/highlander.factory.rb', line 52 def loadDepandantExt() @highlander_dsl.dependson_components.each do |requirement| requirement.component_loaded.cfndsl_ext_files.each do |file| cfndsl_ext_files << file end end end |