Class: Staypuft::DeploymentParamExporter
- Inherits:
-
Object
- Object
- Staypuft::DeploymentParamExporter
- Defined in:
- app/lib/staypuft/deployment_param_exporter.rb
Constant Summary collapse
- NAME =
:name
- DESCRIPTION =
:description
- UI_PARAMS =
"ui_params"
- PUPPET_PARAMS =
"puppet_params"
- SERVICES =
"services"
- SERVICE_NAME =
"name"
- SERVICE_PARAMS =
"params"
- PARAM_KEY =
"key"
- PARAM_ROLE =
"role"
- PARAM_PUPPETCLASS =
"puppetclass"
- PARAM_VALUE =
"value"
Instance Method Summary collapse
-
#initialize(deployment) ⇒ DeploymentParamExporter
constructor
A new instance of DeploymentParamExporter.
- #param(param_hash) ⇒ Object
- #params(one_service, hostgroup) ⇒ Object
- #puppet_params ⇒ Object
- #service(one_service, hostgroup) ⇒ Object
- #services ⇒ Object
- #to_hash ⇒ Object
- #ui_params ⇒ Object
Constructor Details
#initialize(deployment) ⇒ DeploymentParamExporter
Returns a new instance of DeploymentParamExporter.
17 18 19 |
# File 'app/lib/staypuft/deployment_param_exporter.rb', line 17 def initialize(deployment) @deployment = deployment end |
Instance Method Details
#param(param_hash) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'app/lib/staypuft/deployment_param_exporter.rb', line 55 def param(param_hash) value = param_hash[:hostgroup].current_param_value_str(param_hash[:param_key]) # force encoding needed to prevent to_yaml from outputting some strings as binary value.force_encoding("UTF-8") if value.is_a? String { PARAM_KEY => param_hash[:param_key].key, PARAM_ROLE => param_hash[:role].name, PARAM_PUPPETCLASS => param_hash[:puppetclass].name, PARAM_VALUE => value } end |
#params(one_service, hostgroup) ⇒ Object
49 50 51 52 53 |
# File 'app/lib/staypuft/deployment_param_exporter.rb', line 49 def params(one_service, hostgroup) one_service.ui_params_for_form(hostgroup).map do |param_hash| param param_hash end end |
#puppet_params ⇒ Object
37 38 39 |
# File 'app/lib/staypuft/deployment_param_exporter.rb', line 37 def puppet_params { SERVICES => services } end |
#service(one_service, hostgroup) ⇒ Object
45 46 47 |
# File 'app/lib/staypuft/deployment_param_exporter.rb', line 45 def service(one_service, hostgroup) { SERVICE_NAME => one_service.name, SERVICE_PARAMS => params(one_service, hostgroup) } end |
#services ⇒ Object
41 42 43 |
# File 'app/lib/staypuft/deployment_param_exporter.rb', line 41 def services @deployment.services_hostgroup_map.map { |one_service, hostgroup| service(one_service, hostgroup) } end |
#to_hash ⇒ Object
21 22 23 24 25 26 |
# File 'app/lib/staypuft/deployment_param_exporter.rb', line 21 def to_hash {"deployment" => {NAME.to_s => @deployment.send(NAME), DESCRIPTION.to_s => @deployment.send(DESCRIPTION), UI_PARAMS => ui_params, PUPPET_PARAMS => puppet_params} } end |
#ui_params ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'app/lib/staypuft/deployment_param_exporter.rb', line 28 def ui_params param_hash = {} services_hash = {} Deployment::EXPORT_PARAMS.each {|param| param_hash[param.to_s] = @deployment.send(param)} Deployment::EXPORT_SERVICES.each {|param| services_hash[param.to_s] = @deployment.send(param).param_hash} param_hash[SERVICES.to_s] = services_hash param_hash end |