social_stream-base 0.24.1 → 0.24.2

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.
@@ -1,2 +1,3 @@
1
- class Ability < SocialStream::Ability
1
+ class Ability
2
+ include SocialStream::Ability
2
3
  end
@@ -2,13 +2,8 @@
2
2
  <% locale_as @receiver.subject %>
3
3
  <%= t('notification.hello', :receiver => @receiver.name)%>
4
4
 
5
- <% if @notification.notified_object.verb == 'join' %>
6
- <%= render :partial => "notifications/activities/join_#{ @notification.notified_object.direct_object.class.to_s.underscore }",
7
- :locals =>{:activity => @notification.notified_object} %>
8
- <% else %>
9
- <%= render :partial => "notifications/activities/#{ @notification.notified_object.verb }",
10
- :locals =>{:activity => @notification.notified_object}%>
11
- <% end %>
5
+ <%= render partial: "notifications/activities/#{ @notification.notified_object.verb }",
6
+ locals: { activity: @notification.notified_object } %>
12
7
 
13
8
  -----------------------------------------------
14
9
  <%= raw t('notification.visit', :url=> notifications_url)%>
@@ -20,14 +20,8 @@
20
20
 
21
21
  <div class="content_right">
22
22
  <div class="briefing">
23
- <% if notification.notified_object.verb == 'join' %>
24
- <%= render :partial => "notifications/activities/join_#{ notification.notified_object.direct_object.class.to_s.underscore }",
25
- :locals =>{:activity => notification.notified_object} %>
26
- <% else %>
27
-
28
- <%= render :partial => "notifications/activities/#{ notification.notified_object.verb }",
29
- :locals =>{:activity => notification.notified_object} %>
30
- <% end %>
23
+ <%= render partial: "notifications/activities/#{ notification.notified_object.verb }",
24
+ locals: { activity: notification.notified_object } %>
31
25
  </div>
32
26
  <div class="clearfloat">
33
27
  </div>
@@ -47,4 +41,4 @@
47
41
  </div>
48
42
  <div class="clearfloat">
49
43
  </div>
50
- <% end %>
44
+ <% end %>
@@ -59,4 +59,40 @@ class SocialStream::Base::InstallGenerator < Rails::Generators::Base #:nodoc:
59
59
  Rake::Task['railties:install:migrations'].reenable
60
60
  Rake::Task['social_stream_base_engine:install:migrations'].invoke
61
61
  end
62
+
63
+ def create_ability_file
64
+ ability_code = [
65
+ "# Generator social_stream:install has modified this file. Please,", #0
66
+ "# check everything is working ok, specially if the former `Ability`", #1
67
+ "# class inherited from another class or included another module", #2
68
+ "class Ability", #3
69
+ " include SocialStream::Ability", #4
70
+ "", #5
71
+ " def initialize(subject)", #6
72
+ " super", #7
73
+ "", #8
74
+ " # Add your authorization rules here", #9
75
+ " # For instance:", #10
76
+ " # can :create, Comment", #11
77
+ " # can [:create, :destroy], Post do |p|", #12
78
+ " # p.actor_id == Actor.normalize_id(subject)", #13
79
+ " # end", #14
80
+ " end", #15
81
+ "end"] #16
82
+ ability_file = 'app/models/ability.rb'
83
+
84
+ if FileTest.exists? ability_file
85
+ prepend_to_file ability_file, ability_code[0..2].join("\n")+"\n"
86
+ if not File.read(ability_file).include?("include SocialStream::Ability\n")
87
+ inject_into_file ability_file, ability_code[4..5].join("\n")+"\n", :after => /class Ability(.*)\n/
88
+ end
89
+ if File.read(ability_file).include?("def initialize\n")
90
+ inject_into_file ability_file, ability_code[7..14].join("\n")+"\n", :after => /def initialize(.*)\n/
91
+ else
92
+ inject_into_file ability_file, ability_code[5..15].join("\n")+"\n", :after => /include SocialStream::Ability\n/
93
+ end
94
+ else
95
+ create_file ability_file, ability_code[3..16].join("\n")
96
+ end
97
+ end
62
98
  end
@@ -10,13 +10,14 @@ SocialStream.setup do |config|
10
10
  # config.devise_modules = :database_authenticatable, :registerable,
11
11
  # :recoverable, :rememberable, :trackable,
12
12
  # :omniauthable, :token_authenticatable
13
-
13
+
14
14
  # Type of activities managed by actors
15
15
  # Remember you must add an "activity_object_id" foreign key column to your migration!
16
+ # Be sure to add the other modules of Social Stream you might be using (e.g. :document, :event, :link ).
16
17
  #
17
18
  # config.objects = [ :post, :comment ]
18
-
19
- # Form for activity objects to be loaded
19
+
20
+ # Form for activity objects to be loaded
20
21
  # You can write your own activity objects
21
22
  #
22
23
  # config.activity_forms = [ :post, :document, :foo, :bar ]
@@ -31,10 +32,10 @@ SocialStream.setup do |config|
31
32
  # Expose resque interface to manage background tasks at /resque
32
33
  #
33
34
  # config.resque_access = true
34
-
35
+
35
36
  # Quick search (header) and Extended search models and its order. Remember to create
36
37
  # the indexes with thinking-sphinx if you are using customized models.
37
- #
38
+ #
38
39
  # config.quick_search_models = [:user, :group]
39
40
  # config.extended_search_models = [:user, :group]
40
41
 
@@ -1,7 +1,7 @@
1
- require 'social_stream/ability/base'
1
+ require 'social_stream/base/ability'
2
2
 
3
3
  module SocialStream
4
- class Ability
5
- include SocialStream::Ability::Base
4
+ module Ability
5
+ include SocialStream::Base::Ability
6
6
  end
7
7
  end
@@ -1,6 +1,6 @@
1
1
  module SocialStream
2
- class Ability
3
- module Base
2
+ module Base
3
+ module Ability
4
4
  include CanCan::Ability
5
5
 
6
6
  # Create a new ability for this user, who is currently representing subject
@@ -1,5 +1,5 @@
1
1
  module SocialStream
2
2
  module Base
3
- VERSION = "0.24.1".freeze
3
+ VERSION = "0.24.2".freeze
4
4
  end
5
5
  end
@@ -90,7 +90,7 @@ module SocialStream
90
90
  # Override Cancan#current_ability method to use {#current_subject}
91
91
  def current_ability
92
92
  @current_ability ||=
93
- Ability.new(current_subject)
93
+ ::Ability.new(current_subject)
94
94
  end
95
95
 
96
96
  private
@@ -3,12 +3,15 @@ require 'social_stream/base/dependencies'
3
3
 
4
4
  # Provides your Rails application with social network and activity stream support
5
5
  module SocialStream
6
- autoload :Ability, 'social_stream/ability'
6
+ autoload :Ability, 'social_stream/ability'
7
7
  autoload :ActivityStreams, 'social_stream/activity_streams'
8
8
  module ActivityStreams
9
9
  autoload :Supertype, 'social_stream/activity_streams/supertype'
10
10
  autoload :Subtype, 'social_stream/activity_streams/subtype'
11
11
  end
12
+ module Base
13
+ autoload :Ability, 'social_stream/base/ability'
14
+ end
12
15
  autoload :D3, 'social_stream/d3'
13
16
  autoload :Populate, 'social_stream/populate'
14
17
  autoload :Relations, 'social_stream/relations'
@@ -52,6 +52,10 @@ namespace :workers do
52
52
  ENV['COUNT']
53
53
  end
54
54
 
55
+ def queue_pathname
56
+ queue.gsub(/[:\*<>\|\"\/\\\?]/, "_")
57
+ end
58
+
55
59
  def Process.exists?(pid)
56
60
  kill(0, pid.to_i) rescue false
57
61
  end
@@ -61,11 +65,11 @@ namespace :workers do
61
65
  end
62
66
 
63
67
  def pid_directory_for_group
64
- @pid_directory_for_group ||= Rails.root.join('tmp', 'pids', "resque", queue)
68
+ @pid_directory_for_group ||= Rails.root.join('tmp', 'pids', "resque", queue_pathname)
65
69
  end
66
70
 
67
71
  def group_master_pid
68
- File.read pid_directory.join("#{queue}.pid").to_s rescue nil
72
+ File.read pid_directory.join("#{queue_pathname}.pid").to_s rescue nil
69
73
  end
70
74
 
71
75
  def group?
@@ -77,10 +81,20 @@ namespace :workers do
77
81
  end
78
82
 
79
83
  def kill_worker(pid)
80
- Process.kill("QUIT", pid)
81
- puts "Killed worker with PID #{pid}"
82
- rescue Errno::ESRCH => e
83
- puts " STALE worker with PID #{pid}"
84
+ %w{QUIT TERM KILL}.each do |signal|
85
+ if Signal.list.has_key?(signal)
86
+ begin
87
+ Process.kill(signal, pid)
88
+ rescue Errno::EINVAL
89
+ next
90
+ end
91
+
92
+ puts "Killed worker with PID #{pid}"
93
+ break
94
+ end
95
+ end
96
+ rescue Errno::ESRCH => e
97
+ puts " STALE worker with PID #{pid}"
84
98
  end
85
99
 
86
100
  def kill_workers
@@ -97,7 +111,7 @@ namespace :workers do
97
111
  end
98
112
  end
99
113
  if group_master_pid
100
- FileUtils.rm pid_directory.join("#{queue}.pid").to_s
114
+ FileUtils.rm pid_directory.join("#{queue_pathname}.pid").to_s
101
115
  FileUtils.rm_rf pid_directory_for_group.to_s
102
116
  end
103
117
  end
@@ -120,7 +134,13 @@ namespace :workers do
120
134
 
121
135
  # Handle exit
122
136
  trap('INT') { shutdown }
123
- trap('QUIT') { shutdown }
137
+
138
+ begin
139
+ trap('QUIT') { shutdown }
140
+ rescue ArgumentError
141
+ warn "SIGQUIT not supported"
142
+ end
143
+
124
144
  trap('TERM') { shutdown }
125
145
  trap('KILL') { shutdown }
126
146
  trap('SIGKILL') { shutdown }
@@ -130,7 +150,11 @@ namespace :workers do
130
150
  # Launch workers in separate processes, saving their PIDs
131
151
  @pids = []
132
152
  ENV['COUNT'].to_i.times do
133
- @pids << Process.fork { Rake::Task['resque:work'].invoke }
153
+ if Process.respond_to?(:fork)
154
+ @pids << Process.fork { Rake::Task['resque:work'].invoke }
155
+ else
156
+ @pids << Process.spawn("rake environment resque:work", chdir: Rails.root)
157
+ end
134
158
  end
135
159
 
136
160
  if group?
@@ -138,7 +162,7 @@ namespace :workers do
138
162
  FileUtils.mkdir_p pid_directory.to_s
139
163
  FileUtils.mkdir_p pid_directory_for_group.to_s
140
164
  # Create PID files for workers
141
- File.open( pid_directory.join("#{queue}.pid").to_s, 'w' ) do |f| f.write Process.pid end
165
+ File.open( pid_directory.join("#{queue_pathname}.pid").to_s, 'w' ) do |f| f.write Process.pid end
142
166
  @pids.each do |pid|
143
167
  File.open( pid_directory_for_group.join("worker_#{pid}.pid").to_s, 'w' ) { |f| f.write pid }
144
168
  end
@@ -156,7 +180,7 @@ namespace :workers do
156
180
  Resque::Worker.all.each do |worker|
157
181
  puts "Shutting down worker #{worker}"
158
182
  host, pid, queues = worker.id.split(':')
159
- Process.kill("QUIT", pid.to_i)
183
+ kill_worker(pid.to_i)
160
184
  end
161
185
  end
162
186
 
@@ -10,13 +10,14 @@ SocialStream.setup do |config|
10
10
  # config.devise_modules = :database_authenticatable, :registerable,
11
11
  # :recoverable, :rememberable, :trackable,
12
12
  # :omniauthable, :token_authenticatable
13
-
13
+
14
14
  # Type of activities managed by actors
15
15
  # Remember you must add an "activity_object_id" foreign key column to your migration!
16
+ # Be sure to add the other modules of Social Stream you might be using (e.g. :document, :event, :link ).
16
17
  #
17
18
  # config.objects = [ :post, :comment ]
18
-
19
- # Form for activity objects to be loaded
19
+
20
+ # Form for activity objects to be loaded
20
21
  # You can write your own activity objects
21
22
  #
22
23
  # config.activity_forms = [ :post, :document, :foo, :bar ]
@@ -31,10 +32,10 @@ SocialStream.setup do |config|
31
32
  # Expose resque interface to manage background tasks at /resque
32
33
  #
33
34
  # config.resque_access = true
34
-
35
+
35
36
  # Quick search (header) and Extended search models and its order. Remember to create
36
37
  # the indexes with thinking-sphinx if you are using customized models.
37
- #
38
+ #
38
39
  # config.quick_search_models = [:user, :group]
39
40
  # config.extended_search_models = [:user, :group]
40
41
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_stream-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.1
4
+ version: 0.24.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-17 00:00:00.000000000 Z
13
+ date: 2012-12-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: deep_merge
@@ -1113,10 +1113,10 @@ files:
1113
1113
  - lib/rails/social_stream.rb
1114
1114
  - lib/social_stream-base.rb
1115
1115
  - lib/social_stream/ability.rb
1116
- - lib/social_stream/ability/base.rb
1117
1116
  - lib/social_stream/activity_streams.rb
1118
1117
  - lib/social_stream/activity_streams/subtype.rb
1119
1118
  - lib/social_stream/activity_streams/supertype.rb
1119
+ - lib/social_stream/base/ability.rb
1120
1120
  - lib/social_stream/base/dependencies.rb
1121
1121
  - lib/social_stream/base/engine.rb
1122
1122
  - lib/social_stream/base/thinking-sphinx.rb