Class: PresenceChannel::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/presence_channel.rb

Overview

Class for managing config of PresenceChannel Three parameters can be provided on initialization:

public: boolean value. If true, channel information is visible to all users (default false)
allowed_user_ids: array of user_ids that can view, and become present in, the channel (default [])
allowed_group_ids: array of group_ids that can view, and become present in, the channel (default [])
count_only: boolean. If true, user identities are never revealed to clients. (default [])

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(public: false, allowed_user_ids: nil, allowed_group_ids: nil, count_only: false, timeout: nil) ⇒ Config

Returns a new instance of Config.



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/presence_channel.rb', line 46

def initialize(
  public: false,
  allowed_user_ids: nil,
  allowed_group_ids: nil,
  count_only: false,
  timeout: nil
)
  @public = public
  @allowed_user_ids = allowed_user_ids
  @allowed_group_ids = allowed_group_ids
  @count_only = count_only
  @timeout = timeout
end

Instance Attribute Details

#allowed_group_idsObject

Returns the value of attribute allowed_group_ids.



44
45
46
# File 'lib/presence_channel.rb', line 44

def allowed_group_ids
  @allowed_group_ids
end

#allowed_user_idsObject

Returns the value of attribute allowed_user_ids.



44
45
46
# File 'lib/presence_channel.rb', line 44

def allowed_user_ids
  @allowed_user_ids
end

#count_onlyObject

Returns the value of attribute count_only.



44
45
46
# File 'lib/presence_channel.rb', line 44

def count_only
  @count_only
end

#publicObject

Returns the value of attribute public.



44
45
46
# File 'lib/presence_channel.rb', line 44

def public
  @public
end

#timeoutObject

Returns the value of attribute timeout.



44
45
46
# File 'lib/presence_channel.rb', line 44

def timeout
  @timeout
end

Class Method Details

.from_json(json) ⇒ Object



60
61
62
63
64
# File 'lib/presence_channel.rb', line 60

def self.from_json(json)
  data = JSON.parse(json, symbolize_names: true)
  data = {} if !data.is_a? Hash
  new(**data.slice(:public, :allowed_user_ids, :allowed_group_ids, :count_only, :timeout))
end

Instance Method Details

#to_jsonObject



66
67
68
69
70
71
72
73
# File 'lib/presence_channel.rb', line 66

def to_json
  data = { public: public }
  data[:allowed_user_ids] = allowed_user_ids if allowed_user_ids
  data[:allowed_group_ids] = allowed_group_ids if allowed_group_ids
  data[:count_only] = count_only if count_only
  data[:timeout] = timeout if timeout
  data.to_json
end