Sha256: b7e4dea08eb0775c678532eae939cd6ebf93719875053af69c49fd59d7350042

Contents?: true

Size: 870 Bytes

Versions: 1

Compression:

Stored size: 870 Bytes

Contents

module Flyboy
  class Ability
    include ::CanCan::Ability

    def initialize(user = nil)
      # Allowed actions (all by default)
      can [:create, :read, :update, :delete, :open, :close], Flyboy::Goal
      can [:create, :read, :update, :delete, :complete, :snooze], Flyboy::Task

      # Restricted actions

      cannot [:update, :delete], Flyboy::Goal do |goal|
        goal.closed?
      end

      cannot :close, Flyboy::Goal do |goal|
        not goal.may_close?
      end

      cannot :open, Flyboy::Goal do |goal|
        not goal.may_open?
      end

      cannot [:create, :update, :delete], Flyboy::Task do |task|
        task.goal.closed?
      end

      cannot :complete, Flyboy::Task do |task|
        task.done?
      end

      cannot :snooze, Flyboy::Task do |task|
        task.done? || task.reminder >= Date.today
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flyboy-0.0.2 app/models/flyboy/ability.rb