lib/cfer/core/resource.rb in cfer-0.3.0 vs lib/cfer/core/resource.rb in cfer-0.4.0

- old
+ new

@@ -1,44 +1,42 @@ -module Cfer::Cfn - class Resource < Cfer::Block - NON_PROXIED_METHODS = [:parameters, :options, :lookup_output] +module Cfer::Core + class Resource < Cfer::BlockHash + @@types = {} 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) + def properties(keyvals = {}) self[:Properties].merge!(keyvals) end - def respond_to?(method_sym) - !NON_PROXIED_METHODS.include?(method_sym) + def get_property(key) + puts self[:Properties] + self[:Properties].fetch key 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 + class << self + def resource_class(type) + @@types[type] ||= "CferExt::#{type}".split('::').inject(Object) { |o, c| o.const_get c if o && o.const_defined?(c) } || Class.new(Cfer::Core::Resource) end + + def extend_resource(type, &block) + resource_class(type).instance_eval(&block) + end end private - def camelize_property(sym) - sym.to_s.camelize.to_sym - end end end