Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: pokonski/public_activity
...
head fork: pokonski/public_activity
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
131 Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- public_activity (0.3.1)
+ public_activity (0.3.3)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
i18n (>= 0.5.0)
@@ -10,109 +10,102 @@ PATH
GEM
remote: http://rubygems.org/
specs:
- actionmailer (3.1.1)
- actionpack (= 3.1.1)
- mail (~> 2.3.0)
- actionpack (3.1.1)
- activemodel (= 3.1.1)
- activesupport (= 3.1.1)
+ actionmailer (3.2.3)
+ actionpack (= 3.2.3)
+ mail (~> 2.4.4)
+ actionpack (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
builder (~> 3.0.0)
erubis (~> 2.7.0)
- i18n (~> 0.6)
- rack (~> 1.3.2)
- rack-cache (~> 1.1)
- rack-mount (~> 0.8.2)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.2)
rack-test (~> 0.6.1)
- sprockets (~> 2.0.2)
- activemodel (3.1.1)
- activesupport (= 3.1.1)
+ sprockets (~> 2.1.2)
+ activemodel (3.2.3)
+ activesupport (= 3.2.3)
builder (~> 3.0.0)
- i18n (~> 0.6)
- activerecord (3.1.1)
- activemodel (= 3.1.1)
- activesupport (= 3.1.1)
- arel (~> 2.2.1)
+ activerecord (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
+ arel (~> 3.0.2)
tzinfo (~> 0.3.29)
- activeresource (3.1.1)
- activemodel (= 3.1.1)
- activesupport (= 3.1.1)
- activesupport (3.1.1)
+ activeresource (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
+ activesupport (3.2.3)
+ i18n (~> 0.6)
multi_json (~> 1.0)
- arel (2.2.1)
+ arel (3.0.2)
builder (3.0.0)
- crack (0.1.8)
diff-lcs (1.1.3)
erubis (2.7.0)
hike (1.2.1)
i18n (0.6.0)
- json (1.6.1)
- mail (2.3.0)
+ journey (1.0.3)
+ json (1.7.3)
+ mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
- mime-types (1.16)
- multi_json (1.0.3)
- polyglot (0.3.2)
- pusher (0.8.4)
- crack (~> 0.1.0)
+ mime-types (1.18)
+ multi_json (1.3.5)
+ polyglot (0.3.3)
+ pusher (0.9.3)
multi_json (~> 1.0)
- ruby-hmac (~> 0.4.0)
signature (~> 0.1.2)
- rack (1.3.4)
- rack-cache (1.1)
+ rack (1.4.1)
+ rack-cache (1.2)
rack (>= 0.4)
- rack-mount (0.8.3)
- rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
- rails (3.1.1)
- actionmailer (= 3.1.1)
- actionpack (= 3.1.1)
- activerecord (= 3.1.1)
- activeresource (= 3.1.1)
- activesupport (= 3.1.1)
+ rails (3.2.3)
+ actionmailer (= 3.2.3)
+ actionpack (= 3.2.3)
+ activerecord (= 3.2.3)
+ activeresource (= 3.2.3)
+ activesupport (= 3.2.3)
bundler (~> 1.0)
- railties (= 3.1.1)
- railties (3.1.1)
- actionpack (= 3.1.1)
- activesupport (= 3.1.1)
+ railties (= 3.2.3)
+ railties (3.2.3)
+ actionpack (= 3.2.3)
+ activesupport (= 3.2.3)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
- rake (0.9.2)
- rdoc (3.11)
+ rake (0.9.2.2)
+ rdoc (3.12)
json (~> 1.4)
- rspec (2.7.0)
- rspec-core (~> 2.7.0)
- rspec-expectations (~> 2.7.0)
- rspec-mocks (~> 2.7.0)
- rspec-core (2.7.0)
- rspec-expectations (2.7.0)
- diff-lcs (~> 1.1.2)
- rspec-mocks (2.7.0)
- rspec-rails (2.7.0)
- actionpack (~> 3.0)
- activesupport (~> 3.0)
- railties (~> 3.0)
- rspec (~> 2.7.0)
- ruby-hmac (0.4.0)
- signature (0.1.2)
- ruby-hmac
- sprockets (2.0.3)
+ rspec (2.10.0)
+ rspec-core (~> 2.10.0)
+ rspec-expectations (~> 2.10.0)
+ rspec-mocks (~> 2.10.0)
+ rspec-core (2.10.1)
+ rspec-expectations (2.10.0)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.10.1)
+ rspec-rails (2.10.1)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec (~> 2.10.0)
+ signature (0.1.3)
+ sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- sqlite3 (1.3.4)
+ sqlite3 (1.3.6)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
- tzinfo (0.3.30)
- yard (0.7.3)
+ tzinfo (0.3.33)
+ yard (0.8.1)
PLATFORMS
ruby
View
3  lib/public_activity/activity.rb
@@ -12,7 +12,8 @@ class Activity < ActiveRecord::Base
serialize :parameters, Hash
class_attribute :template
-
+
+ attr_accessible :key, :owner, :parameters
# Virtual attribute returning text description of the activity
# using basic ERB templating
#
View
97 lib/public_activity/common.rb
@@ -2,58 +2,55 @@ module PublicActivity
# Common methods shared across the gem.
module Common
extend ActiveSupport::Concern
- # Instance methods used by other methods in PublicActivity module.
- module InstanceMethods
- # Directly creates activity record in the database, based on supplied arguments.
- # Only first argument - key - is required.
- #
- # == Usage:
- #
- # current_user.create_activity("activity.user.avatar_changed") if @user.avatar_file_name_changed?
- #
- # == Parameters:
- # [key]
- # Custom key that will be used as a i18n translation key - *required*
- # [owner]
- # Polymorphic relation specifying the owner of this activity (for example, a User who performed this task) - *optional*
- # [params]
- # Hash with parameters passed directly into i18n.translate method - *optional*
- #
- def create_activity(key, owner = nil, params = {})
-
- if owner.nil? && ((defined? User) != nil) && User.respond_to?(:current_user)
- owner = User.current_user
- end
-
- activity = self.activities.create(:key => key, :owner => owner, :parameters => params)
- if !Pusher.app_id.nil? && !Pusher.key.nil? && !Pusher.secret.nil?
- Pusher['acitivty-channel'].trigger('acitivty-create', {:key => key, :owner => owner, :parameters => params, :text => activity.text, :object => self})
- end
+ # Directly creates activity record in the database, based on supplied arguments.
+ # Only first argument - key - is required.
+ #
+ # == Usage:
+ #
+ # current_user.create_activity("activity.user.avatar_changed") if @user.avatar_file_name_changed?
+ #
+ # == Parameters:
+ # [key]
+ # Custom key that will be used as a i18n translation key - *required*
+ # [owner]
+ # Polymorphic relation specifying the owner of this activity (for example, a User who performed this task) - *optional*
+ # [params]
+ # Hash with parameters passed directly into i18n.translate method - *optional*
+ #
+ def create_activity(key, owner = nil, params = {})
+
+ if owner.nil? && ((defined? User) != nil) && User.respond_to?(:current_user)
+ owner = User.current_user
end
- private
- # Prepares settings used during creation of Activity record.
- # params passed directly to tracked model have priority over
- # settings specified in tracked() method
- def prepare_settings
- # user responsible for the activity
- if self.activity_owner
- owner = self.activity_owner
- else
- owner = self.class.activity_owner_global
- end
-
- case owner
- when Symbol
- owner = self.try(owner)
- when Proc
- owner = owner.call(self)
- end
- #customizable parameters
- parameters = self.class.activity_params_global
- parameters.merge! self.activity_params if self.activity_params
- return {:key => self.activity_key,:owner => owner, :parameters => parameters}
- end
+ activity = self.activities.create(:key => key, :owner => owner, :parameters => params)
+ if !Pusher.app_id.nil? && !Pusher.key.nil? && !Pusher.secret.nil?
+ Pusher['acitivty-channel'].trigger('acitivty-create', {:key => key, :owner => owner, :parameters => params, :text => activity.text, :object => self})
+ end
end
+
+ private
+ # Prepares settings used during creation of Activity record.
+ # params passed directly to tracked model have priority over
+ # settings specified in tracked() method
+ def prepare_settings
+ # user responsible for the activity
+ if self.activity_owner
+ owner = self.activity_owner
+ else
+ owner = self.class.activity_owner_global
+ end
+
+ case owner
+ when Symbol
+ owner = self.try(owner)
+ when Proc
+ owner = owner.call(self)
+ end
+ #customizable parameters
+ parameters = self.class.activity_params_global
+ parameters.merge! self.activity_params if self.activity_params
+ return {:key => self.activity_key,:owner => owner, :parameters => parameters}
+ end
end
end
View
15 lib/public_activity/creation.rb
@@ -6,14 +6,11 @@ module Creation
included do
after_create :activity_on_create
end
- # Handlers responsible for creating Activities.
- module InstanceMethods
- private
- # Creates activity upon creation of the tracked model
- def activity_on_create
- settings = prepare_settings
- create_activity(settings[:key] || "activity."+self.class.name.parameterize('_')+".create", settings[:owner], settings[:parameters])
- end
- end
+ private
+ # Creates activity upon creation of the tracked model
+ def activity_on_create
+ settings = prepare_settings
+ create_activity(settings[:key] || "activity."+self.class.name.parameterize('_')+".create", settings[:owner], settings[:parameters])
+ end
end
end
View
15 lib/public_activity/destruction.rb
@@ -6,14 +6,11 @@ module Destruction
included do
before_destroy :activity_on_destroy
end
- # Handlers responsible for adding {Activity} when object is destroyed.
- module InstanceMethods
- private
- # Records an activity upon destruction of the tracked model
- def activity_on_destroy
- settings = prepare_settings
- create_activity("activity."+self.class.name.parameterize('_')+".destroy", settings[:owner], settings[:parameters])
- end
- end
+ private
+ # Records an activity upon destruction of the tracked model
+ def activity_on_destroy
+ settings = prepare_settings
+ create_activity("activity."+self.class.name.parameterize('_')+".destroy", settings[:owner], settings[:parameters])
+ end
end
end
View
23 lib/public_activity/tracked.rb
@@ -87,12 +87,12 @@ module ClassMethods
# method. It is later used in {Activity#text} method.
# == Example:
# @article.activity :parameters => {:title => @article.title, :short => truncate(@article.text, :length => 50)}
- # Everything specified here has a lower priority than parameters specified directly in {Tracked::InstanceMethods#activity} method.
+ # Everything specified here has a lower priority than parameters specified directly in {#activity} method.
# So treat it as a place where you provide 'default' values.
# For more dynamic settings refer to {Activity} model
# documentation.
# [:skip_defaults]
- # Disables recording of activities on create/update/destroy leaving that to programmer's choice. Check {PublicActivity::Common::InstanceMethods#create_activity}
+ # Disables recording of activities on create/update/destroy leaving that to programmer's choice. Check {PublicActivity::Common#create_activity}
# for a guide on how to manually record activities.
def tracked(options = {})
include Common
@@ -131,8 +131,6 @@ def tracked(options = {})
end
end
- # A module with shortcut method for setting own parameters to the {Activity} model
- module InstanceMethods
# A shortcut method for setting custom key, owner and parameters of {Activity}
# in one line. Accepts a hash with 3 keys:
# :key, :owner, :params. You can specify all of them or just the ones you want to overwrite.
@@ -145,7 +143,7 @@ module InstanceMethods
# Specify the owner of the {Activity} (person responsible for the action).
# It can be a Proc, Symbol or an ActiveRecord object:
# == Examples:
- # @article.activity :owner => :author
+ # @article.activity :owner => :author
# @article.activity :owner => {|o| o.author}
# @article.activity :owner => User.where(:login => 'piotrek').first
# Keep in mind that owner relation is polymorphic, so you can't just provide id number of the owner object.
@@ -160,22 +158,21 @@ module InstanceMethods
#
# class Article < ActiveRecord::Base
# tracked
- # end
+ # end
#
# In controller:
#
# @article = Article.new
- # @article.title = "New article"
+ # @article.title = "New article"
# @article.activity :key => "my.custom.article.key", :owner => @article.author, :params => {:title => @article.title}
# @article.save
# @article.activities.last.key #=> "my.custom.article.key"
# @article.activities.last.parameters #=> {:title => "New article"}
- def activity(options = {})
- self.activity_key = options[:key] if options[:key]
- self.activity_owner = options[:owner] if options[:owner]
- self.activity_params = options[:params] if options[:params]
- end
+ def activity(options = {})
+ self.activity_key = options[:key] if options[:key]
+ self.activity_owner = options[:owner] if options[:owner]
+ self.activity_params = options[:params] if options[:params]
end
-
+
end
end
View
15 lib/public_activity/update.rb
@@ -6,14 +6,11 @@ module Update
included do
after_update :activity_on_update
end
- # Handlers responsible for updating Activities.
- module InstanceMethods
- private
- # Creates activity upon modification of the tracked model
- def activity_on_update
- settings = prepare_settings
- create_activity(settings[:key] || "activity."+self.class.name.parameterize('_')+".update", settings[:owner], settings[:parameters])
- end
- end
+ private
+ # Creates activity upon modification of the tracked model
+ def activity_on_update
+ settings = prepare_settings
+ create_activity(settings[:key] || "activity."+self.class.name.parameterize('_')+".update", settings[:owner], settings[:parameters])
+ end
end
end
View
2  lib/public_activity/version.rb
@@ -1,4 +1,4 @@
module PublicActivity
# A constant with gem's version
- VERSION = '0.3.2'
+ VERSION = '0.3.3'
end

No commit comments for this range

Something went wrong with that request. Please try again.