Class: Rave::Models::Event

Inherits:
Object
  • Object
show all
Includes:
Rave::Mixins::ObjectFactory, Rave::Mixins::TimeUtils
Defined in:
lib/models/event.rb

Overview

Represents an event received from the server.

Defined Under Namespace

Classes: BlipContributorsChanged, BlipDeleted, BlipSubmitted, DocumentChanged, FormButtonClicked, OperationError, WaveletBlipCreated, WaveletBlipRemoved, WaveletCreated, WaveletParticipantsChanged, WaveletSelfAdded, WaveletSelfRemoved, WaveletTimestampChanged, WaveletTitleChanged, WaveletVersionChanged

Constant Summary collapse

BLIP_ID =

:nodoc:

'blipId'

Constants included from Rave::Mixins::ObjectFactory

Rave::Mixins::ObjectFactory::WILDCARD

Instance Attribute Summary

Attributes included from Rave::Mixins::ObjectFactory

#type

Instance Method Summary collapse

Methods included from Rave::Mixins::ObjectFactory

included

Methods included from Rave::Mixins::TimeUtils

#time_from_json

Constructor Details

#initialize(options = {}) ⇒ Event

Options include:

  • :timestamp

  • :modified_by

  • :properties

  • :context

Do not use Event.new from outside; instead use Event.create

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
49
50
# File 'lib/models/event.rb', line 41

def initialize(options = {}) # :nodoc:
  @timestamp = time_from_json(options[:timestamp]) || Time.now
  @modified_by_id = options[:modified_by] || User::NOBODY_ID
  @properties = options[:properties] || {}
  @context = options[:context]

  raise ArgumentError.new(":context option required") if @context.nil?

  add_user_ids([@modified_by_id])
end

Instance Method Details

#blipObject

Blip that caused the event, or wavelet’s root blip for wavelet events [Blip]



31
32
33
# File 'lib/models/event.rb', line 31

def blip # :nodoc:
  @context.blips[@properties[BLIP_ID]]
end

#blip_idObject

ID of the blip that caused the event, or root blip of the wavelet that caused the event [String]



16
17
18
# File 'lib/models/event.rb', line 16

def blip_id # :nodoc:
  @properties[BLIP_ID].dup
end

#modified_byObject

The user that caused this event to be generated [User]



26
27
28
# File 'lib/models/event.rb', line 26

def modified_by # :nodoc:
  @context.users[@modified_by_id]
end

#timestampObject

Time at which the event was created [Time]



11
12
13
# File 'lib/models/event.rb', line 11

def timestamp # :nodoc:
  @timestamp.dup
end

#waveletObject

Wavelet that caused the event, or wavelet containing the blip that caused the event [Wavelet]



21
22
23
# File 'lib/models/event.rb', line 21

def wavelet # :nodoc:
  @context.primary_wavelet
end