Class: Cfer::BlockHash

Inherits:
Block
  • Object
show all
Defined in:
lib/cfer/block.rb

Overview

BlockHash is a Block that responds to DSL-style properties.

Constant Summary collapse

NON_PROXIED_METHODS =
[
  :parameters,
  :options,
  :lookup_output,
  :lookup_outputs
].freeze

Instance Method Summary collapse

Methods inherited from Block

#build_from_block, #build_from_file, #build_from_string, #include_file, #post_block, #pre_block

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/cfer/block.rb', line 85

def method_missing(method_sym, *arguments, &block)
  key = camelize_property(method_sym)
  properties key =>
    case arguments.size
    when 0
      if block
        BlockHash.new.build_from_block(&block)
      else
        raise "Expected a value or block when setting property #{key}"
      end
    when 1
      arguments.first
    else
      arguments
    end
end

Instance Method Details

#get_property(key) ⇒ Object

Gets the current value of a given property

Parameters:

  • key (String)

    The name of the property to fetch



77
78
79
# File 'lib/cfer/block.rb', line 77

def get_property(key)
  self.fetch key
end

#properties(keyvals = {}) ⇒ Object

Directly sets raw properties in the underlying CloudFormation structure.

Parameters:

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

    The properties to set on this object.



71
72
73
# File 'lib/cfer/block.rb', line 71

def properties(keyvals = {})
  self.merge!(keyvals)
end

#respond_to?(method_sym) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/cfer/block.rb', line 81

def respond_to?(method_sym)
  !non_proxied_methods.include?(method_sym)
end