Module: Orthrus::ClassMethods

Defined in:
lib/orthrus.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#remote_defaultsHash

Define default settings for the remote connection.

Parameters:

  • options (Hash)

    to be set as default

Returns:

  • (Hash)

    the current remote default settings



23
24
25
# File 'lib/orthrus.rb', line 23

def remote_defaults(options)
  remote_options.smart_merge!(options)
end

Instance Method Details

#call_remote_method(method_name, args) ⇒ Object

Find the specified remote method and pass the arguments

Parameters:

  • method_name (Symbol)

    to identify the remote method

  • args (Hash)

    to pass through



50
51
52
53
# File 'lib/orthrus.rb', line 50

def call_remote_method(method_name, args)
  remote_method = @remote_methods[method_name]
  remote_method.run(args)
end

#define_remote_method(name, options = {}) ⇒ Object

Declare a remote method and create a class method as wrapper

Parameters:

  • name (Symbol)

    of the remote method

  • options (Hash) (defaults to: {})

    for the remote method



36
37
38
39
40
41
42
43
44
45
# File 'lib/orthrus.rb', line 36

def define_remote_method(name, options = {})
  @remote_methods ||= {}
  @remote_methods[name] = RemoteMethod.new(remote_options.smart_merge(options))

  class_eval <<-SRC
    def self.#{name.to_s}(args = {})
      call_remote_method(:#{name.to_s}, args)
    end
  SRC
end

#inherited(child) ⇒ Object

If we get subclassed, make sure that child inherits the remote defaults of the parent class.



29
30
31
# File 'lib/orthrus.rb', line 29

def inherited(child)
  child.__send__(:remote_defaults, remote_options)
end

#remote_optionsRemoteOptions

Getter for remote options

Returns:



15
16
17
# File 'lib/orthrus.rb', line 15

def remote_options
  @remote_options ||= RemoteOptions.new
end