Class: Multiconnect::Connection::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/multiconnect/connection/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
# File 'lib/multiconnect/connection/base.rb', line 7

def initialize(options = {})
  self.client = options.fetch :client, nil
  @except     = Array(options.fetch :except, []).map(&:to_sym)
  @only       = Array(options.fetch :only, []).map(&:to_sym)
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



5
6
7
# File 'lib/multiconnect/connection/base.rb', line 5

def client
  @client
end

Instance Method Details

#execute(action, *args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/multiconnect/connection/base.rb', line 21

def execute(action, *args)
  if allowed?(action)
    Result.new status: Result::SUCCESS, data: request(action, *args), connection: self.class
  else
    Result.new 
  end

rescue => e
  report_error(e)
  Result.new
end

#report_error(e) ⇒ Object

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/multiconnect/connection/base.rb', line 17

def report_error(e)
  raise NotImplementedError
end

#request(action, *args) ⇒ Object

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/multiconnect/connection/base.rb', line 13

def request(action, *args)
  raise NotImplementedError
end