Class: CemAcpt::ActionResult

Inherits:
Object
  • Object
show all
Defined in:
lib/cem_acpt/action_result.rb

Overview

Wrapper class for the result of an action. Provides a common interface for getting reportable data from the result.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ ActionResult

Returns a new instance of ActionResult.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cem_acpt/action_result.rb', line 9

def initialize(result)
  @result = if result.instance_of?(CemAcpt::Goss::Api::ActionResponse)
              result
            elsif result.instance_of?(CemAcpt::Bolt::Cmd::Output)
              result
            elsif result.is_a?(StandardError)
              ErrorActionResult.new(result)
            else
              raise ArgumentError, "result must be a CemAcpt::Goss::Api::ActionResponse, CemAcpt::Bolt::Cmd::Output, or StandardError, got #{result.class}"
            end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **kwargs, &block) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/cem_acpt/action_result.rb', line 25

def method_missing(method_name, *args, **kwargs, &block)
  if @result.respond_to?(method_name)
    @result.send(method_name, *args, **kwargs, &block)
  else
    super
  end
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



7
8
9
# File 'lib/cem_acpt/action_result.rb', line 7

def result
  @result
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/cem_acpt/action_result.rb', line 21

def error?
  @result.is_a?(ErrorActionResult) || (@result.respond_to?(:error?) && @result.error?)
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/cem_acpt/action_result.rb', line 33

def respond_to_missing?(method_name, include_private = false)
  @result.respond_to?(method_name, include_private) || super
end