social_stream-base 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee108a6d8f73b1340ebede2f72b76b88118d2ff6
4
- data.tar.gz: 6da91ab7d4ab780895d3744e7eb53a3a21e52c35
3
+ metadata.gz: 3e5124e3850b3a546d1aec128165eac20a19e4f0
4
+ data.tar.gz: 1e56c930444d1e6ba3728aec673b4403ddcd1e73
5
5
  SHA512:
6
- metadata.gz: 7084015f905d5a3dac7ddbca431996993eb9e945e93823c4abcf3e5e17e76ef3c7713ee6a4e088baa0112a1602fd6896ca9db1b683afe9c5550bff6011ac97d6
7
- data.tar.gz: 59559a542cab6358dd8b10836a1cde1367da7c8967c7ae5e90155593bcac81766ca2be3b6744cc888630d9871eda9249eb7cc4ca7ea4169b21db95eb01413cfc
6
+ metadata.gz: ba14732b219222209d925080c14bccd9c5933f5b5de8eec56975d488582a6acc806988550a7aa6ee9d8d3315227de016f83a90ae8ccf618dab2857e728e313e0
7
+ data.tar.gz: d180b4b9abc79343be9ab0291468be68111e4319638158c23c7461da2cff3fb3150103bfd71962bbb43bc87ff1113b59ec817b3adf649b15242c5220ab8e58d0
data/Rakefile CHANGED
@@ -1,21 +1,9 @@
1
1
  # encoding: UTF-8
2
- require 'rake'
3
- require 'rdoc/task'
4
-
5
- require 'rubygems'
6
-
7
- require 'rspec/core/rake_task'
8
-
9
- require 'ci/reporter/rake/rspec'
10
-
11
- require 'bundler'
2
+ require 'bundler/gem_tasks'
12
3
 
13
- require File.join(File.dirname(__FILE__), 'lib', 'social_stream', 'base', 'version')
14
-
15
-
16
- RSpec::Core::RakeTask.new(:spec)
4
+ require 'rdoc/task'
17
5
 
18
- task :default => :spec
6
+ task :default => :rdoc
19
7
 
20
8
  Rake::RDocTask.new(:rdoc) do |rdoc|
21
9
  rdoc.rdoc_dir = 'rdoc'
@@ -25,8 +13,6 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
25
13
  rdoc.rdoc_files.include('lib/**/*.rb', 'app/**/*.rb')
26
14
  end
27
15
 
28
- Bundler::GemHelper.install_tasks
29
-
30
16
  # Modify this gem's tags
31
17
  class Bundler::GemHelper
32
18
  def version_tag
@@ -3,6 +3,7 @@ SocialStream.Actor = (function(SS, $, undefined) {
3
3
  var select2 = function(selector) {
4
4
  $(selector).select2({
5
5
  multiple: true,
6
+ minimumInputLength: 1,
6
7
  ajax: {
7
8
  url: $(selector).attr('data-path'),
8
9
  dataType: 'json',
@@ -15,7 +16,8 @@ SocialStream.Actor = (function(SS, $, undefined) {
15
16
  },
16
17
  id: function(object) { return object.id.toString(); },
17
18
  formatResult: select2FormatResult,
18
- formatSelection: select2FormatSelection
19
+ formatSelection: select2FormatSelection,
20
+ initSelection: select2InitSelection
19
21
  });
20
22
  };
21
23
 
@@ -27,6 +29,10 @@ SocialStream.Actor = (function(SS, $, undefined) {
27
29
  return '<img src="' + object.image.url + '"> ' + object.name;
28
30
  };
29
31
 
32
+ var select2InitSelection = function(element, callback) {
33
+ callback([ { id: element.val(), name: element.attr('data-actor_name'), locked: true } ]);
34
+ };
35
+
30
36
  return {
31
37
  select2: select2
32
38
  };
@@ -171,6 +171,13 @@ SocialStream.Contact = (function($, SS, undefined) {
171
171
 
172
172
  // new_ callbacks
173
173
 
174
+ var initHideModal = function() {
175
+ $('#add-contact-modal').on('hide', function () {
176
+ $('input[name="actors"]').select2('close');
177
+ $('select[name="relations[]"]').select2('close');
178
+ });
179
+ };
180
+
174
181
  var initActorSelect2 = function() {
175
182
  SS.Actor.select2('input[name="actors"]');
176
183
  };
@@ -298,6 +305,7 @@ SocialStream.Contact = (function($, SS, undefined) {
298
305
  hideLoading);
299
306
 
300
307
  callback.register('new_',
308
+ initHideModal,
301
309
  initActorSelect2,
302
310
  initRelationSelect2);
303
311
 
@@ -1,4 +1,8 @@
1
1
  SocialStream.Flash = (function(Flashy, undefined) {
2
+ var notice = function(message) {
3
+ Flashy.message('notice', message);
4
+ };
5
+
2
6
  var error = function(message) {
3
7
  if (message === undefined) {
4
8
  message = I18n.t('ajax.error');
@@ -11,8 +15,14 @@ SocialStream.Flash = (function(Flashy, undefined) {
11
15
  Flashy.message('success', message);
12
16
  };
13
17
 
18
+ var warning = function(message) {
19
+ Flashy.message('warning', message);
20
+ };
21
+
14
22
  return {
23
+ notice: notice,
15
24
  error: error,
16
- success: success
25
+ success: success,
26
+ warning: warning
17
27
  };
18
28
  })(Flashy);
@@ -4,7 +4,7 @@ class GroupsController < ApplicationController
4
4
 
5
5
  before_filter :authenticate_user!, :except => [ :index, :show ]
6
6
 
7
- load_and_authorize_resource
7
+ load_and_authorize_resource except: :index
8
8
 
9
9
  respond_to :html, :js
10
10
 
@@ -1,6 +1,8 @@
1
1
  class ProfilesController < ApplicationController
2
2
  before_filter :authenticate_user!, :except => [ :show ]
3
3
 
4
+ before_filter :authorize_update, except: [ :show ]
5
+
4
6
  respond_to :html, :js
5
7
 
6
8
  def show
@@ -14,11 +16,10 @@ class ProfilesController < ApplicationController
14
16
  end
15
17
 
16
18
  def edit
17
- current_profile
18
19
  end
19
20
 
20
21
  def update
21
- current_profile.update_attributes profile_params
22
+ subject_profile.update_attributes profile_params
22
23
 
23
24
  respond_to do |format|
24
25
  format.html{ redirect_to [profile_subject, :profile] }
@@ -53,4 +54,8 @@ class ProfilesController < ApplicationController
53
54
 
54
55
  current_subject.profile
55
56
  end
57
+
58
+ def authorize_update
59
+ authorize! :update, subject_profile
60
+ end
56
61
  end
@@ -45,17 +45,15 @@ class SearchController < ApplicationController
45
45
  private
46
46
 
47
47
  def search mode
48
- result = SocialStream::Search.search(params[:q],
49
- current_subject,
50
- :mode => mode,
51
- :key => params[:type])
52
-
53
- if mode.to_s.eql? "quick"
54
- result = Kaminari.paginate_array(result).page(1).per(7)
55
- else
56
- result = Kaminari.paginate_array(result).page(params[:page]).per(RESULTS_SEARCH_PER_PAGE)
57
- end
48
+ page = ( mode == "quick" ? 1 : params[:page] )
49
+ limit = ( mode == "quick" ? 7 : RESULTS_SEARCH_PER_PAGE )
50
+
51
+ SocialStream::Search.search(params[:q],
52
+ current_subject,
53
+ mode: mode,
54
+ key: params[:type],
55
+ page: page,
56
+ limit: limit)
58
57
 
59
- result
60
58
  end
61
59
  end
@@ -51,18 +51,19 @@ class Permission < ActiveRecord::Base
51
51
  # if the class is not found
52
52
  def available(subject)
53
53
  class_name = subject.class.to_s.underscore
54
+ # TODO add further classes
54
55
  base_class_name = subject.class.base_class.to_s.underscore
55
56
 
56
- candidates = [ class_name, class_name.to_sym ]
57
+ candidates = [ class_name ]
57
58
 
58
59
  if class_name != base_class_name
59
- candidates += [ base_class_name, base_class_name.to_sym ]
60
+ candidates += [ base_class_name ]
60
61
  end
61
62
 
62
63
  list = nil
63
64
 
64
65
  candidates.each do |n|
65
- list = SocialStream.available_permissions[n]
66
+ list = SocialStream.available_permissions.with_indifferent_access[n]
66
67
 
67
68
  break if list.present?
68
69
  end
@@ -24,8 +24,8 @@ class Relation::Custom < Relation
24
24
  class << self
25
25
  def defaults_for(actor)
26
26
  subject_type = actor.subject.class.to_s.underscore
27
- cfg_rels = SocialStream.custom_relations[subject_type] ||
28
- SocialStream.custom_relations[subject_type.to_sym]
27
+
28
+ cfg_rels = SocialStream.custom_relations.with_indifferent_access[subject_type]
29
29
 
30
30
  if cfg_rels.nil?
31
31
  raise "Undefined relations for subject type #{ subject_type }. Please, add an entry to config/initializers/social_stream.rb"
@@ -36,10 +36,10 @@ class Relation::Custom < Relation
36
36
  cfg_rels.each_pair do |name, cfg_rel|
37
37
  rels[name] =
38
38
  create! :actor => actor,
39
- :name => cfg_rel['name'],
40
- :receiver_type => cfg_rel['receiver_type']
39
+ :name => cfg_rel[:name],
40
+ :receiver_type => cfg_rel[:receiver_type]
41
41
 
42
- if (ps = cfg_rel['permissions']).present?
42
+ if (ps = cfg_rel[:permissions]).present?
43
43
  ps.each do |p|
44
44
  p.push(nil) if p.size == 1
45
45
 
@@ -50,6 +50,8 @@ class User < ActiveRecord::Base
50
50
 
51
51
  def as_json options = nil
52
52
  {
53
+ id: id,
54
+ actorId: actor_id,
53
55
  nickName: slug,
54
56
  displayName: name,
55
57
  email: email,
@@ -6,10 +6,10 @@
6
6
  </div>
7
7
  <div class="modal-body">
8
8
  <%= label_tag 'actors', t('actor.title.other') %>
9
- <%= text_field_tag 'actors', '', 'data-path' => actors_path(stranger: true, sender_id: Actor.normalize_id(sender)), 'data-type' => Array.wrap(type).compact.join(',') %>
9
+ <%= text_field_tag 'actors', '', 'data-path' => actors_path(stranger: true, sender_id: Actor.normalize_id(sender)), 'data-type' => Array.wrap(type).compact.join(','), placeholder: t('contact.new.modal.placeholder.actors') %>
10
10
 
11
11
  <%= label_tag 'relations', t('activerecord.attributes.contact.relation_ids') %>
12
- <%= select_tag 'relations', contact_select_options(sender.options_for_contact_select), multiple: true %>
12
+ <%= select_tag 'relations', contact_select_options(sender.options_for_contact_select), multiple: true, "data-placeholder" => t('contact.new.modal.placeholder.actors') %>
13
13
  </div>
14
14
  <div class="modal-footer">
15
15
  <%= submit_tag t('contact.new.modal.button') %>
@@ -20,10 +20,11 @@
20
20
  <div id="<%= type %>" class="tab-pane <%= 'active' if current_contact_section?(type) %>">
21
21
  <%= text_field_tag "contact-filter-#{ type }", (current_contact_section?(type) ? params[:q] : ""), class: "pull-right contact-filter", placeholder: "filter", autocomplete: "off" %>
22
22
 
23
- <% if type == :group %>
23
+ <% if user_signed_in? && type == :group %>
24
24
  <%= link_to t('group.new.link'), new_group_path, class: 'new_group-modal-link', 'data-toggle' => 'modal' %>
25
25
 
26
- <%= render partial: 'groups/new_modal' %>
26
+ <%= render partial: 'groups/new_modal',
27
+ locals: { resource_class: Group } %>
27
28
  <% end %>
28
29
 
29
30
  <div class="contact-list">
@@ -1,15 +1 @@
1
- <%= location(t('account.one'),
2
- link_to(t('settings.main'), settings_path)
3
- ) %>
4
-
5
- <h2>
6
- <%= t('settings.for')%> <%= current_subject.name %>
7
- </h2>
8
-
9
- <%= render :partial => "edit_user"%>
10
- <%= render :partial => "settings/language" %>
11
- <%= render :partial => "settings/notifications" %>
12
- <% if current_subject.respond_to? :authentication_token%>
13
- <%= render :partial => "settings/api_key" %>
14
- <% end %>
15
- <%= render :partial => "delete_account"%>
1
+ <%= render template: 'settings/index' %>
@@ -18,7 +18,7 @@
18
18
  </section>
19
19
  <section class="owners">
20
20
  <%= f.label :owners %>
21
- <%= f.hidden_field :owners, 'data-path' => actors_path(format: :json) %>
21
+ <%= f.hidden_field :owners, 'data-path' => actors_path(format: :json), "data-actor_name" => current_subject.name %>
22
22
  </section>
23
23
  <section class="tags">
24
24
  <%= f.label :tags_list %>
@@ -5,7 +5,7 @@
5
5
  </div>
6
6
  <div class="modal-body">
7
7
  <%= render partial: 'groups/form',
8
- object: Group.new,
8
+ object: resource_class.new(owners: current_subject.actor_id),
9
9
  as: :group %>
10
10
  </div>
11
11
  </div>
@@ -8,6 +8,6 @@
8
8
  <h2><%= t('group.new.title') %></h2>
9
9
 
10
10
  <%= render partial: 'form',
11
- object: @group,
11
+ object: resource_class.new(owners: current_subject.actor_id),
12
12
  as: :group %>
13
13
  </section>
@@ -1,4 +1,4 @@
1
- <%= form_for(@profile, :url => [current_subject, :profile]) do |f| %>
1
+ <%= form_for(@profile, :url => [@profile.subject, :profile]) do |f| %>
2
2
  <%= f.label :phone, t('profile.phone') %>
3
3
 
4
4
  <%= f.phone_field :phone %>
@@ -1,5 +1,5 @@
1
- <%= form_for(@profile, :url => [current_subject, :profile]) do |f| %>
1
+ <%= form_for(@profile, :url => [@profile.subject, :profile]) do |f| %>
2
2
  <%= f.text_area :experience, :maxlength => 246, :rows => 5 %>
3
3
 
4
4
  <%= f.submit :class => "btn" %>
5
- <% end %>
5
+ <% end %>
@@ -1,10 +1,10 @@
1
- <%= form_for(@profile, :url => [current_subject, :profile]) do |f| %>
1
+ <%= form_for(@profile, :url => [@profile.subject, :profile]) do |f| %>
2
2
  <span class="required">*</span>
3
3
  <%= f.label :name %>
4
4
 
5
5
  <%= f.text_field :name, :class => "required" %>
6
6
 
7
- <%= f.label :description, t("profile.#{ current_subject.class.to_s.downcase }.about") %>
7
+ <%= f.label :description, t("profile.#{ f.object.subject.class.to_s.downcase }.about") %>
8
8
 
9
9
  <%= f.text_area :description, :maxlength => 200, :rows => 10 %>
10
10
 
@@ -12,7 +12,7 @@
12
12
 
13
13
  <%= f.text_field :organization %>
14
14
 
15
- <%= f.label :birthday, t('profile.' + current_subject.class.to_s.downcase + '.birthday') %>
15
+ <%= f.label :birthday, t('profile.' + f.object.subject.class.to_s.downcase + '.birthday') %>
16
16
 
17
17
  <%= date_select "profile", "birthday", :order => [:day, :month, :year], :end_year => Date.today.year, :start_year => (Date.today.year - 100), :prompt => {:day => 'Day', :month => 'Month', :year => 'Year'} %>
18
18
 
@@ -5,4 +5,5 @@
5
5
  }
6
6
  });
7
7
  <% else %>
8
+ SocialStream.Flash.error('<%= @custom.errors.full_messages.to_sentence %>');
8
9
  <% end %>
@@ -7,5 +7,5 @@
7
7
  section: '<%= params[:section] %>'
8
8
  });
9
9
  <% else %>
10
-
10
+ SocialStream.Flash.error('<%= @custom.errors.full_messages.to_sentence %>');
11
11
  <% end %>
@@ -5,5 +5,5 @@
5
5
  <section id="settings">
6
6
  <%= render partial: 'toolbar/profile', locals: { subject: current_subject } %>
7
7
 
8
- <%= render :partial => 'index' %>
8
+ <%= render partial: 'settings/index' %>
9
9
  </section>
@@ -184,6 +184,9 @@ en:
184
184
  link: Add contact
185
185
  modal:
186
186
  button: Add
187
+ placeholder:
188
+ actors: Type names
189
+ relations: Type names
187
190
  title: Add contacts
188
191
  title: Add %{name} to your contacts
189
192
  menu: Add contact
@@ -586,7 +586,7 @@ es:
586
586
  query: Más resultados para %{query} >
587
587
  name: Buscar
588
588
  no_subject_found: No se encontró a %{subject}.
589
- nothing: No se ha econtrado nada.
589
+ nothing: No se ha encontrado nada.
590
590
  searching: 'Buscando: %{query}'
591
591
  show_all: Todos
592
592
  write: Escribe tu búsqueda...
@@ -1,17 +1,16 @@
1
1
  module SocialStream
2
+
2
3
  autoload :Ability, 'social_stream/ability'
3
4
  autoload :ActivityStreams, 'social_stream/activity_streams'
5
+
4
6
  module ActivityStreams
5
7
  autoload :Supertype, 'social_stream/activity_streams/supertype'
6
8
  autoload :Subtype, 'social_stream/activity_streams/subtype'
7
9
  end
10
+
8
11
  module Base
9
12
  autoload :Ability, 'social_stream/base/ability'
10
13
  end
11
- autoload :D3, 'social_stream/d3'
12
- autoload :Populate, 'social_stream/populate'
13
- autoload :Relations, 'social_stream/relations'
14
- autoload :TestHelpers, 'social_stream/test_helpers'
15
14
 
16
15
  module Controllers
17
16
  autoload :Authorship, 'social_stream/controllers/authorship'
@@ -23,6 +22,8 @@ module SocialStream
23
22
  autoload :Subjects, 'social_stream/controllers/subjects'
24
23
  end
25
24
 
25
+ autoload :D3, 'social_stream/d3'
26
+
26
27
  module Devise
27
28
  module Controllers
28
29
  autoload :UserSignIn, 'social_stream/devise/controllers/user_sign_in'
@@ -36,6 +37,8 @@ module SocialStream
36
37
  autoload :Supertype, 'social_stream/models/supertype'
37
38
  end
38
39
 
40
+ autoload :Population, 'social_stream/population'
41
+
39
42
  module Population
40
43
  autoload :ActivityObject, 'social_stream/population/activity_object'
41
44
  autoload :Actor, 'social_stream/population/actor'
@@ -43,6 +46,8 @@ module SocialStream
43
46
  autoload :Timestamps, 'social_stream/population/timestamps'
44
47
  end
45
48
 
49
+ autoload :Relations, 'social_stream/relations'
50
+
46
51
  module Routing
47
52
  module Constraints
48
53
  autoload :Custom, 'social_stream/routing/constraints/custom'
@@ -53,12 +58,14 @@ module SocialStream
53
58
 
54
59
  autoload :Search, 'social_stream/search'
55
60
 
56
- module Views
57
- autoload :List, 'social_stream/views/list'
58
- autoload :Location, 'social_stream/views/location'
59
- end
61
+ autoload :TestHelpers, 'social_stream/test_helpers'
60
62
 
61
63
  module TestHelpers
62
64
  autoload :Controllers, 'social_stream/test_helpers/controllers'
63
65
  end
66
+
67
+ module Views
68
+ autoload :List, 'social_stream/views/list'
69
+ autoload :Location, 'social_stream/views/location'
70
+ end
64
71
  end
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Base
3
- VERSION = "2.2.0".freeze
3
+ VERSION = "2.2.1".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,14 @@
1
+ module SocialStream
2
+ module Population
3
+ class << self
4
+ def task message
5
+ puts message
6
+ time = Time.now
7
+
8
+ yield
9
+
10
+ puts " -> #{ (Time.now - time).round(4) }s"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -117,8 +117,10 @@ module SocialStream
117
117
 
118
118
  [
119
119
  query,
120
- :classes => models,
121
- :with => with
120
+ classes: models,
121
+ with: with,
122
+ limit: options[:limit],
123
+ page: options[:page]
122
124
  ]
123
125
  end
124
126
  end
@@ -45,171 +45,127 @@ namespace :db do
45
45
  # USERS
46
46
  desc "Create users"
47
47
  task :users => :read_environment do
48
- puts 'User population (Demo and ' + @USERS.to_s + ' users more)'
49
- users_start = Time.now
50
-
51
- # Create demo user if not present
52
- if Actor.find_by_slug('demo').blank?
53
- u = User.create! :name => '<Demo>',
54
- :email => 'demo@social-stream.dit.upm.es',
55
- :password => 'demonstration',
56
- :password_confirmation => 'demonstration'
57
- u.actor!.update_attribute :slug, 'demo'
58
- end
48
+ SocialStream::Population.task "User population (Demo and #{ @USERS } users more)" do
59
49
 
60
- @USERS.times do
61
- User.create! :name => Forgery::Name.full_name,
62
- :email => Forgery::Internet.email_address,
63
- :password => 'demonstration',
64
- :password_confirmation => 'demonstration'
65
- end
50
+ # Create demo user if not present
51
+ if Actor.find_by_slug('demo').blank?
52
+ u = User.create! :name => '<Demo>',
53
+ :email => 'demo@social-stream.dit.upm.es',
54
+ :password => 'demonstration',
55
+ :password_confirmation => 'demonstration'
56
+ u.actor!.update_attribute :slug, 'demo'
57
+ end
66
58
 
67
- # Reload actors to include new users
68
- @available_actors = Actor.all
59
+ @USERS.times do
60
+ User.create! :name => Forgery::Name.full_name,
61
+ :email => Forgery::Internet.email_address,
62
+ :password => 'demonstration',
63
+ :password_confirmation => 'demonstration'
64
+ end
69
65
 
70
- users_end = Time.now
71
- puts ' -> ' + (users_end - users_start).round(4).to_s + 's'
66
+ # Reload actors to include new users
67
+ @available_actors = Actor.all
68
+ end
72
69
  end
73
70
 
74
71
 
75
72
  # GROUPS
76
73
  desc "Create groups"
77
74
  task :groups => :read_environment do
78
- puts 'Groups population (' + @GROUPS.to_s + ' groups)'
79
- groups_start = Time.now
75
+ SocialStream::Population.task "Groups population (#{ @GROUPS } groups)" do
76
+ @GROUPS.times do
77
+ founder = @available_actors[rand(@available_actors.size)]
80
78
 
81
- @GROUPS.times do
82
- founder = @available_actors[rand(@available_actors.size)]
79
+ Group.create! :name => Forgery::Name.company_name,
80
+ :email => Forgery::Internet.email_address,
81
+ :author_id => founder.id,
82
+ :user_author_id => founder.id
83
+ end
83
84
 
84
- Group.create! :name => Forgery::Name.company_name,
85
- :email => Forgery::Internet.email_address,
86
- :author_id => founder.id,
87
- :user_author_id => founder.id
85
+ # Reload actors to include groups
86
+ @available_actors = Actor.all
88
87
  end
89
-
90
- # Reload actors to include groups
91
- @available_actors = Actor.all
92
-
93
- groups_end = Time.now
94
- puts ' -> ' + (groups_end - groups_start).round(4).to_s + 's'
95
88
  end
96
89
 
97
90
  desc "Populate profiles"
98
91
 
99
92
  task :profiles => :read_environment do
100
- puts "Profiles population"
101
- time = Time.now
93
+ SocialStream::Population.task "Profiles population" do
94
+ SocialStream::Population::Actor.available.each do |a|
95
+ p = a.profile
102
96
 
103
- SocialStream::Population::Actor.available.each do |a|
104
- p = a.profile
97
+ if rand < 0.2
98
+ a.tag_list = Forgery::LoremIpsum.words(3, random: true).gsub(' ', ',')
99
+ end
105
100
 
106
- if rand < 0.2
107
- a.tag_list = Forgery::LoremIpsum.words(3, random: true).gsub(' ', ',')
108
- end
101
+ if rand < 0.2
102
+ p.organization = Forgery::Name.company_name
103
+ end
109
104
 
110
- if rand < 0.2
111
- p.organization = Forgery::Name.company_name
112
- end
105
+ if rand < 0.2
106
+ p.birthday = Time.at(Time.now.to_i - (18.years + rand(60.years)))
107
+ end
113
108
 
114
- if rand < 0.2
115
- p.birthday = Time.at(Time.now.to_i - (18.years + rand(60.years)))
116
- end
109
+ if rand < 0.2
110
+ p.city = Forgery::Address.city
111
+ end
117
112
 
118
- if rand < 0.2
119
- p.city = Forgery::Address.city
120
- end
113
+ if rand < 0.2
114
+ p.country = Forgery::Address.country
115
+ end
121
116
 
122
- if rand < 0.2
123
- p.country = Forgery::Address.country
124
- end
117
+ if rand < 0.2
118
+ p.description = Forgery::LoremIpsum.sentences(2, random: true)
119
+ end
125
120
 
126
- if rand < 0.2
127
- p.description = Forgery::LoremIpsum.sentences(2, random: true)
128
- end
121
+ if rand < 0.2
122
+ p.phone = Forgery::Address.phone
123
+ end
129
124
 
130
- if rand < 0.2
131
- p.phone = Forgery::Address.phone
132
- end
125
+ if rand < 0.2
126
+ p.address = Forgery::Address.street_address
127
+ end
133
128
 
134
- if rand < 0.2
135
- p.address = Forgery::Address.street_address
136
- end
129
+ if rand < 0.2
130
+ p.website = "http://#{ Forgery::Internet.domain_name }"
131
+ end
137
132
 
138
- if rand < 0.2
139
- p.website = "http://#{ Forgery::Internet.domain_name }"
140
- end
133
+ if rand < 0.2
134
+ p.experience = Forgery::LoremIpsum.sentences(3, random: true)
135
+ end
141
136
 
142
- if rand < 0.2
143
- p.experience = Forgery::LoremIpsum.sentences(3, random: true)
137
+ p.save!
144
138
  end
145
-
146
- p.save!
147
139
  end
148
-
149
- puts ' -> ' + (Time.now - time).round(4).to_s + 's'
150
140
  end
151
141
 
152
142
  # TIES
153
143
  desc "Create ties"
154
144
  task :ties => :read_environment do
155
- puts 'Ties population'
156
- ties_start = Time.now
157
-
158
- SocialStream::Population::Actor.available.each do |a|
159
- actors = SocialStream::Population::Actor.available
160
- actors.delete(a)
161
-
162
- relations = a.relation_customs + [ Relation::Reject.instance ]
163
-
164
- Forgery::Basic.number(:at_most => actors.size).times do
165
- actor = actors.delete_at((rand * actors.size).to_i)
166
- contact = a.contact_to!(actor)
167
- contact.user_author = a.user_author if a.subject_type != "User"
168
- contact.relation_ids = [ Forgery::Extensions::Array.new(relations).random.id ]
145
+ SocialStream::Population.task 'Ties population' do
146
+ SocialStream::Population::Actor.available.each do |a|
147
+ actors = SocialStream::Population::Actor.available
148
+ actors.delete(a)
149
+
150
+ relations = a.relation_customs + [ Relation::Reject.instance ]
151
+
152
+ Forgery::Basic.number(:at_most => actors.size).times do
153
+ actor = actors.delete_at((rand * actors.size).to_i)
154
+ contact = a.contact_to!(actor)
155
+ contact.user_author = a.user_author if a.subject_type != "User"
156
+ contact.relation_ids = [ Forgery::Extensions::Array.new(relations).random.id ]
157
+ end
169
158
  end
170
- end
171
-
172
- Activity.includes(:activity_verb).merge(ActivityVerb.verb_name(["follow", "make-friend"])).each do |a|
173
- t = SocialStream::Population::Timestamps.new
174
-
175
- a.update_attributes :created_at => t.created,
176
- :updated_at => t.updated
177
- end
178
-
179
- ties_end = Time.now
180
- puts ' -> ' + (ties_end - ties_start).round(4).to_s + 's'
181
- end
182
159
 
160
+ Activity.includes(:activity_verb).merge(ActivityVerb.verb_name(["follow", "make-friend"])).each do |a|
161
+ t = SocialStream::Population::Timestamps.new
183
162
 
184
- # TIES, special version for cheesecake testing
185
- desc "Create cheesecake ties"
186
- task :cheesecake_ties => :read_environment do
187
- puts 'Ties population (Cheesecake version)'
188
- ties_start = Time.now
189
-
190
- SocialStream::Population::Actor.available.each do |a|
191
- actors = SocialStream::Population::Actor.available - Array(a)
192
- relations = a.relation_customs + Array.wrap(Relation::Reject.instance)
193
- break if actors.size==0
194
- actor = Actor.first
195
- unless a==actor
196
- puts a.name + " connecting with " + actor.name
197
- # DRY! :-S
198
- contact = a.contact_to!(actor)
199
- contact.user_author = a.user_author if a.subject_type != "User"
200
- contact.relation_ids = Array(Forgery::Extensions::Array.new(a.relation_customs).random.id)
201
-
202
- contact = actor.contact_to!(a)
203
- contact.user_author = actor.user_author if actor.subject_type != "User"
204
- contact.relation_ids = Array(Forgery::Extensions::Array.new(actor.relation_customs).random.id)
163
+ a.update_attributes :created_at => t.created,
164
+ :updated_at => t.updated
205
165
  end
206
166
  end
207
-
208
- ties_end = Time.now
209
- puts ' -> ' + (ties_end - ties_start).round(4).to_s + 's'
210
167
  end
211
168
 
212
-
213
169
  # POSTS
214
170
  desc "Create posts"
215
171
  task :posts => :read_environment do
@@ -223,58 +179,52 @@ namespace :db do
223
179
  # MESSAGES
224
180
  desc "Create messages using mailboxer"
225
181
  task :messages => :read_environment do
226
- puts 'Mailboxer population'
227
- mailboxer_start = Time.now
182
+ SocialStream::Population.task 'Mailboxer population' do
183
+ demo = SocialStream::Population::Actor.demo
184
+ @available_actors = Actor.all.sample(Actor.count / 3)
185
+ @available_actors |= [ demo ]
228
186
 
229
- demo = SocialStream::Population::Actor.demo
230
- @available_actors = Actor.all.sample(Actor.count / 3)
231
- @available_actors |= [ demo ]
232
187
 
188
+ 5.times do
189
+ actors = @available_actors.dup
233
190
 
234
- 5.times do
235
- actors = @available_actors.dup
191
+ mult_recp = actors.uniq
236
192
 
237
- mult_recp = actors.uniq
193
+ actor = mult_recp.sample
238
194
 
239
- actor = mult_recp.sample
195
+ mult_recp.delete(actor)
240
196
 
241
- mult_recp.delete(actor)
197
+ mail = actor.send_message(mult_recp, "Hello all, I am #{actor.name}. #{Forgery::LoremIpsum.sentences(2,:random => true)}", Forgery::LoremIpsum.words(10,:random => true))
242
198
 
243
- mail = actor.send_message(mult_recp, "Hello all, I am #{actor.name}. #{Forgery::LoremIpsum.sentences(2,:random => true)}", Forgery::LoremIpsum.words(10,:random => true))
199
+ [ 'Well', 'Ok', 'Pretty well', 'Finally' ].inject(mail) do |st|
200
+ break if rand < 0.2
244
201
 
245
- [ 'Well', 'Ok', 'Pretty well', 'Finally' ].inject(mail) do |st|
246
- break if rand < 0.2
202
+ actor = mult_recp.sample
247
203
 
248
- actor = mult_recp.sample
204
+ mail = actor.reply_to_all(mail, "#{ st }, I am #{actor.name}. #{Forgery::LoremIpsum.sentences(2,:random => true)}")
249
205
 
250
- mail = actor.reply_to_all(mail, "#{ st }, I am #{actor.name}. #{Forgery::LoremIpsum.sentences(2,:random => true)}")
251
-
252
- mail
253
- end
206
+ mail
207
+ end
254
208
 
255
- if rand > 0.75
256
- mail.conversation.move_to_trash(demo)
257
- end
209
+ if rand > 0.75
210
+ mail.conversation.move_to_trash(demo)
211
+ end
258
212
 
259
- @available_actors = (Actor.all.sample(Actor.count / 3) - [ demo ])
213
+ @available_actors = (Actor.all.sample(Actor.count / 3) - [ demo ])
260
214
 
261
- @available_actors.each do |a|
262
- mail = a.send_message(demo, "Hello, #{demo.name}. #{Forgery::LoremIpsum.sentences(2,:random => true)}", Forgery::LoremIpsum.words(10,:random => true))
263
- if rand > 0.5
264
- mail = demo.reply_to_sender(mail, "Pretty well #{a.name}. #{Forgery::LoremIpsum.sentences(2,:random => true)}")
215
+ @available_actors.each do |a|
216
+ mail = a.send_message(demo, "Hello, #{demo.name}. #{Forgery::LoremIpsum.sentences(2,:random => true)}", Forgery::LoremIpsum.words(10,:random => true))
265
217
  if rand > 0.5
266
- a.reply_to_sender(mail, "Ok #{demo.name}. #{Forgery::LoremIpsum.sentences(2,:random => true)}")
218
+ mail = demo.reply_to_sender(mail, "Pretty well #{a.name}. #{Forgery::LoremIpsum.sentences(2,:random => true)}")
219
+ if rand > 0.5
220
+ a.reply_to_sender(mail, "Ok #{demo.name}. #{Forgery::LoremIpsum.sentences(2,:random => true)}")
221
+ end
267
222
  end
268
223
  end
269
224
  end
270
225
  end
271
-
272
- mailboxer_end = Time.now
273
- puts ' -> ' + (mailboxer_end - mailboxer_start).round(4).to_s + 's'
274
-
275
226
  end
276
227
 
277
-
278
228
  # AVATARS
279
229
  desc "Create avatars"
280
230
  task :avatars => :read_environment do
@@ -295,11 +245,9 @@ namespace :db do
295
245
  end
296
246
  end
297
247
 
298
- puts 'Avatar population'
299
- avatar_start = Time.now
300
- SocialStream.subjects.each {|a| set_logos(Kernel.const_get(a.to_s.classify)) }
301
- avatar_end = Time.now
302
- puts ' -> ' + (avatar_end - avatar_start).round(4).to_s + 's'
248
+ SocialStream::Population.task 'Avatar population' do
249
+ SocialStream.subjects.each {|a| set_logos(Kernel.const_get(a.to_s.classify)) }
250
+ end
303
251
  end
304
252
  end
305
253
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_stream-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GING - DIT - UPM
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-01 00:00:00.000000000 Z
11
+ date: 2013-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge
@@ -1145,6 +1145,7 @@ files:
1145
1145
  - lib/social_stream/models/subject.rb
1146
1146
  - lib/social_stream/models/subtype.rb
1147
1147
  - lib/social_stream/models/supertype.rb
1148
+ - lib/social_stream/population.rb
1148
1149
  - lib/social_stream/population/activity_object.rb
1149
1150
  - lib/social_stream/population/actor.rb
1150
1151
  - lib/social_stream/population/power_law.rb
@@ -1281,7 +1282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1281
1282
  version: '0'
1282
1283
  requirements: []
1283
1284
  rubyforge_project:
1284
- rubygems_version: 2.0.0
1285
+ rubygems_version: 2.0.6
1285
1286
  signing_key:
1286
1287
  specification_version: 4
1287
1288
  summary: Basic features for Social Stream, the core for building social network websites