Class: ForemanRemoteExecution::Renderer::Scope::Input
- Inherits:
-
Foreman::Renderer::Scope::Template
- Object
- Foreman::Renderer::Scope::Template
- ForemanRemoteExecution::Renderer::Scope::Input
- Extended by:
- ApipieDSL::Class
- Includes:
- Foreman::Renderer::Scope::Macros::HostTemplate
- Defined in:
- app/lib/foreman_remote_execution/renderer/scope/input.rb
Instance Attribute Summary collapse
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#error_message ⇒ Object
Returns the value of attribute error_message.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#input_template_instance ⇒ Object
readonly
Returns the value of attribute input_template_instance.
-
#invocation ⇒ Object
readonly
Returns the value of attribute invocation.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #allowed_helpers ⇒ Object
- #cached(key, &block) ⇒ Object
- #foreign_input_set_values(target_template, overrides = {}) ⇒ Object
- #input(name) ⇒ Object
- #preview? ⇒ Boolean
- #render_error(message) ⇒ Object
-
#render_template(template_name, input_values = {}, options = {}) ⇒ Object
rubocop:enable Lint/InterpolationCheck.
Instance Attribute Details
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
8 9 10 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 8 def current_user @current_user end |
#error_message ⇒ Object
Returns the value of attribute error_message.
9 10 11 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 9 def @error_message end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 8 def host @host end |
#input_template_instance ⇒ Object (readonly)
Returns the value of attribute input_template_instance.
8 9 10 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 8 def input_template_instance @input_template_instance end |
#invocation ⇒ Object (readonly)
Returns the value of attribute invocation.
8 9 10 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 8 def invocation @invocation end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
8 9 10 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 8 def template @template end |
Instance Method Details
#allowed_helpers ⇒ Object
110 111 112 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 110 def allowed_helpers super + [:input, :render_template, :preview?, :render_error, :current_user] end |
#cached(key, &block) ⇒ Object
38 39 40 41 42 43 44 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 38 def cached(key, &block) return yield if preview? cache_key = "#{JobInvocation::CACHE_PREFIX}_#{invocation.job_invocation_id}_#{key}" Rails.logger.debug "cache hit for #{cache_key}" if Rails.cache.exist?(cache_key) Rails.cache.fetch(cache_key, &block) end |
#foreign_input_set_values(target_template, overrides = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 81 def foreign_input_set_values(target_template, overrides = {}) input_set = @template.foreign_input_sets.find_by(:target_template_id => target_template) return overrides if input_set.nil? inputs_to_generate = input_set.inputs.map { |i| i.name.to_s } - overrides.keys.map(&:to_s) input_values = inputs_to_generate.inject(HashWithIndifferentAccess.new) do |hash, input_name| hash.merge(input_name.to_s => input(input_name)) end input_values.merge(overrides).with_indifferent_access end |
#input(name) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 98 def input(name) return template_input_values[name.to_s] if template_input_values.key?(name.to_s) input = find_by_name(template.template_inputs_with_foreign, name) if input @preview ? input.preview(self) : input.value(self) else = _('input macro with name \'%s\' used, but no input with such name defined for this template') % name raise UndefinedInput, "Rendering failed, no input with name #{name} for input macro found" end end |
#preview? ⇒ Boolean
34 35 36 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 34 def preview? !!@preview end |
#render_error(message) ⇒ Object
27 28 29 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 27 def render_error() raise ::InputTemplateRenderer::RenderError.new() end |
#render_template(template_name, input_values = {}, options = {}) ⇒ Object
rubocop:enable Lint/InterpolationCheck
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 56 def render_template(template_name, input_values = {}, = {}) .assert_valid_keys(:with_foreign_input_set) with_foreign_input_set = .fetch(:with_foreign_input_set, true) template = @template.class.("view_#{@template.class.to_s.underscore.pluralize}").find_by(name: template_name) unless template self. = _('included template \'%s\' not found') % template_name raise end default_values = template.default_input_values(input_values.keys) if with_foreign_input_set input_values = foreign_input_set_values(template, input_values) end input_values = default_values.merge(input_values).with_indifferent_access included_renderer = InputTemplateRenderer.new(template, host, invocation, input_values, @preview, @templates_stack) out = included_renderer.render if included_renderer. @input_template_instance. = included_renderer. raise else out end end |