Class: Rave::Models::Context
- Inherits:
-
Object
- Object
- Rave::Models::Context
- Defined in:
- lib/models/context.rb
Overview
Contains server request information including current waves and operations.
Constant Summary collapse
- JAVA_CLASS =
:nodoc:
'com.google.wave.api.impl.OperationMessageBundle'
Instance Attribute Summary collapse
-
#primary_wavelet ⇒ Object
readonly
:nodoc: API users should use Event#wavelet.
-
#robot ⇒ Object
readonly
The robot managing this context.
Instance Method Summary collapse
-
#add_blip(blip) ⇒ Object
Add a blip to blips (Use an Operation to actually add the blip to the Wave).
-
#add_operation(options) ⇒ Object
Add an operation to the list to be executed.
-
#add_user(options) ⇒ Object
Add a user to users (Use an Operation to actually add the blip to the Wave).
-
#add_wave(wave) ⇒ Object
Add a wave to waves (Use an Operation to actually add the wave).
-
#add_wavelet(wavelet) ⇒ Object
Add a wavelet to wavelets (Use an Operation to actually add the blip to the Wave).
-
#blips ⇒ Object
All wavelets by ID [Hash of String => Wavelet].
-
#create_wavelet(participants) ⇒ Object
participants
-
Participants to exist in the new wavelet, as IDs or objects [Array of String/User] Returns: Newly created wave [Wave].
-
#initialize(options = {}) ⇒ Context
constructor
Options include: - :waves - :wavelets - :blips - :operations - :users.
-
#operations ⇒ Object
All operations [Array of Operation].
-
#print_structure(indent = 0) ⇒ Object
:nodoc:.
-
#remove_blip(blip) ⇒ Object
Remove a blip.
-
#to_json ⇒ Object
Serialize the context for use in the line protocol.
-
#users ⇒ Object
All users by ID [Hash of String => User].
-
#wavelets ⇒ Object
All wavelets by ID [Hash of String => Wavelet].
-
#waves ⇒ Object
All waves by ID [Hash of String => Wave].
Constructor Details
#initialize(options = {}) ⇒ Context
Options include:
-
:waves
-
:wavelets
-
:blips
-
:operations
-
:users
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/models/context.rb', line 42 def initialize( = {}) # :nodoc: @waves = [:waves] || {} @waves.values.each { |wave| wave.context = self } #Set up self as this wave's context @wavelets = [:wavelets] || {} @wavelets.values.each { |wavelet| wavelet.context = self } #Set up self as this wavelet's context @primary_wavelet = @wavelets.values[0] # As opposed to any that are created later. @blips = [:blips] || {} @blips.values.each { |blip| blip.context = self } #Set up self as this blip's context @operations = [:operations] || [] @users = [:users] || {} @users.values.each { |user| user.context = self } #Set up self as this user's context resolve_user_references([:robot]) end |
Instance Attribute Details
#primary_wavelet ⇒ Object (readonly)
:nodoc: API users should use Event#wavelet
6 7 8 |
# File 'lib/models/context.rb', line 6 def primary_wavelet @primary_wavelet end |
#robot ⇒ Object (readonly)
The robot managing this context.
7 8 9 |
# File 'lib/models/context.rb', line 7 def robot @robot end |
Instance Method Details
#add_blip(blip) ⇒ Object
Add a blip to blips (Use an Operation to actually add the blip to the Wave). Returns: The blip [Blip].
95 96 97 98 99 |
# File 'lib/models/context.rb', line 95 def add_blip(blip) # :nodoc: @blips[blip.id] = blip blip.context = self blip end |
#add_operation(options) ⇒ Object
Add an operation to the list to be executed. Returns: self [Context]
103 104 105 106 |
# File 'lib/models/context.rb', line 103 def add_operation() # :nodoc: @operations << Operation.new() self end |
#add_user(options) ⇒ Object
Add a user to users (Use an Operation to actually add the blip to the Wave).
147 148 149 150 151 152 153 154 |
# File 'lib/models/context.rb', line 147 def add_user() # :nodoc: [:id].downcase! if [:id] raise DuplicatedIDError.new("Can't add another User with id #{[:id]}") if @users.has_key? [:id].downcase user = User.new() @users[user.id] = user user.context = self user end |
#add_wave(wave) ⇒ Object
Add a wave to waves (Use an Operation to actually add the wave). Returns: The wave [Wave].
118 119 120 121 122 |
# File 'lib/models/context.rb', line 118 def add_wave(wave)# :nodoc: @waves[wave.id] = wave wave.context = self wave end |
#add_wavelet(wavelet) ⇒ Object
Add a wavelet to wavelets (Use an Operation to actually add the blip to the Wave). Returns: The wavelet [Wavelet].
110 111 112 113 114 |
# File 'lib/models/context.rb', line 110 def add_wavelet(wavelet)# :nodoc: @wavelets[wavelet.id] = wavelet wavelet.context = self wavelet end |
#blips ⇒ Object
All wavelets by ID [Hash of String => Wavelet]
20 21 22 |
# File 'lib/models/context.rb', line 20 def blips # :nodoc: @blips.dup end |
#create_wavelet(participants) ⇒ Object
participants
-
Participants to exist in the new wavelet, as IDs or objects [Array of String/User]
Returns: Newly created wave [Wave]
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/models/context.rb', line 126 def create_wavelet(participants) # :nodoc: # Map participants to strings, since they could be Users. participant_ids = participants.map {|p| p.to_s.downcase } participant_ids << @robot.id unless participant_ids.include? @robot.id wavelet = Wavelet.new(:context => self, :participants => participant_ids) add_wavelet(wavelet) # TODO: Get wave id from sensible place? add_operation(:type => Operation::WAVELET_CREATE, :wave_id => @waves.keys[0], :property => wavelet) wavelet end |
#operations ⇒ Object
All operations [Array of Operation]
25 26 27 |
# File 'lib/models/context.rb', line 25 def operations # :nodoc: @operations.dup end |
#print_structure(indent = 0) ⇒ Object
:nodoc:
165 166 167 168 169 170 171 |
# File 'lib/models/context.rb', line 165 def print_structure(indent = 0) # :nodoc: str = '' waves.each_value do |wave| str << wave.print_structure(indent) end str end |
#remove_blip(blip) ⇒ Object
Remove a blip.
142 143 144 |
# File 'lib/models/context.rb', line 142 def remove_blip(blip) # :nodoc: @blips.delete(blip.id) end |
#to_json ⇒ Object
Serialize the context for use in the line protocol.
157 158 159 160 161 162 163 |
# File 'lib/models/context.rb', line 157 def to_json # :nodoc: hash = { 'operations' => { 'javaClass' => 'java.util.ArrayList', 'list' => @operations }, 'javaClass' => JAVA_CLASS } hash.to_json end |
#users ⇒ Object
All users by ID [Hash of String => User]
30 31 32 |
# File 'lib/models/context.rb', line 30 def users # :nodoc: @users.dup end |
#wavelets ⇒ Object
All wavelets by ID [Hash of String => Wavelet]
15 16 17 |
# File 'lib/models/context.rb', line 15 def wavelets # :nodoc: @wavelets.dup end |
#waves ⇒ Object
All waves by ID [Hash of String => Wave]
10 11 12 |
# File 'lib/models/context.rb', line 10 def waves # :nodoc: @waves.dup end |