Class: QB::Ansible::Module::Response

Inherits:
NRSER::Stash
  • Object
show all
Includes:
NRSER::Props::Mutable::Stash
Defined in:
lib/qb/ansible/module/response.rb

Overview

Encapsulation of data that an Ansible module responds to Ansible with.

Ansible calls this a module's "return value".

Props collapse

Instance Method Summary collapse

Constructor Details

#initialize(values = {}) ⇒ Response

Instantiate a new QB::Ansible::Module::Response.



155
156
157
158
# File 'lib/qb/ansible/module/response.rb', line 155

def initialize values = {}
  super()
  initialize_props values
end

Instance Attribute Details

#depreciationsArray<{ msg: String, version: String }>

This key contains a list of dictionaries that will be presented to the user. Keys of the dictionaries are msg and version, values are string, value for the version key can be an empty string.

Returns:

  • (Array<{ msg: String, version: String }>)


139
140
141
142
143
# File 'lib/qb/ansible/module/response.rb', line 139

prop  :depreciations,
type: t.array(
  t.shape( msg: t.non_empty_str, version: t.non_empty_str )
),
default: ->{ [] }

#warningsArray<String>

This key contains a list of strings that will be presented to the user.

Returns:

  • (Array<String>)

    Non-empty string warning messages to return to Ansible.



127
128
129
# File 'lib/qb/ansible/module/response.rb', line 127

prop  :warnings,
type: t.array( t.non_empty_str ),
default: -> { [] }

Instance Method Details

#convert_key(key) ⇒ Symbol

Uses Symbol keys, and they can not be empty. Will convert non-empty strings to their symbols.

Parameters:

  • key (Symbol | String)

Returns:

  • (Symbol)


170
171
172
173
174
# File 'lib/qb/ansible/module/response.rb', line 170

def convert_key key
  t.match key,
    t.non_empty_str, :to_sym.to_proc,
    t.non_empty_sym, key
end

#to_failure(msg:, warnings: [], depreciations: [], **values) ⇒ return_type

Create a new response to represent a failure, copying the stuff that makes sense to keep from this one.

Parameters:

  • arg_name (type)

    @todo Add name param description.

Returns:

  • (return_type)

    @todo Document return value.



186
187
188
189
190
191
192
# File 'lib/qb/ansible/module/response.rb', line 186

def to_failure msg:, warnings: [], depreciations: [], **values
  self.class.new \
    failed: true,
    msg: msg,
    warnings: (self.warnings + warnings),
    depreciations: (self.depreciations + depreciations)
end