Class: ForemanRemoteExecution::Renderer::Scope::Input
- Inherits:
-
Foreman::Renderer::Scope::Base
- Object
- Foreman::Renderer::Scope::Base
- ForemanRemoteExecution::Renderer::Scope::Input
- Includes:
- Foreman::Renderer::Scope::Macros::HostTemplate
- Defined in:
- app/lib/foreman_remote_execution/renderer/scope/input.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#input_template_instance ⇒ Object
readonly
Returns the value of attribute input_template_instance.
-
#input_values ⇒ Object
readonly
Returns the value of attribute input_values.
-
#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
- #foreign_input_set_values(target_template, overrides = {}) ⇒ Object
- #preview? ⇒ Boolean
- #render_error(message) ⇒ Object
- #render_template(template_name, input_values = {}, options = {}) ⇒ Object
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
7 8 9 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 7 def host @host end |
#input_template_instance ⇒ Object (readonly)
Returns the value of attribute input_template_instance.
7 8 9 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 7 def input_template_instance @input_template_instance end |
#input_values ⇒ Object (readonly)
Returns the value of attribute input_values.
7 8 9 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 7 def input_values @input_values end |
#invocation ⇒ Object (readonly)
Returns the value of attribute invocation.
7 8 9 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 7 def invocation @invocation end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
7 8 9 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 7 def template @template end |
Instance Method Details
#allowed_helpers ⇒ Object
51 52 53 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 51 def allowed_helpers super + [:input, :render_template, :preview?, :render_error] end |
#foreign_input_set_values(target_template, overrides = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 39 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(&:name) - overrides.keys.map(&:to_s) included_renderer = InputTemplateRenderer.new(input_set.target_template, host, invocation, nil, @preview, @templates_stack) input_values = inputs_to_generate.inject(HashWithIndifferentAccess.new) do |hash, input_name| hash.merge(input_name => included_renderer.input(input_name)) end input_values.merge(overrides) end |
#preview? ⇒ Boolean
14 15 16 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 14 def preview? !!@preview end |
#render_error(message) ⇒ Object
10 11 12 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 10 def render_error() raise ::InputTemplateRenderer::RenderError.new() end |
#render_template(template_name, input_values = {}, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/lib/foreman_remote_execution/renderer/scope/input.rb', line 18 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 if with_foreign_input_set input_values = foreign_input_set_values(template, input_values) end included_renderer = InputTemplateRenderer.new(template, host, invocation, input_values.with_indifferent_access, @preview, @templates_stack) out = included_renderer.render if included_renderer. @input_template_instance. = included_renderer. raise else out end end |