Sha256: b5af48e95053218f42456e291ab2eedf019fde3dd7160edf6590643e1e013674

Contents?: true

Size: 1.47 KB

Versions: 3

Compression:

Stored size: 1.47 KB

Contents

module Trestle
  module Adapters
    extend ActiveSupport::Autoload

    autoload :ActiveRecordAdapter
    autoload :DraperAdapter

    class Adapter
      attr_reader :admin

      def initialize(admin)
        @admin = admin
      end

      def collection(params={})
        raise NotImplementedError
      end

      def find_instance(params)
        raise NotImplementedError
      end

      def build_instance(params={})
        raise NotImplementedError
      end

      def update_instance(instance, params)
        raise NotImplementedError
      end

      def save_instance(instance)
        raise NotImplementedError
      end

      def delete_instance(instance)
        raise NotImplementedError
      end

      def decorate_collection(collection)
        collection
      end

      def merge_scopes(scope, other)
        raise NotImplementedError
      end

      def sort(collection, params)
        raise NotImplementedError
      end

      def paginate(collection, params)
        raise NotImplementedError
      end

      def count(collection)
        raise NotImplementedError
      end

      def permitted_params(params)
        params.require(admin.admin_name.singularize).permit!
      end

      def default_attributes
        raise NotImplementedError
      end

      # Creates a new Adapter class with the given modules mixed in
      def self.compose(*modules)
        Class.new(self) do
          modules.each { |mod| include(mod) }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trestle-0.8.3 lib/trestle/adapters.rb
trestle-0.8.2 lib/trestle/adapters.rb
trestle-0.8.0 lib/trestle/adapters.rb