Sha256: 49923b9449037034a35a5763afa629fcdad3dbe407cddf8d0cbc299d7a5a8cb1

Contents?: true

Size: 843 Bytes

Versions: 37

Compression:

Stored size: 843 Bytes

Contents

module Gritano
  class Permission < ActiveRecord::Base
    belongs_to :user
    belongs_to :repository
    
    READ = 1
    WRITE = 2
    
    def add_access(access)
      if access == :read
        self.access = READ | (self.access || 0)
      elsif access == :write
        self.access = WRITE | (self.access || 0)
      else
        return false
      end
      return true
    end
    
    def remove_access(access)
      if access == :read
        self.access = (self.access || 0) & (~ READ)
      elsif access == :write
        self.access = (self.access || 0) & (~ WRITE)
      else
        return false
      end
      return true
    end
    
    def is(access)
      if access == :read
        return (self.access & READ) == READ
      elsif access == :write
        return (self.access & WRITE) == WRITE
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
gritano-1.0.0 lib/gritano/models/permission.rb
gritano-0.11.2 lib/gritano/models/permission.rb
gritano-0.11.1 lib/gritano/models/permission.rb
gritano-0.11.0 lib/gritano/models/permission.rb
gritano-0.10.3 lib/gritano/models/permission.rb
gritano-0.10.2 lib/gritano/models/permission.rb
gritano-0.10.1 lib/gritano/models/permission.rb
gritano-0.10.0 lib/gritano/models/permission.rb
gritano-0.9.4 lib/gritano/models/permission.rb
gritano-0.9.3 lib/gritano/models/permission.rb
gritano-0.9.2 lib/gritano/models/permission.rb
gritano-0.9.1 lib/gritano/models/permission.rb
gritano-0.9.0 lib/gritano/models/permission.rb
gritano-0.8.1 lib/gritano/models/permission.rb
gritano-0.8.0 lib/gritano/models/permission.rb
gritano-0.7.2 lib/gritano/models/permission.rb
gritano-0.7.1 lib/gritano/models/permission.rb
gritano-0.7.0 lib/gritano/models/permission.rb
gritano-0.6.0 lib/gritano/models/permission.rb
gritano-0.5.4 lib/gritano/models/permission.rb