Class: Tekeya::Feed::Activity::Item
- Inherits:
-
Object
- Object
- Tekeya::Feed::Activity::Item
- Defined in:
- lib/tekeya/feed/activity/item.rb
Instance Attribute Summary collapse
-
#activity_id ⇒ Object
readonly
Returns the value of attribute activity_id.
-
#activity_type ⇒ Object
readonly
Returns the value of attribute activity_type.
-
#actor ⇒ Object
readonly
Returns the value of attribute actor.
-
#attachments ⇒ Object
readonly
Returns the value of attribute attachments.
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
-
.from_db(activity, act_actor = nil) ⇒ Tekeya::Feed::Activity::Item
Builds a feed item a DB activity.
-
.from_redis(key, act_actor = nil) ⇒ Tekeya::Feed::Activity::Item
Builds a feed item from a redis activity.
Instance Method Summary collapse
-
#initialize(activity_id, activity_type, attachments, actor, author, timestamp) ⇒ Item
constructor
A new instance of Item.
Constructor Details
#initialize(activity_id, activity_type, attachments, actor, author, timestamp) ⇒ Item
Returns a new instance of Item.
7 8 9 10 11 12 13 14 |
# File 'lib/tekeya/feed/activity/item.rb', line 7 def initialize(activity_id, activity_type, , actor, , ) @activity_id = activity_id @activity_type = activity_type @attachments = @actor = actor @author = @timestamp = end |
Instance Attribute Details
#activity_id ⇒ Object (readonly)
Returns the value of attribute activity_id.
5 6 7 |
# File 'lib/tekeya/feed/activity/item.rb', line 5 def activity_id @activity_id end |
#activity_type ⇒ Object (readonly)
Returns the value of attribute activity_type.
5 6 7 |
# File 'lib/tekeya/feed/activity/item.rb', line 5 def activity_type @activity_type end |
#actor ⇒ Object (readonly)
Returns the value of attribute actor.
5 6 7 |
# File 'lib/tekeya/feed/activity/item.rb', line 5 def actor @actor end |
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
5 6 7 |
# File 'lib/tekeya/feed/activity/item.rb', line 5 def @attachments end |
#author ⇒ Object (readonly)
Returns the value of attribute author.
5 6 7 |
# File 'lib/tekeya/feed/activity/item.rb', line 5 def @author end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
5 6 7 |
# File 'lib/tekeya/feed/activity/item.rb', line 5 def @timestamp end |
Class Method Details
.from_db(activity, act_actor = nil) ⇒ Tekeya::Feed::Activity::Item
Builds a feed item a DB activity
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tekeya/feed/activity/item.rb', line 54 def self.from_db(activity, act_actor = nil) act_id = activity.id.to_s act_type = activity.activity_type.to_sym act_time = activity.created_at act_actor ||= activity.entity = activity. = activity..map(&:attachable) return self.new(act_id, act_type, , act_actor, , act_time) end |
.from_redis(key, act_actor = nil) ⇒ Tekeya::Feed::Activity::Item
Builds a feed item from a redis activity
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tekeya/feed/activity/item.rb', line 21 def self.from_redis(key, act_actor = nil) key_components = key.split(':') act_id = key_components[1] act_type = key_components[6].to_sym act_time = Time.at(key_components[7].to_i) if act_actor.nil? actor_class = key_components[2].safe_constantize act_actor = actor_class.where(:"#{actor_class.entity_primary_key}" => key_components[3]).first end = unless key_components[2] == key_components[4] && key_components[3] == key_components[5] = key_components[4].safe_constantize .where(:"#{actor_class.entity_primary_key}" => key_components[5]).first else act_actor end = ::Tekeya.redis.smembers(key).map{|act| ActiveSupport::JSON.decode(act) }.map{|att| att['attachable_type'].safe_constantize.find att['attachable_id'] } return self.new(act_id, act_type, , act_actor, , act_time) end |