Sha256: 53b268d2eef7b086d74b3c47b05baa151ff50a2d8468cbfdea6235b5bb5fed4c

Contents?: true

Size: 852 Bytes

Versions: 1

Compression:

Stored size: 852 Bytes

Contents

module Federails
  class FederailsPolicy
    attr_reader :user, :record

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

    def index?
      true
    end

    def show?
      true
    end

    def create?
      @user.present?
    end

    def new?
      create?
    end

    def update?
      owner?
    end

    def edit?
      update?
    end

    def destroy?
      owner?
    end

    class Scope
      attr_reader :user, :scope

      def initialize(user, scope)
        @user = user
        @scope = scope
      end

      def resolve
        scope.all
      end
    end

    private

    def owner?
      return false unless @user

      @record.actor_id == @user.federails_actor.id
    end

    def user_with_actor?
      @user && Federails.actor_entity?(@user) && !!@user.federails_actor
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
federails-0.4.0 app/policies/federails/federails_policy.rb