Module: Challah::Rolls::Role::ClassMethods

Defined in:
lib/challah/rolls/role.rb

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Role?

Quickly access a Role instance by the provided name. If no Role is found with that key, nil is returned.

Examples:

Role[:administrator]        # => Role.find_by_name('administrator')
Role['User Manager']        # => Role.find_by_name('user manager')
Role[:does_not_exist]       # => nil

Parameters:

  • name (Symbol, String)

    A role name to locate.

Returns:



107
108
109
# File 'lib/challah/rolls/role.rb', line 107

def [](name)
  self.find_by_name(name.to_s.strip.downcase.gsub(' ', '_').titleize)
end

#adminRole?

Shortcut for finding the Role named ‘Administrator’

Examples:

Role.admin # => Role.find_by_name('administrator')

Returns:



117
118
119
# File 'lib/challah/rolls/role.rb', line 117

def admin
  @admin ||= self.find_by_name('Administrator')
end