Class: PresenceChannel::Config
- Inherits:
-
Object
- Object
- PresenceChannel::Config
- 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
-
#allowed_group_ids ⇒ Object
Returns the value of attribute allowed_group_ids.
-
#allowed_user_ids ⇒ Object
Returns the value of attribute allowed_user_ids.
-
#count_only ⇒ Object
Returns the value of attribute count_only.
-
#public ⇒ Object
Returns the value of attribute public.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(public: false, allowed_user_ids: nil, allowed_group_ids: nil, count_only: false, timeout: nil) ⇒ Config
constructor
A new instance of Config.
- #to_json ⇒ Object
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_ids ⇒ Object
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_ids ⇒ Object
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_only ⇒ Object
Returns the value of attribute count_only.
44 45 46 |
# File 'lib/presence_channel.rb', line 44 def count_only @count_only end |
#public ⇒ Object
Returns the value of attribute public.
44 45 46 |
# File 'lib/presence_channel.rb', line 44 def public @public end |
#timeout ⇒ Object
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_json ⇒ Object
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 |