Class: EtherpadLite::Group
- Inherits:
-
Object
- Object
- EtherpadLite::Group
- Includes:
- Padded
- Defined in:
- lib/etherpad-lite/models/group.rb
Overview
A Group serves as a container for related pads. Only an Author with a Session can access a group Pad.
Group examples:
# Create a new group
group1 = @ether.create_group
# Etherpad Lite will assign it an internal id
group.id #> 'g.asdflsadf7w9823kjlasdf'
# Create a new group with a mapper, so it can be easily found again
group2 = @ether.create_group :mapper => 'Blurg'
# Load (or create, if it doesn't exist) a group mapped to "Flarb"
group3 = @ether.group('Flarb')
# Load an existing group based on its internal id
group4 = @ether.get_group('g.823lasdlfj98asdfj')
Group pad examples:
# Create a new pad in this group, optionally specifying its initial text
pad1 = group1.create_pad('group 1 pad', :text => 'Words!')
# Load (or create, if it doesn't exist) a pad in this group
pad2 = group2.pad('group 2 pad')
# Load an existing pad from group 2
pad3 = group2.get_pad('important pad')
Session examples:
# Create two hour-long session for an author in group 1
= @ether.('author_1')
session = group1.create_session(, 60)
Understand how ids work. A group pad’s id is the group_id + ‘$’ + pad_name:
pad2.group_id == group2.id #> true
pad2.id == group2.id + '$' + pad2.name #> true
pad2 == group2.pad('group 2 pad') == @ether.get_pad("#{group2.id}$group 2 pad") == @ether.get_pad('group 2 pad', :groupID => group2.id) #> true
group2.mapper #> "Blurg"
Constant Summary collapse
- GROUP_ID_REGEX =
/^g\.[^\$]+/
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
The group id.
-
#instance ⇒ Object
readonly
The EtherpadLite::Instance object.
-
#mapper ⇒ Object
readonly
An optional identifier used to map the group to something outside Etherpad Lite.
Class Method Summary collapse
-
.create(instance, options = {}) ⇒ Object
Creates a new Group.
Instance Method Summary collapse
-
#create_pad(id, options = {}) ⇒ Object
Creates and returns a Pad with the given id.
-
#create_session(author, length_in_min) ⇒ Object
Create a new session for author that will last length_in_minutes.
-
#delete ⇒ Object
Deletes the Group.
-
#get_pad(id, options = {}) ⇒ Object
Returns the Pad with the given id (presumed to already exist).
-
#initialize(instance, id, options = {}) ⇒ Group
constructor
Instantiates a Group object (presumed it already exists).
-
#pad(id, options = {}) ⇒ Object
Returns the Pad with the given id, creating it if it doesn’t already exist.
-
#pad_ids ⇒ Object
Returns an array of all the Pad ids in this Group.
-
#pads ⇒ Object
Returns an array of all the Pads in this Group.
-
#session_ids ⇒ Object
Returns all session ids in this Group.
-
#sessions ⇒ Object
Returns all sessions in this Group.
Constructor Details
#initialize(instance, id, options = {}) ⇒ Group
Instantiates a Group object (presumed it already exists)
Options:
mapper => the foreign id it’s mapped to
77 78 79 80 81 |
# File 'lib/etherpad-lite/models/group.rb', line 77 def initialize(instance, id, ={}) @instance = instance @id = id @mapper = [:mapper] end |
Instance Attribute Details
#id ⇒ Object (readonly)
The group id
54 55 56 |
# File 'lib/etherpad-lite/models/group.rb', line 54 def id @id end |
#instance ⇒ Object (readonly)
The EtherpadLite::Instance object
52 53 54 |
# File 'lib/etherpad-lite/models/group.rb', line 52 def instance @instance end |
#mapper ⇒ Object (readonly)
An optional identifier used to map the group to something outside Etherpad Lite
56 57 58 |
# File 'lib/etherpad-lite/models/group.rb', line 56 def mapper @mapper end |
Class Method Details
.create(instance, options = {}) ⇒ Object
Creates a new Group. Optionally, you may pass the :mapper option your third party system’s group id. This will allow you to find your Group again later using the same identifier as your foreign system. If you pass the mapper option, the method behaves like “create group for <mapper> if it doesn’t already exist”.
Options:
mapper => your foreign group id
65 66 67 68 69 70 |
# File 'lib/etherpad-lite/models/group.rb', line 65 def self.create(instance, ={}) result = [:mapper] \ ? instance.client.createGroupIfNotExistsFor(groupMapper: [:mapper]) \ : instance.client.createGroup new instance, result[:groupID], end |
Instance Method Details
#create_pad(id, options = {}) ⇒ Object
Creates and returns a Pad with the given id.
Options:
text => ‘initial Pad text’
102 103 104 105 |
# File 'lib/etherpad-lite/models/group.rb', line 102 def create_pad(id, ={}) [:groupID] = @id super groupify_pad_id(id), end |
#create_session(author, length_in_min) ⇒ Object
Create a new session for author that will last length_in_minutes.
118 119 120 |
# File 'lib/etherpad-lite/models/group.rb', line 118 def create_session(, length_in_min) Session.create(@instance, @id, .id, length_in_min) end |
#delete ⇒ Object
Deletes the Group
135 136 137 |
# File 'lib/etherpad-lite/models/group.rb', line 135 def delete @instance.client.deleteGroup(groupID: @id) end |
#get_pad(id, options = {}) ⇒ Object
Returns the Pad with the given id (presumed to already exist). Use this instead of Group#pad when you know the Pad already exists; it will save an HTTP request.
92 93 94 95 |
# File 'lib/etherpad-lite/models/group.rb', line 92 def get_pad(id, ={}) [:group] = self super groupify_pad_id(id), end |
#pad(id, options = {}) ⇒ Object
Returns the Pad with the given id, creating it if it doesn’t already exist. This requires an HTTP request, so if you know the Pad already exists, use Group#get_pad instead.
85 86 87 88 |
# File 'lib/etherpad-lite/models/group.rb', line 85 def pad(id, ={}) [:groupID] = @id super groupify_pad_id(id), end |
#pad_ids ⇒ Object
Returns an array of all the Pad ids in this Group.
113 114 115 |
# File 'lib/etherpad-lite/models/group.rb', line 113 def pad_ids @instance.client.listPads(groupID: @id)[:padIDs] end |
#pads ⇒ Object
Returns an array of all the Pads in this Group.
108 109 110 |
# File 'lib/etherpad-lite/models/group.rb', line 108 def pads pad_ids.map { |id| Pad.new(@instance, id, :group => self) } end |
#session_ids ⇒ Object
Returns all session ids in this Group
123 124 125 126 |
# File 'lib/etherpad-lite/models/group.rb', line 123 def session_ids s = @instance.client.listSessionsOfGroup(groupID: @id) || {} s.keys end |