Module: SparkleFormation::SparkleAttribute

Included in:
SparkleStruct, SparkleFormation::SparkleStruct::Aws, SparkleFormation::SparkleStruct::Azure, SparkleFormation::SparkleStruct::Google, SparkleFormation::SparkleStruct::Heat, SparkleFormation::SparkleStruct::Rackspace, SparkleFormation::SparkleStruct::Terraform, Translation
Defined in:
lib/sparkle_formation/sparkle_attribute.rb,
lib/sparkle_formation/sparkle_attribute/aws.rb,
lib/sparkle_formation/sparkle_attribute/heat.rb,
lib/sparkle_formation/sparkle_attribute/azure.rb,
lib/sparkle_formation/sparkle_attribute/google.rb,
lib/sparkle_formation/sparkle_attribute/rackspace.rb,
lib/sparkle_formation/sparkle_attribute/terraform.rb

Overview

Provides template helper methods

Defined Under Namespace

Modules: Aws, Azure, Google, Heat, Rackspace, Terraform

Constant Summary collapse

OpenStack =
Heat

Instance Method Summary collapse

Instance Method Details

#__attribute_key(key) ⇒ String

Format the provided key. If symbol type is provided formatting is forced. Otherwise the default formatting is applied

Parameters:

  • key (String, Symbol)

    given key

Returns:

  • (String)

    formatted key



151
152
153
154
155
156
157
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 151

def __attribute_key(key)
  if key.is_a?(::Symbol) || key.is_a?(::String)
    _process_key(key, key.is_a?(::Symbol) ? :force : nil)
  else
    key
  end
end

#_dynamic(resource_type, custom_name, options = {}) ⇒ self #_dynamic(dynamic_name, custom_name, options = {}) ⇒ self Also known as: dynamic!

Overloads:

  • #_dynamic(resource_type, custom_name, options = {}) ⇒ self
    Note:

    All other options are set into the new resource's properties

    Insert builtin resource

    Parameters:

    • resource_type (String, Symbol)

      provider resource type

    • custom_name (String, Symbol)

      custom name used for resource name generation

    • options (Hash) (defaults to: {})

    Options Hash (options):

    • :resource_name_suffix (String, NilClass)

      custom suffix to use for name generation (defaults to resource_type)

  • #_dynamic(dynamic_name, custom_name, options = {}) ⇒ self
    Note:

    All options are passed to dynamic with custom_name

    Call custom dynamic from available sparkle packs

    Parameters:

    • dynamic_name (Symbol)

      name of registered dynamic

    • custom_name (Symbol, String)

      unique name passed directly to registered dynamic

    • options (Hash) (defaults to: {})

    Options Hash (options):

    • :provider (String, Symbol)

      override provider restriction when fetching dynamic

Yields:

  • (new_struct)

    Provides newly inserted structure

Yield Parameters:

  • new_struct (SparkleStruct)

    newly inserted structure which can be modified

Yield Returns:

  • (Object)

    discarded

Returns:

  • (self)


101
102
103
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 101

def _dynamic(name, *args, &block)
  SparkleFormation.insert(name, self, *args, &block)
end

#_method(sym) ⇒ Method Also known as: method!

Note:

usually used as puts! method!(:foo).source_location

Lookup a method definition on self

Parameters:

  • sym (Symbol)

    name of method

Returns:

  • (Method)

See Also:

  • Object#method


76
77
78
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 76

def _method(*args)
  ::Kernel.instance_method(:method).bind(self).call(*args)
end

#_nest(template, *names, options = {}) ⇒ self Also known as: nest!

Nest a stack resource

Parameters:

  • template (String, Symbol)

    name of desired template

  • names (String, Symbol)

    list of optional string/symbol values for resource name generation

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :provider (String, Symbol)

    override provider restriction when fetching template

  • :overwrite_name (Truthy, Falsey)

    when set to true, will not include template name in resource name

  • :parameters (Hash)

    compile time parameter values to pass to nested template

Yields:

  • (new_struct)

    Provides newly inserted structure

Yield Parameters:

  • new_struct (SparkleStruct)

    newly inserted structure which can be modified

Yield Returns:

  • (Object)

    discarded

Returns:

  • (self)


139
140
141
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 139

def _nest(template, *args, &block)
  SparkleFormation.nest(template, self, *args, &block)
end

#_puts(obj, ...) ⇒ NilClass Also known as: puts!

Print to stdout

Parameters:

  • obj (Object)

    object to print

Returns:

  • (NilClass)

See Also:

  • Kernel.puts


56
57
58
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 56

def _puts(*args)
  $stdout.puts(*args)
end

#_raise(*args) ⇒ Object Also known as: raise!

Raise an exception

See Also:

  • Kernel.raise


64
65
66
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 64

def _raise(*args)
  ::Kernel.raise(*args)
end

#_registry(name) ⇒ Object #_registry(name, *args, options = {}) ⇒ Object Also known as: registry!

Return value of registry item

Overloads:

  • #_registry(name) ⇒ Object

    Return value from registry item with given name

    Parameters:

    • name (String, Symbol)

      registry item name

  • #_registry(name, *args, options = {}) ⇒ Object
    Note:

    args and options will be passed directly to registry item when called

    Pass given parameters to registry item with given name and return the value

    Parameters:

    • name (String, Symbol)

      registry item name

    • options (Hash) (defaults to: {})
    • options (Hash) (defaults to: {})

      :provider override provider restriction when fetching registry item

    • args (Object)

      argument list

Returns:

  • (Object)

    return value of registry item



119
120
121
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 119

def _registry(name, *args)
  SparkleFormation.registry(name, self, *args)
end

#_resource_nameString Also known as: resource_name!

Return current resource name

Returns:

  • (String)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 18

def _resource_name
  result = nil
  if _parent
    if _parent._parent == _root
      result = _parent._data.detect do |r_name, r_value|
        r_value == self
      end
      result = result.first if result
    else
      result = _parent._resource_name
    end
  end
  unless result
    ::Kernel.raise NameError.new "Failed to determine current resource name! (Check call location)"
  end
  if result.is_a?(::SparkleFormation::FunctionStruct)
    result = result._clone
  end
  result
end

#_system(command) ⇒ String Also known as: system!

Execute system command

Parameters:

  • command (String)

Returns:

  • (String)

    result



45
46
47
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 45

def _system(command)
  ::Kernel.send("`", command)
end