Class: Rave::Models::Wavelet
- Includes:
- Rave::Mixins::Logger, Rave::Mixins::TimeUtils
- Defined in:
- lib/models/wavelet.rb
Overview
Represents a Wavelet, owned by a Wave
Constant Summary collapse
- GENERATED_CREATOR =
Creator of the wavelet if it was generated via an operation.
"[email protected]"
- JAVA_CLASS =
'com.google.wave.api.impl.WaveletData'
- ROOT_ID_SUFFIX =
The suffix for the root wavelet in a wave]
"conv+root"
- ROOT_ID_REGEXP =
/#{Regexp.escape(ROOT_ID_SUFFIX)}$/
Constants inherited from Component
Component::GENERATED_PATTERN, Component::GENERATED_PREFIX
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Current version number of the wavelet [Integer].
Attributes inherited from Component
Instance Method Summary collapse
-
#add_participant(user) ⇒ Object
- Adds a participant (human or robot) to the wavelet
user
-
User to add, as ID or object [String or User] Returns: The user that was added [User or nil].
- Adds a participant (human or robot) to the wavelet
-
#create_blip ⇒ Object
Creates a blip for this wavelet Returns: Gererated blip [Blip].
-
#creation_time ⇒ Object
Time the wavelet was created [Time].
-
#creator ⇒ Object
Users that originally created the wavelet [User].
-
#creator_id ⇒ Object
ID of the creator [String].
-
#data_documents ⇒ Object
Documents contained within the wavelet [Array of Document].
-
#final_blip ⇒ Object
Find the last blip in the main thread [Blip].
-
#initialize(options = {}) ⇒ Wavelet
constructor
Options include: - :creator - :creation_time - :data_documents - :last_modifed_time - :participants - :root_blip_id - :title - :version - :wave_id - :context - :id.
-
#last_modified_time ⇒ Object
The last time the wavelet was modified [Time].
-
#participant_ids ⇒ Object
IDs of all those who are currently members of the wavelet [Array of String].
-
#participants ⇒ Object
Users that are currently have access the wavelet [Array of User].
-
#print_structure(indent = 0) ⇒ Object
:nodoc:.
-
#remove_participant(user) ⇒ Object
Removes a participant (robot only) from the wavelet.
-
#remove_robot ⇒ Object
Removes the local robot from the wavelet.
-
#root? ⇒ Boolean
Is this the root wavelet for its wave? [Boolean].
-
#root_blip ⇒ Object
First blip in the wavelet [Blip].
-
#root_blip_id ⇒ Object
ID for the root blip [String].
-
#set_data_document(name, data) ⇒ Object
Sets the data document for the wavelet.
-
#title ⇒ Object
Wavelet title [String].
-
#title=(title) ⇒ Object
Set the title.
-
#to_json ⇒ Object
INTERNAL Convert to json for sending in an operation.
-
#to_s ⇒ Object
Convert to string.
-
#wave ⇒ Object
Wave that the wavelet is contained within.
-
#wave_id ⇒ Object
ID of the wave that the wavelet is a part of [String].
Methods included from Rave::Mixins::Logger
Methods included from Rave::Mixins::TimeUtils
Methods inherited from Component
Constructor Details
#initialize(options = {}) ⇒ Wavelet
Options include:
-
:creator
-
:creation_time
-
:data_documents
-
:last_modifed_time
-
:participants
-
:root_blip_id
-
:title
-
:version
-
:wave_id
-
:context
-
:id
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/models/wavelet.rb', line 71 def initialize( = {}) # :nodoc: @participant_ids = [:participants] || [] if [:id].nil? and [:context] # Generate the wavelet from scratch. super(:id => "#{GENERATED_PREFIX}_wavelet_#{unique_id}_#{ROOT_ID_SUFFIX}", :context => [:context]) # Create a wave to live in. wave = Wave.new(:wavelet_ids => [@id], :context => @context) @wave_id = wave.id @context.add_wave(wave) # Ensure the newly created wavelet has a root blip. blip = Blip.new(:wave_id => wave.id, :wavelet_id => @id, :creator => @context.robot.id, :contributors => [@context.robot.id]) @context.add_blip(blip) @root_blip_id = blip.id @participant_ids.each do |id| @context.add_user(:id => id) unless @context.users[id] end @creator_id = GENERATED_CREATOR @context.add_user(:id => @creator_id) unless @context.users[@creator_id] else super() @root_blip_id = [:root_blip_id] @creator_id = [:creator] || User::NOBODY_ID @wave_id = [:wave_id] end @creation_time = time_from_json([:creation_time]) || Time.now @data_documents = [:data_documents] || {} @last_modified_time = time_from_json([:last_modified_time]) || Time.now @title = [:title] || '' @version = [:version] || 0 end |
Instance Attribute Details
#version ⇒ Object (readonly)
Current version number of the wavelet [Integer]
12 13 14 |
# File 'lib/models/wavelet.rb', line 12 def version @version end |
Instance Method Details
#add_participant(user) ⇒ Object
Adds a participant (human or robot) to the wavelet
user
-
User to add, as ID or object [String or User]
Returns: The user that was added [User or nil]
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/models/wavelet.rb', line 153 def add_participant(user) # :nodoc: id = user.to_s.downcase if @participant_ids.include?(id) logger.warning("Attempted to add a participant who was already in the wavelet(#{@id}): #{id}") return nil end # Allow string names to be used as participant. user = if @context.users[id] @context.users[id] else @context.add_user(:id => id) end @context.add_operation(:type => Operation::WAVELET_ADD_PARTICIPANT, :wave_id => @wave_id, :wavelet_id => @id, :property => user) @participant_ids << id user end |
#create_blip ⇒ Object
Creates a blip for this wavelet Returns: Gererated blip [Blip]
126 127 128 129 130 131 132 133 134 |
# File 'lib/models/wavelet.rb', line 126 def create_blip parent = final_blip blip = Blip.new(:wave_id => @wave_id, :parent_blip_id => parent.id, :wavelet_id => @id, :context => @context) parent.add_child_blip(blip) @context.add_operation(:type => Operation::WAVELET_APPEND_BLIP, :wave_id => @wave_id, :wavelet_id => @id, :property => blip) blip end |
#creation_time ⇒ Object
Time the wavelet was created [Time]
20 21 22 |
# File 'lib/models/wavelet.rb', line 20 def creation_time # :nodoc: @creation_time.dup end |
#creator ⇒ Object
Users that originally created the wavelet [User]
115 116 117 |
# File 'lib/models/wavelet.rb', line 115 def creator # :nodoc: @context.users[@creator_id] end |
#creator_id ⇒ Object
ID of the creator [String]
15 16 17 |
# File 'lib/models/wavelet.rb', line 15 def creator_id # :nodoc: @creator_id.dup end |
#data_documents ⇒ Object
Documents contained within the wavelet [Array of Document]
25 26 27 |
# File 'lib/models/wavelet.rb', line 25 def data_documents # :nodoc: @data_documents.dup end |
#final_blip ⇒ Object
Find the last blip in the main thread [Blip]
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/models/wavelet.rb', line 137 def final_blip # :nodoc: blip = @context.blips[@root_blip_id] if blip while blip # Find the first blip that is defined, if at all. child_blip = blip.child_blips.find { |b| not b.nil? } break unless child_blip blip = child_blip end end blip end |
#last_modified_time ⇒ Object
The last time the wavelet was modified [Time]
30 31 32 |
# File 'lib/models/wavelet.rb', line 30 def last_modified_time # :nodoc: @last_modified_time.dup end |
#participant_ids ⇒ Object
IDs of all those who are currently members of the wavelet [Array of String]
50 51 52 |
# File 'lib/models/wavelet.rb', line 50 def participant_ids # :nodoc: @participant_ids.map { |id| id.dup } end |
#participants ⇒ Object
Users that are currently have access the wavelet [Array of User]
110 111 112 |
# File 'lib/models/wavelet.rb', line 110 def participants # :nodoc: @participant_ids.map { |p| @context.users[p] } end |
#print_structure(indent = 0) ⇒ Object
:nodoc:
258 259 260 261 262 263 264 265 266 |
# File 'lib/models/wavelet.rb', line 258 def print_structure(indent = 0) # :nodoc: str = "#{' ' * indent}#{to_s}\n" if root_blip str << root_blip.print_structure(indent + 1) end str end |
#remove_participant(user) ⇒ Object
Removes a participant (robot only) from the wavelet.
user
-
User to remove, as ID or object [String or User]
Returns: The user that was removed [User or nil]
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/models/wavelet.rb', line 177 def remove_participant(user) # :nodoc: id = user.to_s.downcase unless @participant_ids.include?(id) logger.warning("Attempted to remove a participant who was not in the wavelet(#{@id}): #{id}") return nil end # Allow string names to be used as participant. user = @context.users[id] unless user.robot? logger.warning("Attempted to remove a non-robot from wavelet(#{@id}): #{id}") return nil end if user == @context.robot return remove_robot end @context.add_operation(:type => Operation::WAVELET_REMOVE_PARTICIPANT, :wave_id => @wave_id, :wavelet_id => @id, :property => user) @participant_ids.delete id user end |
#remove_robot ⇒ Object
Removes the local robot from the wavelet. Returns: The local robot [Robot]
205 206 207 208 209 210 211 212 |
# File 'lib/models/wavelet.rb', line 205 def remove_robot robot = @context.robot @context.add_operation(:type => Operation::WAVELET_REMOVE_SELF, :wave_id => @wave_id, :wavelet_id => @id) @participant_ids.delete robot.id robot end |
#root? ⇒ Boolean
Is this the root wavelet for its wave? [Boolean]
120 121 122 |
# File 'lib/models/wavelet.rb', line 120 def root? # :nodoc: not (id =~ ROOT_ID_REGEXP).nil? end |
#root_blip ⇒ Object
First blip in the wavelet [Blip]
231 232 233 |
# File 'lib/models/wavelet.rb', line 231 def root_blip # :nodoc: @context.blips[@root_blip_id] end |
#root_blip_id ⇒ Object
ID for the root blip [String]
35 36 37 |
# File 'lib/models/wavelet.rb', line 35 def root_blip_id # :nodoc: @root_blip_id.dup end |
#set_data_document(name, data) ⇒ Object
Sets the data document for the wavelet
NOT IMPLEMENTED
217 218 219 |
# File 'lib/models/wavelet.rb', line 217 def set_data_document(name, data) raise NotImplementedError end |
#title ⇒ Object
Wavelet title [String]
40 41 42 |
# File 'lib/models/wavelet.rb', line 40 def title # :nodoc: @title.dup end |
#title=(title) ⇒ Object
Set the title
223 224 225 226 227 228 |
# File 'lib/models/wavelet.rb', line 223 def title=(title) # :nodoc: Documented by title() as accessor. title = title.to_s @context.add_operation(:type => Operation::WAVELET_SET_TITLE, :wave_id => @wave_id, :wavelet_id => @id, :property => title) @title = title end |
#to_json ⇒ Object
INTERNAL Convert to json for sending in an operation.
242 243 244 245 246 247 248 249 250 |
# File 'lib/models/wavelet.rb', line 242 def to_json # :nodoc: { 'waveletId' => @id, 'javaClass' => JAVA_CLASS, 'waveId' => @wave_id, 'rootBlipId' => @root_blip_id, 'participants' => { "javaClass" => "java.util.ArrayList", "list" => @participant_ids } }.to_json end |
#to_s ⇒ Object
Convert to string.
253 254 255 256 |
# File 'lib/models/wavelet.rb', line 253 def to_s text = @title.length > 24 ? "#{@title[0..20]}..." : @title "#{super}:#{participants.join(',')}:#{text}" end |
#wave ⇒ Object
Wave that the wavelet is contained within.
236 237 238 |
# File 'lib/models/wavelet.rb', line 236 def wave# :nodoc: @context.waves[@wave_id] end |
#wave_id ⇒ Object
ID of the wave that the wavelet is a part of [String]
45 46 47 |
# File 'lib/models/wavelet.rb', line 45 def wave_id # :nodoc: @wave_id.dup end |