class Multiconnect::Connection::Base

Attributes

client[RW]

Public Class Methods

new(options = {}) click to toggle source
# 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

Public Instance Methods

execute(action, *args) click to toggle source
# 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) click to toggle source
# File lib/multiconnect/connection/base.rb, line 17
def report_error(e)
  raise NotImplementedError
end
request(action, *args) click to toggle source
# File lib/multiconnect/connection/base.rb, line 13
def request(action, *args)
  raise NotImplementedError
end

Private Instance Methods

allowed?(action) click to toggle source
# File lib/multiconnect/connection/base.rb, line 35
def allowed?(action)
  action = action.to_sym
  allowed_by_only   = @only.blank? || ( @only.present? && @only.include?( action ) )
  allowed_by_except = !@except.include?(action)

  allowed_by_only && allowed_by_except 
end