Sha256: e7ff61224868a28fd13249311e13922c3a5b455c99c95d4a4cf45b2087b927c4

Contents?: true

Size: 1.45 KB

Versions: 52

Compression:

Stored size: 1.45 KB

Contents

module SocialStream
  module Population
    class ActivityObject
      def initialize(klass, &block)
        puts "#{ klass.name } population"
        start_time = Time.now

        50.times do
          author = Actor.all[rand(Actor.all.size)]
          owner = author
          relation_ids = [Relation::Public.instance.id]

          populate klass, author, owner, relation_ids, &block
        end

        if SocialStream.relation_model == :custom
          PowerLaw.new(Tie.allowing('create', 'activity').all) do |t|

            author = t.receiver
            owner  = t.sender
            relation_ids = Array(t.relation_id)

            populate klass, author, owner, relation_ids, &block
          end
        end

        end_time = Time.now
        puts '   -> ' +  (end_time - start_time).round(4).to_s + 's'
      end

      def populate klass, author, owner, relation_ids, &block
        user_author = ( author.subject_type == "User" ? author : author.user_author )
        timestamps = Timestamps.new

        o = klass.new

        o.created_at = timestamps.created
        o.updated_at = timestamps.updated
        o.author_id  = author.id
        o.owner_id   = owner.id
        o.user_author_id = user_author.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
    end
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
social_stream-1.1.12 base/lib/social_stream/population/activity_object.rb
social_stream-base-1.1.11 lib/social_stream/population/activity_object.rb
social_stream-1.1.11 base/lib/social_stream/population/activity_object.rb
social_stream-base-1.1.10 lib/social_stream/population/activity_object.rb
social_stream-1.1.10 base/lib/social_stream/population/activity_object.rb
social_stream-base-1.1.9 lib/social_stream/population/activity_object.rb
social_stream-1.1.9 base/lib/social_stream/population/activity_object.rb
social_stream-base-1.1.8 lib/social_stream/population/activity_object.rb
social_stream-1.1.8 base/lib/social_stream/population/activity_object.rb
social_stream-base-1.1.7 lib/social_stream/population/activity_object.rb
social_stream-1.1.7 base/lib/social_stream/population/activity_object.rb
social_stream-base-1.1.6 lib/social_stream/population/activity_object.rb
social_stream-1.1.6 base/lib/social_stream/population/activity_object.rb
social_stream-base-1.1.5 lib/social_stream/population/activity_object.rb
social_stream-1.1.5 base/lib/social_stream/population/activity_object.rb
social_stream-base-1.1.4 lib/social_stream/population/activity_object.rb
social_stream-1.1.4 base/lib/social_stream/population/activity_object.rb
social_stream-1.1.3 base/lib/social_stream/population/activity_object.rb
social_stream-base-1.1.3 lib/social_stream/population/activity_object.rb
social_stream-1.1.2 base/lib/social_stream/population/activity_object.rb