Sha256: c54a1c5e5857b7a12a6488af055e36e3827fdb10826c9b9e61fbac9381e97704

Contents?: true

Size: 802 Bytes

Versions: 29

Compression:

Stored size: 802 Bytes

Contents

# frozen_string_literal: true

class Policy
  module DefaultPolicy
    def index
      false
    end

    def new?
      false
    end

    def create?
      new?
    end

    def show?
      false
    end

    def edit?
      false
    end

    def update?
      edit?
    end

    def destroy?
      edit?
    end
  end

  include DefaultPolicy

  attr_reader :user, :record

  def initialize(user, record = nil)
    @user = user
    @record = record
  end

  class << self
    def for(user, object)
      if object.is_a?(Class)
        "#{object}Policy".constantize.collection(user)
      else
        "#{object.class}Policy".constantize.member(user, object)
      end
    end

    def collection(user)
      new(user)
    end

    def member(user, record)
      new(user, record)
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
pages_core-3.15.5 app/policies/policy.rb
pages_core-3.15.4 app/policies/policy.rb
pages_core-3.15.3 app/policies/policy.rb
pages_core-3.15.2 app/policies/policy.rb
pages_core-3.15.1 app/policies/policy.rb
pages_core-3.14.0 app/policies/policy.rb
pages_core-3.13.0 app/policies/policy.rb
pages_core-3.12.7 app/policies/policy.rb
pages_core-3.12.6 app/policies/policy.rb
pages_core-3.12.5 app/policies/policy.rb
pages_core-3.12.4 app/policies/policy.rb
pages_core-3.12.3 app/policies/policy.rb
pages_core-3.12.2 app/policies/policy.rb
pages_core-3.12.1 app/policies/policy.rb
pages_core-3.12.0 app/policies/policy.rb
pages_core-3.11.3 app/policies/policy.rb
pages_core-3.11.2 app/policies/policy.rb
pages_core-3.11.1 app/policies/policy.rb
pages_core-3.11.0 app/policies/policy.rb
pages_core-3.10.2 app/policies/policy.rb