Sha256: 3e90afc1fce1501cb2468365cba38dfa3107c73d395feadb55efe74edf55df18

Contents?: true

Size: 562 Bytes

Versions: 1

Compression:

Stored size: 562 Bytes

Contents

module Georgia
  class ApplicationPolicy
    attr_reader :user,  :record

    def initialize(user, record)
      raise Pundit::NotAuthorizedError, "Must be signed in." unless user
      @user   = user
      @record = record
    end

    def scope
      Pundit.policy_scope!(user, record.class)
    end

    def search?
      index?
    end

    private

    def user_roles
      @user_roles ||= @user.role_names.map(&:downcase)
    end

    def user_permissions permissions, action
      user_roles.map{|r| permissions[action].fetch(r, false)}
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
georgia-0.8.0 app/policies/georgia/application_policy.rb