Class: Elementary::Connection
- Inherits:
-
Object
- Object
- Elementary::Connection
- Defined in:
- lib/elementary/connection.rb
Constant Summary collapse
- DEFAULT_HOSTS =
[{:host => 'localhost', :port => 8000}].freeze
Instance Attribute Summary collapse
-
#raise_on_error ⇒ Object
readonly
Returns the value of attribute raise_on_error.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
-
#initialize(service, opts = {}) ⇒ Connection
constructor
Initialize a connection to the
Protobuf::Rpc::Service
. - #rpc ⇒ Object
- #select_transport ⇒ Object
Constructor Details
#initialize(service, opts = {}) ⇒ Connection
Initialize a connection to the Protobuf::Rpc::Service
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/elementary/connection.rb', line 28 def initialize(service, opts={}) opts = Hashie::Mash.new(opts) if service.nil? || service.superclass != Protobuf::Rpc::Service raise ArgumentError, "Cannot construct an Elementary::Connection with `#{service}` (#{service.class})" end @service = service @transport = opts[:transport] @hosts = opts[:hosts] || DEFAULT_HOSTS @transport_opts = opts[:transport_options] || {} @future_opts = opts[:future_options] || {} # Create exectutor here to avoid threading issues later. See Issue #43 rpc end |
Instance Attribute Details
#raise_on_error ⇒ Object (readonly)
Returns the value of attribute raise_on_error.
10 11 12 |
# File 'lib/elementary/connection.rb', line 10 def raise_on_error @raise_on_error end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
10 11 12 |
# File 'lib/elementary/connection.rb', line 10 def service @service end |
Instance Method Details
#rpc ⇒ Object
45 46 47 |
# File 'lib/elementary/connection.rb', line 45 def rpc @rpc ||= Elementary::Executor.new(@service, select_transport, @future_opts) end |
#select_transport ⇒ Object
49 50 51 |
# File 'lib/elementary/connection.rb', line 49 def select_transport Elementary::Transport::HTTP.new(@hosts, @transport_opts) end |