Class: SocialStream::Population::ActivityObject
- Inherits:
-
Object
- Object
- SocialStream::Population::ActivityObject
- Defined in:
- lib/social_stream/population/activity_object.rb
Instance Method Summary collapse
-
#initialize(klass, &block) ⇒ ActivityObject
constructor
A new instance of ActivityObject.
- #populate(klass, author, owner, relation_ids) {|o| ... } ⇒ Object
Constructor Details
#initialize(klass, &block) ⇒ ActivityObject
Returns a new instance of ActivityObject.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/social_stream/population/activity_object.rb', line 4 def initialize(klass, &block) puts "#{ klass.name } population" start_time = Time.now 10.times do = ::Actor.all.sample owner = relation_ids = [Relation::Public.instance.id] populate klass, , owner, relation_ids, &block end ties = Tie.allowing('create', 'activity').all PowerLaw.new ties.sample(ties.count / 3) do |t| = t.receiver owner = t.sender relation_ids = Array(t.relation_id) populate klass, , owner, relation_ids, &block end end_time = Time.now puts ' -> ' + (end_time - start_time).round(4).to_s + 's' end |
Instance Method Details
#populate(klass, author, owner, relation_ids) {|o| ... } ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/social_stream/population/activity_object.rb', line 30 def populate klass, , owner, relation_ids, &block = ( .subject_type == "User" ? : . ) = Timestamps.new o = klass.new o.created_at = .created o.updated_at = .updated o. = .id o.owner_id = owner.id o. = .id o.relation_ids = relation_ids yield o o.save! o.post_activity.update_attributes(:created_at => o.created_at, :updated_at => o.updated_at) o end |