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



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

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



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

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



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

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.



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

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

#remote_optionsRemoteOptions

Getter for remote options

Returns:



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

def remote_options
  @remote_options ||= RemoteOptions.new
end