Class: Role

Inherits:
Object
  • Object
show all
Defined in:
lib/roles_generic/role.rb,
lib/roles_generic/rspec/api/read_api.rb,
lib/roles_generic/rspec/api/group_api.rb,
lib/roles_generic/rspec/api/write_api.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Role

Returns a new instance of Role.



34
35
36
37
38
# File 'lib/roles_generic/role.rb', line 34

def initialize name
  @name = name
  self.class.roles ||= Set.new
  self.class.roles << self
end

Class Attribute Details

.rolesObject

Returns the value of attribute roles.



23
24
25
# File 'lib/roles_generic/role.rb', line 23

def roles
  @roles
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/roles_generic/role.rb', line 4

def name
  @name
end

Class Method Details

.allObject



25
26
27
# File 'lib/roles_generic/role.rb', line 25

def all
  roles.to_a
end

.find_role(role_name) ⇒ Object



6
7
8
9
10
11
# File 'lib/roles_generic/role.rb', line 6

def self.find_role role_name    
  role_name = Roles::Generic::RoleUtil.extract_role(role_name)
  roles.to_a.select do |r| 
    r.name.to_sym == role_name.to_sym
  end.first
end

.find_roles(*role_names) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/roles_generic/role.rb', line 13

def self.find_roles *role_names
  result = Set.new
  role_names.to_symbols.each do |role_name| 
    found_role = find_role(role_name)
    result << found_role if found_role
  end
  result
end

.namesObject



29
30
31
# File 'lib/roles_generic/role.rb', line 29

def names
  roles.map(&:name)
end