Module: SparkleFormation::SparkleAttribute::Google
- Included in:
- SparkleFormation::SparkleStruct::Google
- Defined in:
- lib/sparkle_formation/sparkle_attribute/google.rb
Overview
Google specific helper implementations
Constant Summary collapse
- CHARACTER_COLLECTION =
("a".."z").to_a
Class Method Summary collapse
Instance Method Summary collapse
-
#_env(e_name) ⇒ SparkleFormation::JinjaExpressionStruct
(also: #env!)
Request deployment manager environment variable.
-
#_google_dynamic!(name, *args, &block) ⇒ Object
Customized dynamic to provide automatic unique name generation for built in resources.
-
#_jinja ⇒ SparkleFormation::JinjaExpressionStruct
(also: #jinja!, #fn!)
Jinja function string wrapper.
-
#_property(p_name) ⇒ SparkleFormation::JinjaExpressionStruct
(also: #property!, #properties!)
Access a property value supplied to template.
-
#_ref(r_name) ⇒ SparkleFormation::GoogleStruct
(also: #ref!)
Reference generator.
-
#_stack_output(stack_name, output_name) ⇒ SparkleFormation::JinjaExpressionStruct
(also: #stack_output!)
Reference output value from nested stack.
-
#_statement(line) ⇒ SparkleFormation::JinjaStatementStruct
(also: #statement!)
Generate a statement.
Class Method Details
.included(klass) ⇒ Object
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 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sparkle_formation/sparkle_attribute/google.rb', line 11 def self.included(klass) klass.const_set(:CAMEL_STYLE, :no_leading) klass.class_eval do def _google_dump result = _non_google_attribute_struct_dump if _parent.nil? sparkle_root = {} if result.key?("resources") && result["resources"].is_a?(Hash) resources = result.delete("resources") || {} sparkle_root = (resources.delete(_self.name) || {}).fetch("properties", {}) result["resources"] = resources.map do |r_name, r_content| r_content.merge("name" => r_name) end outputs = result.delete("outputs") || {} result["outputs"] = outputs.map do |o_name, o_content| o_content.merge("name" => o_name) end if _self.parent.nil? result = { "resources" => [{ "name" => _self.name, "type" => _self.stack_resource_type, "properties" => { "stack" => result, }.merge(sparkle_root), }], } end end end result end alias_method :_non_google_attribute_struct_dump, :_dump alias_method :_dump, :_google_dump alias_method :dump!, :_google_dump alias_method :_non_google_dynamic!, :dynamic! alias_method :dynamic!, :_google_dynamic! end end |
Instance Method Details
#_env(e_name) ⇒ SparkleFormation::JinjaExpressionStruct Also known as: env!
Request deployment manager environment variable
108 109 110 111 |
# File 'lib/sparkle_formation/sparkle_attribute/google.rb', line 108 def _env(e_name) __t_stringish(e_name) _jinja.env[__attribute_key(e_name)] end |
#_google_dynamic!(name, *args, &block) ⇒ Object
generate unique names using the :sparkle_unique
argument
Customized dynamic to provide automatic unique name generation for built in resources
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/sparkle_formation/sparkle_attribute/google.rb', line 58 def _google_dynamic!(name, *args, &block) if args.delete(:sparkle_unique) seed = Zlib.crc32(_self.root_path.map(&:name).join("-")) gen = Random.new(seed) suffix = Array.new(10) do CHARACTER_COLLECTION.at( gen.rand(CHARACTER_COLLECTION.size) ) end.join config_hash = args.detect { |a| a.is_a?(Hash) } unless config_hash config_hash = {} args.push(config_hash) end config_hash[:resource_name_suffix] = "-#{suffix}" args[0] = args.first.to_s.tr("_", "-").downcase end _non_google_dynamic!(name, *args, &block) end |
#_jinja ⇒ SparkleFormation::JinjaExpressionStruct Also known as: jinja!, fn!
Jinja function string wrapper
97 98 99 |
# File 'lib/sparkle_formation/sparkle_attribute/google.rb', line 97 def _jinja ::SparkleFormation::JinjaExpressionStruct.new end |
#_property(p_name) ⇒ SparkleFormation::JinjaExpressionStruct Also known as: property!, properties!
Provide lookup validation that defined p_name is valid
Access a property value supplied to template
120 121 122 123 |
# File 'lib/sparkle_formation/sparkle_attribute/google.rb', line 120 def _property(p_name) __t_stringish(p_name) _jinja.properties[__attribute_key(p_name)] end |
#_ref(r_name) ⇒ SparkleFormation::GoogleStruct Also known as: ref!
Reference generator. Will lookup defined resource name to validate exist.
83 84 85 86 87 88 89 90 |
# File 'lib/sparkle_formation/sparkle_attribute/google.rb', line 83 def _ref(r_name) __t_stringish(r_name) if _root.resources.set!(r_name).nil? ::Kernel.raise ::SparkleFormation::Error::NotFound::Resource.new(:name => r_name) else ::SparkleFormation::GoogleStruct.new("ref").set!(__attribute_key(r_name)) end end |
#_stack_output(stack_name, output_name) ⇒ SparkleFormation::JinjaExpressionStruct Also known as: stack_output!
Reference output value from nested stack
143 144 145 146 147 |
# File 'lib/sparkle_formation/sparkle_attribute/google.rb', line 143 def _stack_output(stack_name, output_name) __t_stringish(stack_name) __t_stringish(output_name) _ref(stack_name)._set(output_name) end |
#_statement(line) ⇒ SparkleFormation::JinjaStatementStruct Also known as: statement!
Generate a statement
132 133 134 |
# File 'lib/sparkle_formation/sparkle_attribute/google.rb', line 132 def _statement(line) ::SparkleFormation::JinjaStatementStruct.new(line) end |