Class: MijDiscord::Data::Overwrite
- Inherits:
-
Object
- Object
- MijDiscord::Data::Overwrite
- Includes:
- IDObject
- Defined in:
- lib/mij-discord/data/permissions.rb
Instance Attribute Summary collapse
-
#allow ⇒ Object
Returns the value of attribute allow.
-
#deny ⇒ Object
Returns the value of attribute deny.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes included from IDObject
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(object, type: nil, allow: 0, deny: 0) ⇒ Overwrite
constructor
A new instance of Overwrite.
- #to_hash ⇒ Object
Methods included from IDObject
#==, #creation_time, #hash, synthesize
Constructor Details
#initialize(object, type: nil, allow: 0, deny: 0) ⇒ Overwrite
Returns a new instance of Overwrite.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/mij-discord/data/permissions.rb', line 85 def initialize(object, type: nil, allow: 0, deny: 0) case type when nil, :member, :role # Do nothing else raise ArgumentError, 'Overwrite type must be :member or :role' end @id = object.to_id @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 ⇒ Object
Returns the value of attribute allow.
81 82 83 |
# File 'lib/mij-discord/data/permissions.rb', line 81 def allow @allow end |
#deny ⇒ Object
Returns the value of attribute deny.
83 84 85 |
# File 'lib/mij-discord/data/permissions.rb', line 83 def deny @deny end |
#type ⇒ Object
Returns the value of attribute type.
79 80 81 |
# File 'lib/mij-discord/data/permissions.rb', line 79 def type @type end |
Class Method Details
.from_hash(data) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/mij-discord/data/permissions.rb', line 108 def self.from_hash(data) Overwrite.new( data['id'].to_i, type: data['type'].to_sym, allow: Permissions.new(data['allow']), deny: Permissions.new(data['deny']) ) end |
Instance Method Details
#to_hash ⇒ Object
117 118 119 |
# File 'lib/mij-discord/data/permissions.rb', line 117 def to_hash { id: @id, type: @type, allow: @allow.bits, deny: @deny.bits } end |