Module: Terraspace::Compiler::Dsl::Syntax::Mod::Resource

Defined in:
lib/terraspace/compiler/dsl/syntax/mod/resource.rb

Instance Method Summary collapse

Instance Method Details

#decorate(type, props) ⇒ Object



10
11
12
13
14
15
# File 'lib/terraspace/compiler/dsl/syntax/mod/resource.rb', line 10

def decorate(type, props)
  klass = decorator_class(type)
  return props unless klass
  decorator = klass.new(type, props)
  decorator.call
end

#decorator_class(type) ⇒ Object



17
18
19
20
21
22
# File 'lib/terraspace/compiler/dsl/syntax/mod/resource.rb', line 17

def decorator_class(type)
  # IE: TerraspacePluginAws::Interfaces::Decorator
  klass_name = Terraspace::Plugin.klass("Decorator", resource: type)
  klass_name.constantize if klass_name
rescue NameError
end

#resource(type, name, props = {}) ⇒ Object



3
4
5
6
7
8
# File 'lib/terraspace/compiler/dsl/syntax/mod/resource.rb', line 3

def resource(type, name, props={})
  resource = @structure[:resource] ||= {}
  resource_type = resource[type] ||= {}
  props = decorate(type, props)
  resource_type[name] = props
end