Class: CemAcpt::Bolt::Cmd::OutputItem

Inherits:
Object
  • Object
show all
Defined in:
lib/cem_acpt/bolt/cmd/output.rb

Overview

Represents a single item in the output of a Bolt command

Constant Summary collapse

ATTR_DEFVAL =
'unknown'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item_hash, **item_defaults) ⇒ OutputItem

Returns a new instance of OutputItem.



196
197
198
199
200
201
202
203
204
# File 'lib/cem_acpt/bolt/cmd/output.rb', line 196

def initialize(item_hash, **item_defaults)
  @item_hash = item_hash
  @item_defaults = item_defaults.transform_keys(&:to_s)
  @target = item_hash['target'] || @item_defaults['target'] || ATTR_DEFVAL
  @action = item_hash['action'] || @item_defaults['action'] || ATTR_DEFVAL
  @object = item_hash['object'] || @item_defaults['object'] || ATTR_DEFVAL
  @status = item_hash['status'] || 'failure'
  @value = item_hash['value'] || {}
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



194
195
196
# File 'lib/cem_acpt/bolt/cmd/output.rb', line 194

def action
  @action
end

#objectObject (readonly)

Returns the value of attribute object.



194
195
196
# File 'lib/cem_acpt/bolt/cmd/output.rb', line 194

def object
  @object
end

#statusObject (readonly)

Returns the value of attribute status.



194
195
196
# File 'lib/cem_acpt/bolt/cmd/output.rb', line 194

def status
  @status
end

#targetObject (readonly)

Returns the value of attribute target.



194
195
196
# File 'lib/cem_acpt/bolt/cmd/output.rb', line 194

def target
  @target
end

#valueObject (readonly)

Returns the value of attribute value.



194
195
196
# File 'lib/cem_acpt/bolt/cmd/output.rb', line 194

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



238
239
240
241
242
# File 'lib/cem_acpt/bolt/cmd/output.rb', line 238

def ==(other)
  return false unless other.is_a?(self.class)

  to_h == other.to_h
end

#errorObject



210
211
212
213
214
# File 'lib/cem_acpt/bolt/cmd/output.rb', line 210

def error
  return unless error?

  @error ||= new_error
end

#error?Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/cem_acpt/bolt/cmd/output.rb', line 206

def error?
  !success?
end

#inspectObject



234
235
236
# File 'lib/cem_acpt/bolt/cmd/output.rb', line 234

def inspect
  to_s
end

#outputObject



220
221
222
223
224
# File 'lib/cem_acpt/bolt/cmd/output.rb', line 220

def output
  return nil if error?

  value['_output'] || value['output'] || value
end

#success?Boolean

Returns:

  • (Boolean)


216
217
218
# File 'lib/cem_acpt/bolt/cmd/output.rb', line 216

def success?
  status == 'success'
end

#to_hObject



226
227
228
# File 'lib/cem_acpt/bolt/cmd/output.rb', line 226

def to_h
  @item_hash
end

#to_sObject



230
231
232
# File 'lib/cem_acpt/bolt/cmd/output.rb', line 230

def to_s
  "#<#{self.class}:#{object_id.to_s(16)} #{target},#{action},#{object},#{status}>"
end