Class: BERTRPC::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/bertrpc/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, timeout = nil) ⇒ Service

Returns a new instance of Service


5
6
7
8
9
# File 'lib/bertrpc/service.rb', line 5

def initialize(host, port, timeout = nil)
  @host = host
  @port = port
  @timeout = timeout
end

Instance Attribute Details

#hostObject

Returns the value of attribute host


3
4
5
# File 'lib/bertrpc/service.rb', line 3

def host
  @host
end

#portObject

Returns the value of attribute port


3
4
5
# File 'lib/bertrpc/service.rb', line 3

def port
  @port
end

#timeoutObject

Returns the value of attribute timeout


3
4
5
# File 'lib/bertrpc/service.rb', line 3

def timeout
  @timeout
end

Instance Method Details

#call(options = nil) ⇒ Object


11
12
13
14
# File 'lib/bertrpc/service.rb', line 11

def call(options = nil)
  verify_options(options)
  Request.new(self, :call, options)
end

#cast(options = nil) ⇒ Object


16
17
18
19
# File 'lib/bertrpc/service.rb', line 16

def cast(options = nil)
  verify_options(options)
  Request.new(self, :cast, options)
end

#verify_options(options) ⇒ Object

private


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bertrpc/service.rb', line 23

def verify_options(options)
  if options
    if cache = options[:cache]
      unless cache[0] == :validation && cache[1].is_a?(String)
        raise InvalidOption.new("Valid :cache args are [:validation, String]")
      end
    else
      raise InvalidOption.new("Valid options are :cache")
    end
  end
end