Class: Tekeya::Feed::Activity::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/tekeya/feed/activity/item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, attachments, actor, author, timestamp)
  @activity_id = activity_id
  @activity_type = activity_type
  @attachments = attachments
  @actor = actor
  @author = author
  @timestamp = timestamp
end

Instance Attribute Details

#activity_idObject (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_typeObject (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

#actorObject (readonly)

Returns the value of attribute actor.



5
6
7
# File 'lib/tekeya/feed/activity/item.rb', line 5

def actor
  @actor
end

#attachmentsObject (readonly)

Returns the value of attribute attachments.



5
6
7
# File 'lib/tekeya/feed/activity/item.rb', line 5

def attachments
  @attachments
end

#authorObject (readonly)

Returns the value of attribute author.



5
6
7
# File 'lib/tekeya/feed/activity/item.rb', line 5

def author
  @author
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



5
6
7
# File 'lib/tekeya/feed/activity/item.rb', line 5

def timestamp
  @timestamp
end

Class Method Details

.from_db(activity, act_actor = nil) ⇒ Tekeya::Feed::Activity::Item

Builds a feed item a DB activity

Parameters:

  • activity (Tekeya::Activity)

    the source activity

  • act_actor (Tekeya::Entity) (defaults to: nil)

    the activty actor; when nil the actor is retrieved from the activity

Returns:



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
  act_author        = activity.author
  act_attachments   = activity.attachments.map(&:attachable)

  return self.new(act_id, act_type, act_attachments, act_actor, act_author, act_time)
end

.from_redis(key, act_actor = nil) ⇒ Tekeya::Feed::Activity::Item

Builds a feed item from a redis activity

Parameters:

  • key (String)

    the aggregate key of the activity

  • act_actor (Tekeya::Entity) (defaults to: nil)

    the activty actor; when nil the actor is retrieved from the aggregate key

Returns:



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

  act_author = unless key_components[2] == key_components[4] && key_components[3] == key_components[5]
    author_class = key_components[4].safe_constantize
    author_class.where(:"#{actor_class.entity_primary_key}" => key_components[5]).first
  else
    act_actor
  end

  act_attachments = ::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_attachments, act_actor, act_author, act_time)
end