Class: Chatrix::Components::Permissions
- Inherits:
-
Object
- Object
- Chatrix::Components::Permissions
- Includes:
- Wisper::Publisher
- Defined in:
- lib/chatrix/components/permissions.rb
Overview
Helper for parsing permissions in a room.
Instance Method Summary collapse
-
#can?(user, action) ⇒ Boolean
Check if a user can perform an action.
-
#can_set?(user, event) ⇒ Boolean
Check if a user can set an event.
-
#initialize(room) ⇒ Permissions
constructor
Initializes a new Permissions instance.
-
#update(content) ⇒ Object
Updates permission data.
Constructor Details
#initialize(room) ⇒ Permissions
Initializes a new Permissions instance.
14 15 16 17 18 |
# File 'lib/chatrix/components/permissions.rb', line 14 def initialize(room) @room = room @actions = {} @events = {} end |
Instance Method Details
#can?(user, action) ⇒ Boolean
Check if a user can perform an action.
41 42 43 44 |
# File 'lib/chatrix/components/permissions.rb', line 41 def can?(user, action) return false unless @actions.key? action user.power_in(@room) >= @actions[action] end |
#can_set?(user, event) ⇒ Boolean
Check if a user can set an event.
52 53 54 55 |
# File 'lib/chatrix/components/permissions.rb', line 52 def can_set?(user, event) return false unless @events.key? event user.power_in(@room) >= @events[event] end |
#update(content) ⇒ Object
Updates permission data.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/chatrix/components/permissions.rb', line 22 def update(content) @actions[:ban] = content['ban'] @actions[:kick] = content['kick'] @actions[:invite] = content['invite'] @actions[:redact] = content['redact'] content['events'].each do |event, level| @events[event.match(/\w+$/).to_s.to_sym] = level end broadcast :update, @room, self end |