Sha256: f0070208848790a402cf427c63ad25a9c8cf91fa7f6da61905a319806c4feed7

Contents?: true

Size: 1.04 KB

Versions: 10

Compression:

Stored size: 1.04 KB

Contents

module Comable
  module Ransackable
    extend ActiveSupport::Concern

    module ClassMethods
      attr_reader :_ransack_options

      def ransack_options(options = nil)
        if options
          @_ransack_options = options
        else
          @_ransack_options || {}
        end
      end

      def ransackable_attribute?
        klass.ransackable_attributes(auth_object).include? str
      end

      def ransackable_attributes(_auth_object = nil)
        ransackable_attributes_options = ransack_options[:ransackable_attributes] || {}
        if ransackable_attributes_options[:only]
          [ransackable_attributes_options[:only]].flatten.map(&:to_s)
        else
          column_names + _ransackers.keys - [ransackable_attributes_options[:except]].flatten.map(&:to_s)
        end
      end

      def ransackable_association?
        klass.ransackable_associations(auth_object).include? str
      end

      def ransackable_associations(_auth_object = nil)
        reflect_on_all_associations.map { |a| a.name.to_s }
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
comable-core-0.7.1 app/models/concerns/comable/ransackable.rb
comable-core-0.7.0 app/models/concerns/comable/ransackable.rb
comable-core-0.7.0.beta2 app/models/concerns/comable/ransackable.rb
comable-core-0.7.0.beta1 app/models/concerns/comable/ransackable.rb
comable-core-0.6.0 app/models/concerns/comable/ransackable.rb
comable_core-0.5.0 app/models/concerns/comable/ransackable.rb
comable_core-0.4.2 app/models/concerns/comable/ransackable.rb
comable_core-0.4.1 app/models/concerns/comable/ransackable.rb
comable_core-0.4.0 app/models/concerns/comable/ransackable.rb
comable_core-0.3.4 app/models/concerns/comable/ransackable.rb