Class: Pubnub::Permissions

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

Instance Attribute Summary collapse

Class Method 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

Class Method Details

.pat(read: false, write: false, manage: false, delete: false, create: false, get: false, update: false, join: false) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/pubnub/events/grant_token.rb', line 121

def pat(read: false, write: false, manage: false, delete: false,
        create: false, get: false, update: false, join: false)
  Permissions.new(
    type: :pattern,
    read: read,
    write: write,
    manage: manage,
    delete: delete,
    create: create,
    get: get,
    update: update,
    join: join
  )
end

.res(read: false, write: false, manage: false, delete: false, create: false, get: false, update: false, join: false) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/pubnub/events/grant_token.rb', line 136

def res(read: false, write: false, manage: false, delete: false, create: false, get: false, update: false, join: false)
  Permissions.new(
    type: :resource,
    read: read,
    write: write,
    manage: manage,
    delete: delete,
    create: create,
    get: get,
    update: update,
    join: join
  )
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