Sha256: 1d4d8c5552df2d7b690be650bb0f7e504106cc8adfb57eb1a5ea8b416e8d30c1

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module Cfer::Cfn
  class Resource < Cfer::Block
    NON_PROXIED_METHODS = [:parameters, :options]

    def initialize(name, type, **options, &block)
      @name = name

      self[:Type] = type
      self.merge!(options)
      self[:Properties] = HashWithIndifferentAccess.new
      build_from_block(&block)
    end

    def tag(k, v, **options)
      self[:Properties][:Tags] ||= []
      self[:Properties][:Tags].unshift({"Key" => k, "Value" => v}.merge(options))
    end

    def properties(**keyvals)
      self[:Properties].merge!(keyvals)
    end

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

    def method_missing(method_sym, *arguments, &block)
      key = camelize_property(method_sym)
      case arguments.size
      when 0
        Cfer::Core::Fn::ref(method_sym)
      when 1
        properties key => arguments.first
      else
        properties key => arguments
      end
    end

    private
    def camelize_property(sym)
      sym.to_s.camelize.to_sym
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cfer-0.1.3 lib/cfer/core/resource.rb
cfer-0.1.1 lib/cfer/core/resource.rb