Sha256: 91b268b76b84bbec96cdfd891f2a43a748ef72a6e0685e87d9fb265fc297df77

Contents?: true

Size: 878 Bytes

Versions: 5

Compression:

Stored size: 878 Bytes

Contents

# frozen_string_literal: true

module BaseEditingBootstrap
  module BaseModel
    extend ActiveSupport::Concern

    included do
      include IsValidated
      delegate :ransackable_attributes, :ransackable_associations, to: :@class
    end

    class_methods do
      def ransackable_attributes(auth_object = nil)
        if auth_object
          Pundit.policy(auth_object, self.new).permitted_attributes_for_ransack.map(&:to_s)
        else
          Pundit.policy(User.new, self.new).permitted_attributes_for_ransack.map(&:to_s)
        end
      end 
      
      def ransackable_associations(auth_object = nil)
        if auth_object
          Pundit.policy(auth_object, self.new).permitted_associations_for_ransack.map(&:to_s)
        else
          Pundit.policy(User.new, self.new).permitted_associations_for_ransack.map(&:to_s)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
base_editing_bootstrap-0.14.0 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.13.0 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.12.0 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.11.0 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.10.2 lib/base_editing_bootstrap/base_model.rb