Class: Pubnub::Permissions

Inherits:
Object show all
Defined in:
lib/pubnub/events/grant_token.rb

Defined Under Namespace

Classes: Permissions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Permissions

Returns a new instance of Permissions.



151
152
153
154
155
156
157
158
159
160
161
# File 'lib/pubnub/events/grant_token.rb', line 151

def initialize(options)
  @type = options[:type]
  @read = options[:read] || false
  @write = options[:write] || false
  @manage = options[:manage] || false
  @delete = options[:delete] || false
  @create = options[:create] || false
  @get = options[:get] || false
  @update = options[:update] || false
  @join = options[:join] || false
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



118
119
120
# File 'lib/pubnub/events/grant_token.rb', line 118

def type
  @type
end

Instance Method Details

#calculate_bitmaskObject



167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/pubnub/events/grant_token.rb', line 167

def calculate_bitmask
  sum = 0

  sum |= 1 if @read
  sum |= 2 if @write
  sum |= 4 if @manage
  sum |= 8 if @delete
  sum |= 16 if @create
  sum |= 32 if @get
  sum |= 64 if @update
  sum |= 128 if @join
  sum
end

#to_sObject



163
164
165
# File 'lib/pubnub/events/grant_token.rb', line 163

def to_s
  "Permissions: {:read => #{@read}, :write => #{@write}, :manage => #{@manage} , :delete => #{@delete}, :create => #{@create}, :get => #{@get}, :update => #{@update}, :join => #{@join}}"
end