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.1.2 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.1.1 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.1.0 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.16 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.15 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.14 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.13 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.12 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.11 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.10 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.9 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.8 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.7 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.6 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.5 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.4 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.3 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.2 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.1 app/models/effective/effective_datatable/collection.rb
effective_datatables-3.0.0 app/models/effective/effective_datatable/collection.rb