Sha256: 740a3d737afc5670b55bcecdb8feeba0ffccbcff29010b85ea428988f65089db

Contents?: true

Size: 1.19 KB

Versions: 10

Compression:

Stored size: 1.19 KB

Contents

# == Schema Information
#
# Table name: faalis_groups
#
#  id         :integer          not null, primary key
#  name       :string
#  role       :string
#  created_at :datetime
#  updated_at :datetime
#

module Faalis
  # **Group** model for **Faalis** platform
  class Group < Faalis::ORM.proper_base_class

    # Make this model authorizable
    include Faalis::Concerns::Authorizable

    # Define **Group** fields if current ORM was **Mongoid**
    if Faalis::ORM.mongoid?
      include Mongoid::Document
      include Mongoid::Timestamps

      field :name, type: String
      field :role, type: String
    end

    has_and_belongs_to_many :users, class_name: 'Faalis::User'
    has_and_belongs_to_many :permissions, class_name: 'Faalis::Permission'

    # Validations
    validates :name, presence: true
    validates :role, presence: true, uniqueness: true

    def self.policy_class
      GroupPolicy
    end

    def include_permission?(perm)
      if perm.is_a? Fixnum
        permission_ids.include? perm
      else
        permission_ids.include? perm.id
      end
    end

    def to_s
      name
    end
    private

    def permission_ids
      @permission_ids ||= permissions.map(&:id)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
faalis-2.0.8 app/models/faalis/group.rb
faalis-2.0.7 app/models/faalis/group.rb
faalis-2.0.5 app/models/faalis/group.rb
faalis-2.0.4 app/models/faalis/group.rb
faalis-2.0.3 app/models/faalis/group.rb
faalis-2.0.1 app/models/faalis/group.rb
faalis-2.0.0 app/models/faalis/group.rb
faalis-2.0.0.rc6 app/models/faalis/group.rb
faalis-2.0.0.rc5 app/models/faalis/group.rb
faalis-2.0.0.rc4 app/models/faalis/group.rb