Class: Osm::Role
- Inherits:
-
Object
- Object
- Osm::Role
- Defined in:
- lib/osm/role.rb
Instance Attribute Summary collapse
-
#group_id ⇒ Fixnum
readonly
The group the section is in.
-
#group_name ⇒ String
readonly
The name of the group the section is in.
-
#permissions ⇒ Hash
readonly
The permissions the user has in this role.
-
#section ⇒ Osm::Section
readonly
The section this role related to.
Instance Method Summary collapse
- #<=>(another_role) ⇒ Object
- #==(another_role) ⇒ Object
-
#can_read?(key) ⇒ Boolean
Determine if this role has read access for the provided permission.
-
#can_write?(key) ⇒ Boolean
Determine if this role has write access for the provided permission.
-
#full_name ⇒ String
Get section’s full name in a consistent format.
-
#initialize(data) ⇒ Role
constructor
Initialize a new UserRole using the hash returned by the API call.
-
#long_name ⇒ String
Get section’s long name in a consistent format.
Constructor Details
#initialize(data) ⇒ Role
Initialize a new UserRole using the hash returned by the API call
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/osm/role.rb', line 17 def initialize(data) @section = Osm::Section.new(data['sectionid'], data['sectionname'], ActiveSupport::JSON.decode(data['sectionConfig']), self) @group_name = data['groupname'] @group_id = Osm::to_i_or_nil(data['groupid']) @permissions = data['permissions'].is_a?(Hash) ? Osm::symbolize_hash(data['permissions']) : {} # Convert permission values to a number @permissions.each_key do |key| @permissions[key] = @permissions[key].to_i end end |
Instance Attribute Details
#group_id ⇒ Fixnum (readonly)
Returns the group the section is in.
6 7 8 |
# File 'lib/osm/role.rb', line 6 def group_id @group_id end |
#group_name ⇒ String (readonly)
Returns the name of the group the section is in.
6 7 8 |
# File 'lib/osm/role.rb', line 6 def group_name @group_name end |
#permissions ⇒ Hash (readonly)
Returns the permissions the user has in this role.
6 7 8 |
# File 'lib/osm/role.rb', line 6 def @permissions end |
#section ⇒ Osm::Section (readonly)
Returns the section this role related to.
6 7 8 |
# File 'lib/osm/role.rb', line 6 def section @section end |
Instance Method Details
#<=>(another_role) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/osm/role.rb', line 55 def <=>(another_role) compare_group_name = self.group_name <=> another_role.group_name return compare_group_name unless compare_group_name == 0 return 0 if self.section.type == another_role.section.type [:beavers, :cubs, :scouts, :explorers, :waiting, :adults].each do |type| return -1 if self.section.type == type return 1 if another_role.section.type == type end end |
#==(another_role) ⇒ Object
66 67 68 |
# File 'lib/osm/role.rb', line 66 def ==(another_role) self.section == another_role.try(:section) end |
#can_read?(key) ⇒ Boolean
Determine if this role has read access for the provided permission
32 33 34 |
# File 'lib/osm/role.rb', line 32 def can_read?(key) return [10, 20, 100].include?(@permissions[key]) end |
#can_write?(key) ⇒ Boolean
Determine if this role has write access for the provided permission
39 40 41 |
# File 'lib/osm/role.rb', line 39 def can_write?(key) return [20, 100].include?(@permissions[key]) end |
#full_name ⇒ String
Get section’s full name in a consistent format
51 52 53 |
# File 'lib/osm/role.rb', line 51 def full_name @group_name.blank? ? @section.name : "#{@group_name} #{@section.name}" end |
#long_name ⇒ String
Get section’s long name in a consistent format
45 46 47 |
# File 'lib/osm/role.rb', line 45 def long_name @group_name.blank? ? @section.name : "#{@section.name} (#{@group_name})" end |