Sha256: 24bdeca1ede5a326d46f198cc6f0c430b49865963684882f830a491c370b3111

Contents?: true

Size: 884 Bytes

Versions: 12

Compression:

Stored size: 884 Bytes

Contents

module Flyboy
  class Ability
    include ::CanCan::Ability

    def initialize(user = nil)
      # Allowed actions (all by default)
      can [:list, :create, :read, :update, :delete, :open, :close], Flyboy::Goal
      can [:list, :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

12 entries across 12 versions & 1 rubygems

Version Path
flyboy-1.0.7 app/models/flyboy/ability.rb
flyboy-1.0.6 app/models/flyboy/ability.rb
flyboy-1.0.5 app/models/flyboy/ability.rb
flyboy-1.0.4 app/models/flyboy/ability.rb
flyboy-1.0.3 app/models/flyboy/ability.rb
flyboy-1.0.2 app/models/flyboy/ability.rb
flyboy-1.0.1 app/models/flyboy/ability.rb
flyboy-1.0.0 app/models/flyboy/ability.rb
flyboy-0.0.6 app/models/flyboy/ability.rb
flyboy-0.0.5 app/models/flyboy/ability.rb
flyboy-0.0.4 app/models/flyboy/ability.rb
flyboy-0.0.3 app/models/flyboy/ability.rb