Sha256: 9f456ba5f6e842d690b39c549c13f93400024873dcb1d5bf8fd7e8bfe3cf3c5d

Contents?: true

Size: 1.03 KB

Versions: 11

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Shark
  module Connected
    extend ActiveSupport::Concern

    delegate :connection, to: :class

    included do
      class_attribute :connection_options

      self.connection_options = {
        headers: {
          'Content-Type' => 'application/vnd.api+json',
          'Accept' => 'application/vnd.api+json',
          'X-Forwarded-Proto' => 'https'
        }
      }
    end

    module ClassMethods
      # Return/build a connection object
      #
      # @return [Connection] The connection to the api server
      # @api public
      def connection(rebuild = false, &block)
        _build_connection(rebuild, &block)
        @connection
      end

      protected

      # @api private
      def _build_connection(rebuild = false)
        return @connection unless @connection.nil? || rebuild

        options = connection_options.merge(site: site)
        @connection = Shark::Client::Connection.new(options).tap do |conn|
          yield(conn) if block_given?
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
bima-shark-sdk-3.1.1 lib/shark/concerns/connected.rb
bima-shark-sdk-2.5.0 lib/shark/concerns/connected.rb
bima-shark-sdk-3.1.0 lib/shark/concerns/connected.rb
bima-shark-sdk-3.0.0 lib/shark/concerns/connected.rb
bima-shark-sdk-2.4.4 lib/shark/concerns/connected.rb
bima-shark-sdk-2.4.3 lib/shark/concerns/connected.rb
bima-shark-sdk-2.4.2 lib/shark/concerns/connected.rb
bima-shark-sdk-2.4.1 lib/shark/concerns/connected.rb
bima-shark-sdk-2.4.0 lib/shark/concerns/connected.rb
bima-shark-sdk-2.3.1 lib/shark/concerns/connected.rb
bima-shark-sdk-2.3.0 lib/shark/concerns/connected.rb