Class: Discordrb::Overwrite
- Inherits:
-
Object
- Object
- Discordrb::Overwrite
- Defined in:
- lib/discordrb/data/overwrite.rb
Overview
A permissions overwrite, when applied to channels describes additional permissions a member needs to perform certain actions in context.
Constant Summary collapse
- TYPES =
Types of overwrites mapped to their API value.
{ role: 0, member: 1 }.freeze
Instance Attribute Summary collapse
-
#allow ⇒ Permissions
Allowed permissions for this overwrite type.
-
#deny ⇒ Permissions
Denied permissions for this overwrite type.
-
#id ⇒ Integer
ID of the thing associated with this overwrite type.
-
#type ⇒ Symbol
Either :role or :member.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Comparison by attributes [:id, :type, :allow, :deny].
-
#initialize(object = nil, type: nil, allow: 0, deny: 0) ⇒ Overwrite
constructor
Creates a new Overwrite object.
Constructor Details
#initialize(object = nil, type: nil, allow: 0, deny: 0) ⇒ Overwrite
Creates a new Overwrite object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/discordrb/data/overwrite.rb', line 45 def initialize(object = nil, type: nil, allow: 0, deny: 0) if type type = TYPES.value?(type) ? TYPES.key(type) : type.to_sym raise ArgumentError, 'Overwrite type must be :member or :role' unless type end @id = object.respond_to?(:id) ? object.id : object @type = case object when User, Member, Recipient, Profile :member when Role :role else type end @allow = allow.is_a?(Permissions) ? allow : Permissions.new(allow) @deny = deny.is_a?(Permissions) ? deny : Permissions.new(deny) end |
Instance Attribute Details
#allow ⇒ Permissions
Returns allowed permissions for this overwrite type.
20 21 22 |
# File 'lib/discordrb/data/overwrite.rb', line 20 def allow @allow end |
#deny ⇒ Permissions
Returns denied permissions for this overwrite type.
23 24 25 |
# File 'lib/discordrb/data/overwrite.rb', line 23 def deny @deny end |
#id ⇒ Integer
Returns ID of the thing associated with this overwrite type.
14 15 16 |
# File 'lib/discordrb/data/overwrite.rb', line 14 def id @id end |
#type ⇒ Symbol
Returns either :role or :member.
17 18 19 |
# File 'lib/discordrb/data/overwrite.rb', line 17 def type @type end |
Instance Method Details
#==(other) ⇒ Object
Comparison by attributes [:id, :type, :allow, :deny]
67 68 69 70 71 72 73 74 75 |
# File 'lib/discordrb/data/overwrite.rb', line 67 def ==(other) # rubocop:disable Lint/Void false unless other.is_a? Discordrb::Overwrite # rubocop:enable Lint/Void id == other.id && type == other.type && allow == other.allow && deny == other.deny end |