Class: Orchparty::Transformations::Variable
- Inherits:
-
Object
- Object
- Orchparty::Transformations::Variable
- Defined in:
- lib/orchparty/transformations/variable.rb
Instance Method Summary collapse
- #build_context(application:, service:) ⇒ Object
- #eval_value(context, value) ⇒ Object
-
#initialize(opts = {}) ⇒ Variable
constructor
A new instance of Variable.
- #transform(ast) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Variable
Returns a new instance of Variable.
5 6 7 |
# File 'lib/orchparty/transformations/variable.rb', line 5 def initialize(opts = {}) @force_variable_definition = opts[:force_variable_definition] end |
Instance Method Details
#build_context(application:, service:) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/orchparty/transformations/variable.rb', line 36 def build_context(application:, service:) application._variables ||= {} variables = application._variables.merge(service._variables) context = Context.new(variables.merge({application: application.merge(application._variables), service: service.merge(service._variables)})) context._force_variable_definition = @force_variable_definition context end |
#eval_value(context, value) ⇒ Object
32 33 34 |
# File 'lib/orchparty/transformations/variable.rb', line 32 def eval_value(context, value) context.instance_exec(&value) end |
#transform(ast) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/orchparty/transformations/variable.rb', line 9 def transform(ast) ast.applications.each do |_, application| application.services = application.services.each do |_, service| service.deep_transform_values! do |v| if v.respond_to?(:call) eval_value(build_context(application: application, service: service), v) elsif v.is_a? Array v.map do |v| if v.respond_to?(:call) eval_value(build_context(application: application, service: service), v) else v end end else v end end end end ast end |