Sha256: cfa282b9be64f8e48fcbf73caf25b14fd09d68c78d658365de97eb0c6272773d

Contents?: true

Size: 1.79 KB

Versions: 16

Compression:

Stored size: 1.79 KB

Contents

module Ransack
  module Adapters
    module ActiveRecord
      module Base

        def self.extended(base)
          alias :search :ransack unless base.respond_to? :search
          base.class_eval do
            class_attribute :_ransackers
            self._ransackers ||= {}
          end
        end

        def ransack(params = {}, options = {})
          Search.new(self, params, options)
        end

        def ransacker(name, opts = {}, &block)
          self._ransackers = _ransackers.merge name.to_s => Ransacker
            .new(self, name, opts, &block)
        end

        # Ransackable_attributes, by default, returns all column names
        # and any defined ransackers as an array of strings.
        # For overriding with a whitelist array of strings.
        #
        def ransackable_attributes(auth_object = nil)
          column_names + _ransackers.keys
        end

        # Ransackable_associations, by default, returns the names
        # of all associations as an array of strings.
        # For overriding with a whitelist array of strings.
        #
        def ransackable_associations(auth_object = nil)
          reflect_on_all_associations.map { |a| a.name.to_s }
        end

        # Ransortable_attributes, by default, returns the names
        # of all attributes available for sorting as an array of strings.
        # For overriding with a whitelist array of strings.
        #
        def ransortable_attributes(auth_object = nil)
          ransackable_attributes(auth_object)
        end

        # Ransackable_scopes, by default, returns an empty array
        # i.e. no class methods/scopes are authorized.
        # For overriding with a whitelist array of *symbols*.
        #
        def ransackable_scopes(auth_object = nil)
          []
        end

      end
    end
  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
ransack-1.7.0 lib/ransack/adapters/active_record/base.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/ransack-1.6.6/lib/ransack/adapters/active_record/base.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/ransack-1.6.6/lib/ransack/adapters/active_record/base.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/ransack-1.6.6/lib/ransack/adapters/active_record/base.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/ransack-1.6.2/lib/ransack/adapters/active_record/base.rb
ransack-1.6.6 lib/ransack/adapters/active_record/base.rb
ransack-1.6.5 lib/ransack/adapters/active_record/base.rb
ransack-1.6.4 lib/ransack/adapters/active_record/base.rb
ransack-1.6.3 lib/ransack/adapters/active_record/base.rb
ransack-1.6.2 lib/ransack/adapters/active_record/base.rb
ransack-1.6.1 lib/ransack/adapters/active_record/base.rb
ransack-1.6.0 lib/ransack/adapters/active_record/base.rb
ransack-1.5.1 lib/ransack/adapters/active_record/base.rb
ransack-1.5.0 lib/ransack/adapters/active_record/base.rb
ransack-1.4.1 lib/ransack/adapters/active_record/base.rb
ransack-1.4.0 lib/ransack/adapters/active_record/base.rb