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.



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

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.



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

def action
  @action
end

#objectObject (readonly)

Returns the value of attribute object.



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

def object
  @object
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

#targetObject (readonly)

Returns the value of attribute target.



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

def target
  @target
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

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



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

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

  to_h == other.to_h
end

#errorObject



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

def error
  return unless error?

  @error ||= new_error
end

#error?Boolean

Returns:

  • (Boolean)


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

def error?
  !success?
end

#inspectObject



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

def inspect
  to_s
end

#outputObject



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

def output
  return nil if error?

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

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  status == 'success'
end

#to_hObject



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

def to_h
  @item_hash
end

#to_sObject



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

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