Class: ActivityStream::Definition
- Inherits:
-
Object
- Object
- ActivityStream::Definition
- Defined in:
- lib/activity_stream/definition.rb
Overview
Defines a type of activity. You don’t actually interact with this class directly.
Instance Attribute Summary collapse
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Class Method Summary collapse
-
.all ⇒ Array<ActivityStream::Definition>
List of registered definitions.
-
.find_by_name(name) ⇒ ActivityStream::Definition
Find a registered definition by its symbolic name.
-
.register(definition) ⇒ Definition
Returns the registered definition.
Instance Method Summary collapse
- #icon_path ⇒ Object
-
#initialize(proxy) ⇒ Definition
constructor
A new instance of Definition.
Constructor Details
#initialize(proxy) ⇒ Definition
Returns a new instance of Definition.
12 13 14 15 16 17 |
# File 'lib/activity_stream/definition.rb', line 12 def initialize(proxy) @name = proxy[:name] @metadata = proxy[:metadata] || {} @template = proxy[:template] || 'activity' @icon = proxy[:icon] || 'activity_icon.png' end |
Instance Attribute Details
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
8 9 10 |
# File 'lib/activity_stream/definition.rb', line 8 def icon @icon end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
8 9 10 |
# File 'lib/activity_stream/definition.rb', line 8 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/activity_stream/definition.rb', line 8 def name @name end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
8 9 10 |
# File 'lib/activity_stream/definition.rb', line 8 def template @template end |
Class Method Details
.all ⇒ Array<ActivityStream::Definition>
List of registered definitions
44 45 46 |
# File 'lib/activity_stream/definition.rb', line 44 def all @definitions ||= [] end |
.find_by_name(name) ⇒ ActivityStream::Definition
Find a registered definition by its symbolic name
51 52 53 54 55 56 57 |
# File 'lib/activity_stream/definition.rb', line 51 def find_by_name(name) unless definition = all.find{|definition| definition.name == name.to_sym} raise ActivityStream::UndefinedActivity, "Could not find a definition for `#{name}`" else definition end end |
.register(definition) ⇒ Definition
Returns the registered definition
26 27 28 29 30 31 32 33 34 |
# File 'lib/activity_stream/definition.rb', line 26 def register(definition) definition = new(definition) if definition.is_a? DefinitionProxy if definition.is_a? Definition self.all << definition definition else false end end |
Instance Method Details
#icon_path ⇒ Object
19 20 21 |
# File 'lib/activity_stream/definition.rb', line 19 def icon_path 'activity_stream/icons/%s' % self.icon end |