Class: Rave::Models::Component

Inherits:
Object
  • Object
show all
Includes:
Rave::Mixins::Logger
Defined in:
lib/models/component.rb

Overview

A wave or wave component. This is an abstract class.

Direct Known Subclasses

Blip, Element, User, Wave, Wavelet

Constant Summary collapse

GENERATED_PREFIX =

:nodoc: Prefixes blips and wavelets that are created by the robot.

'TBD'
GENERATED_PATTERN =

:nodoc:

/^#{GENERATED_PREFIX}/
@@last_id =

For generated components, this is a unique ID number for them.

0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Rave::Mixins::Logger

#logger

Constructor Details

#initialize(options = {}) ⇒ Component

:nodoc:



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

def initialize(options = {}) # :nodoc:
  @id = options[:id] or raise ArgumentError.new(":id option is required for #{self.class.name}")
  @context = options[:context]
end

Instance Attribute Details

#context=(value) ⇒ Object (writeonly)

:nodoc: Allow context to set link to it.



13
14
15
# File 'lib/models/component.rb', line 13

def context=(value)
  @context = value
end

Instance Method Details

#generated?Boolean

Has this component been generated by the robot [Boolean]

Returns:

  • (Boolean)


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

def generated? # :nodoc:
  # This is true for all components except Users, who would override this.
  not (@id =~ /^#{GENERATED_PREFIX}/).nil?
end

#idObject

ID [String]



27
28
29
# File 'lib/models/component.rb', line 27

def id # :nodoc:
  @id.dup
end

#to_sObject

Convert to string.



37
38
39
# File 'lib/models/component.rb', line 37

def to_s
  "#{self.class.name[/[^:]*$/]}:#{@id}"
end

#unique_idObject

Generate a unique id number (from 1) [Integer]



22
23
24
# File 'lib/models/component.rb', line 22

def unique_id # :nodoc:
  @@last_id += 1
end