Class: Terraframe::ScriptItem
- Inherits:
-
Object
- Object
- Terraframe::ScriptItem
- Defined in:
- lib/terraframe/script_item.rb
Direct Known Subclasses
AWS::AWSTagBlock, Connection, Provider, Provisioner, Resource
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
- #id_of(resource_type, resource_name) ⇒ Object
-
#initialize(vars, context, &block) ⇒ ScriptItem
constructor
A new instance of ScriptItem.
-
#method_missing(method_name, *args, &block) ⇒ Object
DSL FUNCTIONS BELOW.
- #output_of(resource_type, resource_name, output_type) ⇒ Object
- #to_json(*a) ⇒ Object
Constructor Details
#initialize(vars, context, &block) ⇒ ScriptItem
Returns a new instance of ScriptItem.
10 11 12 13 14 15 16 |
# File 'lib/terraframe/script_item.rb', line 10 def initialize(vars, context, &block) @fields = {} @context = context @vars = Hashie::Mash.new(vars) instance_eval &block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
DSL FUNCTIONS BELOW
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/terraframe/script_item.rb', line 26 def method_missing(method_name, *args, &block) if args.length == 1 if args[0] == nil raise "Passed nil to '#{method_name}'. Generally disallowed, subclass ScriptItem if you need this." end @fields[method_name.to_sym] = args[0] else raise "Multiple fields passed to a scalar auto-argument '#{method_name}'." end end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
8 9 10 |
# File 'lib/terraframe/script_item.rb', line 8 def context @context end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
6 7 8 |
# File 'lib/terraframe/script_item.rb', line 6 def fields @fields end |
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
7 8 9 |
# File 'lib/terraframe/script_item.rb', line 7 def vars @vars end |
Instance Method Details
#id_of(resource_type, resource_name) ⇒ Object
42 43 44 |
# File 'lib/terraframe/script_item.rb', line 42 def id_of(resource_type, resource_name) output_of(resource_type, resource_name, :id) end |
#output_of(resource_type, resource_name, output_type) ⇒ Object
39 40 41 |
# File 'lib/terraframe/script_item.rb', line 39 def output_of(resource_type, resource_name, output_type) "${#{resource_type}.#{resource_name}.#{output_type}}" end |
#to_json(*a) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/terraframe/script_item.rb', line 18 def to_json(*a) sanitized = @fields sanitized.delete("\#") sanitized.to_json(*a) end |