Sha256: f37d13c68f72baa5d828452a2c2d461ae115a6565b8d6df7fd94e5e73929a641

Contents?: true

Size: 866 Bytes

Versions: 76

Compression:

Stored size: 866 Bytes

Contents

class Permissao < ActiveRecord::Base
  belongs_to :papel
  validates :klass, presence: true
  before_save :define_permissioes

  def abilities
    ability = []
    if can_manage
      ability << :manage if can_manage
    else
      ability << :read if can_read
      ability << :create if can_create
      ability << :update if can_update
      ability << :destroy if can_destroy
      ability << :create_or_update if can_create or can_update
    end
    ability
  end

  private

  def define_permissioes
    if self.can_create || self.can_update || self.can_destroy
      self.can_read = true
    end
    if !self.can_read || !self.can_create || !self.can_update || !self.can_destroy
      self.can_manage = false
    end
    if self.can_read && self.can_create && self.can_update && self.can_destroy
      self.can_manage = true
    end
    return true
  end
end

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
templus_models-3.0.21 test/dummy/app/models/permissao.rb
templus_models-3.0.20 test/dummy/app/models/permissao.rb
templus_models-3.0.19 test/dummy/app/models/permissao.rb
templus_models-3.0.17 test/dummy/app/models/permissao.rb
templus_models-2.0.16 test/dummy/app/models/permissao.rb
templus_models-1.6.9 test/dummy/app/models/permissao.rb
templus_models-2.0.15 test/dummy/app/models/permissao.rb
templus_models-3.0.14 test/dummy/app/models/permissao.rb
templus_models-2.0.14 test/dummy/app/models/permissao.rb
templus_models-2.0.12 test/dummy/app/models/permissao.rb
templus_models-3.0.13 test/dummy/app/models/permissao.rb
templus_models-3.0.12 test/dummy/app/models/permissao.rb
templus_models-2.0.11 test/dummy/app/models/permissao.rb
templus_models-2.0.9 test/dummy/app/models/permissao.rb
templus_models-2.0.8 test/dummy/app/models/permissao.rb
templus_models-3.0.10 test/dummy/app/models/permissao.rb
templus_models-1.6.8 test/dummy/app/models/permissao.rb
templus_models-1.6.7 test/dummy/app/models/permissao.rb
templus_models-3.0.9 test/dummy/app/models/permissao.rb
templus_models-2.0.7 test/dummy/app/models/permissao.rb