Sha256: 5af4da52b7d0cdd224f72820c5f8e1f4fc416856e9097c03f21196d7c1045dbf

Contents?: true

Size: 1.28 KB

Versions: 120

Compression:

Stored size: 1.28 KB

Contents

module Effective
  module EffectiveDatatable
    module Collection

      # Used for authorization.  We authorize with authorized?(:index, collection_class)
      def collection_class
        @collection_class  # Will be either User/Post/etc or Array
      end

      def active_record_collection?
        @active_record_collection == true
      end

      def array_collection?
        @array_collection == true
      end

      private

      def load_collection!
        raise 'No collection defined. Please add a collection with collection do ... end' if collection.nil?

        @collection_class = (collection.respond_to?(:klass) ? collection.klass : self.class)
        @active_record_collection = (collection.ancestors.include?(ActiveRecord::Base) rescue false)
        @array_collection = (collection.kind_of?(Array) && (collection.length == 0 || collection.first.kind_of?(Array)))

        unless active_record_collection? || array_collection?
          raise "Unsupported collection type. Expecting an ActiveRecord class, ActiveRecord relation, or an Array of Arrays [[1, 'foo'], [2, 'bar']]"
        end

        _scopes.each do |scope, _|
          raise "invalid scope: :#{scope}. The collection must respond to :#{scope}" unless collection.respond_to?(scope)
        end
      end

    end
  end
end

Version data entries

120 entries across 120 versions & 1 rubygems

Version Path
effective_datatables-3.6.3 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.6.1 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.6.0 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.7.5 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.7.4 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.7.3 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.7.2 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.7.1 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.7.0 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.6.2 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.6.1 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.6.0 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.5.7 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.5.6 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.5.5 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.5.4 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.5.3 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.5.2 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.5.1 app/models/effective/effective_datatable/collection.rb
effective_datatables-4.5.0 app/models/effective/effective_datatable/collection.rb