Sha256: 73c093c035b832eae7da43fad617ace5f1a2d6c25f6de867ba00c66f3c170ef4

Contents?: true

Size: 948 Bytes

Versions: 14

Compression:

Stored size: 948 Bytes

Contents

module KB
  module Queryable
    class KBClientNotSetException < StandardError; end
    extend ActiveSupport::Concern

    included do
      class_attribute :resolver_factory
    end

    module ClassMethods
      def kb_client
        if resolver_factory.blank?
          raise KBClientNotSetException, "You probably forgot to call `kb_api ...` on the class #{name}"
        end

        @kb_client ||= ClientResolver.public_send(resolver_factory)
      end

      def from_api(attributes)
        new(attributes_from_response(attributes), &:persist!).tap(&:clear_changes_information)
      end

      private

      def kb_api(resolver_factory)
        self.resolver_factory = resolver_factory
      end

      # @abstract Subclass is expected to implement #attributes_from_response
      # @!method attributes_from_response
      #    Filter and process the response to return the relevant attributes for entity initialization
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
barkibu-kb-0.27.0 lib/kb/models/concerns/queryable.rb
barkibu-kb-0.26.0 lib/kb/models/concerns/queryable.rb
barkibu-kb-0.25.0 lib/kb/models/concerns/queryable.rb
barkibu-kb-0.24.1 lib/kb/models/concerns/queryable.rb
barkibu-kb-0.24.0 lib/kb/models/concerns/queryable.rb
barkibu-kb-0.23.0 lib/kb/models/concerns/queryable.rb
barkibu-kb-0.22.0 lib/kb/models/concerns/queryable.rb
barkibu-kb-0.21.0 lib/kb/models/concerns/queryable.rb
barkibu-kb-0.20.0 lib/kb/models/concerns/queryable.rb
barkibu-kb-0.19.0 lib/kb/models/concerns/queryable.rb
barkibu-kb-0.18.0 lib/kb/models/concerns/queryable.rb
barkibu-kb-0.17.0 lib/kb/models/concerns/queryable.rb
barkibu-kb-0.16.2 lib/kb/models/concerns/queryable.rb
barkibu-kb-0.16.1 lib/kb/models/concerns/queryable.rb