Sha256: 871eef53a01bebb29ba128ef39228f19941d147cce3518c8a2c0298d189f9cc5

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

=begin

  @File Name                            :role.rb

	@Company Name                         :Mindfire Solutions Pvt. Ltd.

	@Creator Name                         :Indranil Mukherjee

	@Date Created                         :2012-06-04

  @Date Modified                        :2012-06-14

  @Last Modification Details            :Making it as mcms project standard

  @Purpose                              :This model is required for logic set of role related data

=end

class Role < ActiveRecord::Base
  
  self.table_name = 'mcms_roles' # setting my custome table name with this model (required to be declared here/not in application.rb as it is limited to my gem)

  # it is associated with HABTM association to User model
  
  attr_accessible :title

  has_many :roles_users 
  
  has_many :users, :through => :roles_users

  has_many :plugins

  # each role needs an unique title
  
  validates :title,:presence => true , :uniqueness => true

  
  #  @Params                               : Hash
  #  @Returns                              : Array
  #  @Purpose                              : This class method is responsible for fetching an user's roles

  def self.fetch_roles user 
  
    roles = []

    i = 0

    if user.present?

      if user.roles.present?

        user.roles.each do |user_role|

          roles[i] = user_role.title

          i = i + 1

        end

      end
      
    end

    
    roles # returning the roles array

  end

  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mcms_authentication-1.0.0 app/models/role.rb
mcms_authentication-0.0.3 app/models/role.rb
mcms_authentication-0.0.2 app/models/role.rb