Sha256: 72c885c9214cfd12266acfb3b9d41195f3b4745e069bfa9c7add072587f29352

Contents?: true

Size: 854 Bytes

Versions: 13

Compression:

Stored size: 854 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
        else
          Pundit.policy(User.new, self.new).permitted_attributes_for_ransack
        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

13 entries across 13 versions & 1 rubygems

Version Path
base_editing_bootstrap-0.10.1 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.10.0 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.9.1 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.9.0 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.8.0 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.7.0 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.6.0 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.4.1 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.4.0 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.3.0 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.2.0 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.1.4 lib/base_editing_bootstrap/base_model.rb
base_editing_bootstrap-0.1.2 lib/base_editing_bootstrap/base_model.rb