Module: Ronin::CLI::MethodOptions Private

Included in:
StringMethodsCommand
Defined in:
lib/ronin/cli/method_options.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Allows adding options which call methods on a given object.

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#method_callsArray<Symbol, (Symbol, Array)> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The method calls to apply to an object.

Returns:

  • (Array<Symbol, (Symbol, Array)>)

Since:

  • 2.0.0



28
29
30
# File 'lib/ronin/cli/method_options.rb', line 28

def method_calls
  @method_calls
end

Instance Method Details

#apply_method_options(object) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Applies the method options to the given object.

Parameters:

  • object (Object)

    The object to call the method options on.

Returns:

  • (Object)

    The final object.

Raises:

  • (ArgumentError)

    One of the method calls in #method_calls attempted to call a private/protected or global method on the object.

Since:

  • 2.0.0



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ronin/cli/method_options.rb', line 52

def apply_method_options(object)
  common_object_methods = Object.public_instance_methods

  @method_calls.each do |method,arguments,kwargs={}|
    allowed_methods = object.public_methods - common_object_methods

    unless allowed_methods.include?(method)
      raise(ArgumentError,"cannot call method Object##{method} on object #{object.inspect}")
    end

    object = object.public_send(method,*arguments,**kwargs)
  end

  return object
end

#initialize(**kwargs) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes #method_calls.

Since:

  • 2.0.0



33
34
35
36
37
# File 'lib/ronin/cli/method_options.rb', line 33

def initialize(**kwargs)
  super(**kwargs)

  @method_calls = []
end