Sha256: f1850dba5dc2d1c32b037d4812ea35582589a06b44e9c26cec2c7a028ff2cde7

Contents?: true

Size: 1020 Bytes

Versions: 1

Compression:

Stored size: 1020 Bytes

Contents

module JsonApiClient
  module Helpers
    module Queryable
      extend ActiveSupport::Concern

      included do
        class << self
          extend Forwardable
          def_delegators :new_scope, :where, :order, :includes, :select, :all, :paginate, :page, :first, :find
        end
        class_attribute :connection_class, :connection_object, :connection_options, :query_builder
        self.connection_class = Connection
        self.connection_options = {}
        self.query_builder = Query::Builder
      end

      module ClassMethods
        def new_scope
          query_builder.new(self)
        end

        def connection(&block)
          build_connection(&block)
          connection_object
        end

        def build_connection
          return connection_object unless connection_object.nil?
          self.connection_object = connection_class.new(connection_options.merge(site: site)).tap do |conn|
            yield(conn) if block_given?
          end
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
json_api_client-1.0.0.beta3 lib/json_api_client/helpers/queryable.rb