Class: Cloudshaper::StackElement

Inherits:
Object
  • Object
show all
Includes:
Aws
Defined in:
lib/cloudshaper/stack_element.rb

Overview

Defines a single terraform stack element, subclass for any element defined in terraform DSL

Direct Known Subclasses

Module, Output, Provider, Provisioner, Resource, Variable

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Aws

#post_processing_aws, taggable?

Constructor Details

#initialize(stack_module, &block) ⇒ StackElement

Returns a new instance of StackElement.



9
10
11
12
13
# File 'lib/cloudshaper/stack_element.rb', line 9

def initialize(stack_module, &block)
  @module = stack_module
  @fields = {}
  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)

Allows resource attributes to be specified with a nice syntax If the method is implemented, it will be treated as a nested resource



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cloudshaper/stack_element.rb', line 19

def method_missing(method_name, *args, &block)
  symbol = method_name.to_sym
  if args.length == 1
    if args[0].nil?
      fail "Passed nil to '#{method_name}'. Generally disallowed, subclass StackElement if you need this."
    end
    add_field(symbol, args[0])
  else
    add_field(symbol, Cloudshaper::StackElement.new(@module, &block).fields)
  end
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



7
8
9
# File 'lib/cloudshaper/stack_element.rb', line 7

def fields
  @fields
end