Module: SparkleFormation::SparkleAttribute

Included in:
SparkleStruct, 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

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



140
141
142
143
144
145
146
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 140

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

Yield Parameters:

  • new_struct (SparkleStruct)

    newly inserted structure which can be modified

Yield Returns:

  • (Object)

    discarded

Returns:

  • (self)


93
94
95
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 93

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


69
70
71
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 69

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

Yield Parameters:

  • new_struct (SparkleStruct)

    newly inserted structure which can be modified

Yield Returns:

  • (Object)

    discarded

Returns:

  • (self)


129
130
131
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 129

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


51
52
53
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 51

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

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

Raise an exception

See Also:

  • Kernel.raise


58
59
60
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 58

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



110
111
112
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 110

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
# 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
  result
end

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

Execute system command

Parameters:

  • command (String)

Returns:

  • (String)

    result



41
42
43
# File 'lib/sparkle_formation/sparkle_attribute.rb', line 41

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