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 [])
Constant Summary collapse
- NOT_FOUND =
"notfound"
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.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/presence_channel.rb', line 49 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.
47 48 49 |
# File 'lib/presence_channel.rb', line 47 def allowed_group_ids @allowed_group_ids end |
#allowed_user_ids ⇒ Object
Returns the value of attribute allowed_user_ids.
47 48 49 |
# File 'lib/presence_channel.rb', line 47 def allowed_user_ids @allowed_user_ids end |
#count_only ⇒ Object
Returns the value of attribute count_only.
47 48 49 |
# File 'lib/presence_channel.rb', line 47 def count_only @count_only end |
#public ⇒ Object
Returns the value of attribute public.
47 48 49 |
# File 'lib/presence_channel.rb', line 47 def public @public end |
#timeout ⇒ Object
Returns the value of attribute timeout.
47 48 49 |
# File 'lib/presence_channel.rb', line 47 def timeout @timeout end |
Class Method Details
.from_json(json) ⇒ Object
63 64 65 66 67 |
# File 'lib/presence_channel.rb', line 63 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
69 70 71 72 73 74 75 76 |
# File 'lib/presence_channel.rb', line 69 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 |