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.

Direct Known Subclasses

Config, Core::Resource

Constant Summary collapse

NON_PROXIED_METHODS =
[
  :parameters,
  :options,
  :lookup_output,
  :lookup_outputs,
  :__docile_undo_fallback__
].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



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

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



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

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.



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

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

#respond_to?(method_sym) ⇒ Boolean

Returns:

  • (Boolean)


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

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