Class: Role

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/role.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define(name, description, default = false) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/models/role.rb', line 9

def define(name, description, default = false)
  if roles.map(&:name).include?(name.to_s)
    raise ArgumentError, "Tried to define role :#{role}, " \
      "but a role by that name already exists"
  else
    roles << OpenStruct.new(
      name: name.to_s,
      description: description,
      default: default
    )
  end
end

.namesObject


26
27
28
# File 'app/models/role.rb', line 26

def names
  all.map(&:name)
end

.rolesObject


22
23
24
# File 'app/models/role.rb', line 22

def roles
  @roles ||= default_roles + config_roles
end

Instance Method Details

#name=(new_name) ⇒ Object


57
58
59
# File 'app/models/role.rb', line 57

def name=(new_name)
  super(new_name.to_s)
end

#to_sObject


61
62
63
# File 'app/models/role.rb', line 61

def to_s
  name.humanize
end