Class: JobInvocationComposer::UiParams
- Inherits:
-
Object
- Object
- JobInvocationComposer::UiParams
- Defined in:
- app/models/job_invocation_composer.rb
Instance Attribute Summary collapse
-
#ui_params ⇒ Object
readonly
Returns the value of attribute ui_params.
Instance Method Summary collapse
- #blank_to_nil(thing) ⇒ Object
- #concurrency_control_params ⇒ Object
- #execution_timeout_interval ⇒ Object
-
#initialize(ui_params) ⇒ UiParams
constructor
A new instance of UiParams.
- #job_invocation_base ⇒ Object
- #params ⇒ Object
- #providers_base ⇒ Object
- #targeting(targeting_params) ⇒ Object
-
#template_invocations_params ⇒ Object
TODO: Fix this comment parses params to get job templates in form of id => attributes for selected job templates, e.g.
- #triggering ⇒ Object
Constructor Details
#initialize(ui_params) ⇒ UiParams
Returns a new instance of UiParams.
8 9 10 |
# File 'app/models/job_invocation_composer.rb', line 8 def initialize(ui_params) @ui_params = ui_params end |
Instance Attribute Details
#ui_params ⇒ Object (readonly)
Returns the value of attribute ui_params.
7 8 9 |
# File 'app/models/job_invocation_composer.rb', line 7 def ui_params @ui_params end |
Instance Method Details
#blank_to_nil(thing) ⇒ Object
44 45 46 |
# File 'app/models/job_invocation_composer.rb', line 44 def blank_to_nil(thing) thing.presence end |
#concurrency_control_params ⇒ Object
80 81 82 83 84 |
# File 'app/models/job_invocation_composer.rb', line 80 def concurrency_control_params { :level => job_invocation_base[:concurrency_level], } end |
#execution_timeout_interval ⇒ Object
37 38 39 40 41 42 |
# File 'app/models/job_invocation_composer.rb', line 37 def execution_timeout_interval providers_base.values.map do |provider| id = provider[:job_template_id] provider.fetch(:job_templates, {}).fetch(id, {})[:execution_timeout_interval] end.first end |
#job_invocation_base ⇒ Object
29 30 31 |
# File 'app/models/job_invocation_composer.rb', line 29 def job_invocation_base ui_params.fetch(:job_invocation, {}) end |
#params ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/job_invocation_composer.rb', line 12 def params { :job_category => job_invocation_base[:job_category], :targeting => targeting(ui_params.fetch(:targeting, {})), :triggering => triggering, :host_ids => ui_params[:host_ids], :remote_execution_feature_id => job_invocation_base[:remote_execution_feature_id], :description_format => job_invocation_base[:description_format], :ssh_user => blank_to_nil(job_invocation_base[:ssh_user]), :password => blank_to_nil(job_invocation_base[:password]), :key_passphrase => blank_to_nil(job_invocation_base[:key_passphrase]), :effective_user_password => blank_to_nil(job_invocation_base[:effective_user_password]), :concurrency_control => concurrency_control_params, :execution_timeout_interval => execution_timeout_interval, :time_to_pickup => job_invocation_base[:time_to_pickup], :template_invocations => template_invocations_params }.with_indifferent_access end |
#providers_base ⇒ Object
33 34 35 |
# File 'app/models/job_invocation_composer.rb', line 33 def providers_base job_invocation_base.fetch(:providers, {}) end |
#targeting(targeting_params) ⇒ Object
97 98 99 |
# File 'app/models/job_invocation_composer.rb', line 97 def targeting(targeting_params) targeting_params.merge(:user_id => User.current.id) end |
#template_invocations_params ⇒ Object
TODO: Fix this comment parses params to get job templates in form of id => attributes for selected job templates, e.g.
"459" => {,
"454" => {
"input_values" => {
"2" => {
"value" => ""
},
"5" => {
"value" => ""
}
}
}
}
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/job_invocation_composer.rb', line 63 def template_invocations_params providers_base.values.map do |template_params| template_base = template_params.fetch(:job_templates, {}).fetch(template_params[:job_template_id], {}).dup.with_indifferent_access template_base[:template_id] = template_params[:job_template_id] input_values_params = template_base.fetch(:input_values, {}) template_base[:input_values] = input_values_params.map do |id, values| values.merge(:template_input_id => id) end provider_values_params = template_base.fetch(:provider_input_values, {}) template_base[:provider_input_values] = provider_values_params.map do |key, hash| { :name => key, :value => hash[:value] } end template_base end end |
#triggering ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'app/models/job_invocation_composer.rb', line 86 def triggering return {} unless ui_params.key?(:triggering) trig = ui_params[:triggering] keys = (1..5).map { |i| "end_time(#{i}i)" } values = trig.fetch(:end_time, {}).values_at(*keys) return trig if values.any?(&:nil?) trig.merge(:end_time => Time.local(*values)) end |