narrator 0.0.1.beta → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/README.rdoc +0 -1
- data/Rakefile +0 -1
- data/lib/narrator.rb +1 -0
- data/lib/narrator/activity.rb +15 -21
- data/lib/narrator/controller_additions.rb +12 -2
- data/lib/narrator/model_additions.rb +27 -5
- data/lib/narrator/version.rb +1 -1
- data/narrator.gemspec +14 -11
- metadata +19 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 550ddf17fdbb9d5842f2dfa102e16f1f8c2542f8
|
4
|
+
data.tar.gz: ca48647697c0c8b0a3cc919e3a396dbe6eac1ae0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f73733ceac06d10496b1c92c61a68f038a9a7d5abab8d4f905df6d16901faba20bbf165973d4a5113e3c5dae12dfe47f8a17ddf49367efe4e50fcc926cd4bfa
|
7
|
+
data.tar.gz: ad879003c9b482da1fa664c548d87d3d682e8c4789a7c07d3e7a4624c179f4f221ddf58b875093fcf20af304d1780122ec1203429e878e3314c920d4054a1609
|
data/.travis.yml
CHANGED
data/README.rdoc
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
= This gem is currently unstable as it is being developed.
|
2
1
|
= Narrator {<img src="https://secure.travis-ci.org/jweakley/narrator.png?branch=master" />}[http://travis-ci.org/jweakley/narrator]
|
3
2
|
|
4
3
|
Narrator is an activity library for Ruby on Rails that allow you to track what is happening on models and later use to build an activity or news stream. Tracking is done at the controller level with a simple narrate_resource command (which was inspired by the simplicity of Ryan Bates' CanCan gem).
|
data/Rakefile
CHANGED
data/lib/narrator.rb
CHANGED
data/lib/narrator/activity.rb
CHANGED
@@ -1,28 +1,22 @@
|
|
1
1
|
module Narrator
|
2
2
|
class Activity < ::ActiveRecord::Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
attr_accessible :owner,
|
4
|
+
:subject,
|
5
|
+
:actor,
|
6
|
+
:target,
|
7
|
+
:verb,
|
8
|
+
:context,
|
9
|
+
:has_seen
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
belongs_to :actor, polymorphic: true
|
13
|
-
belongs_to :subject, polymorphic: true
|
14
|
-
belongs_to :target, polymorphic: true
|
11
|
+
belongs_to :owner, polymorphic: true
|
12
|
+
belongs_to :actor, polymorphic: true
|
13
|
+
belongs_to :subject, polymorphic: true
|
14
|
+
belongs_to :target, polymorphic: true
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
###
|
19
|
-
validates :subject, presence: true
|
20
|
-
validates :verb, presence: true
|
16
|
+
validates :subject, presence: true
|
17
|
+
validates :verb, presence: true
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
###
|
25
|
-
scope :unseen, where(has_seen: false)
|
26
|
-
scope :seen, where(has_seen: true)
|
19
|
+
scope :unseen, where(has_seen: false)
|
20
|
+
scope :seen, where(has_seen: true)
|
27
21
|
end
|
28
22
|
end
|
@@ -3,7 +3,11 @@ module Narrator
|
|
3
3
|
module ClassMethods
|
4
4
|
|
5
5
|
def narrate_resource(*args)
|
6
|
-
narrator_resource_class.add_after_filter(
|
6
|
+
narrator_resource_class.add_after_filter(
|
7
|
+
self,
|
8
|
+
:narrate_resource,
|
9
|
+
*args
|
10
|
+
)
|
7
11
|
end
|
8
12
|
|
9
13
|
def narrator_resource_class
|
@@ -20,7 +24,13 @@ module Narrator
|
|
20
24
|
base.helper_method :narrate
|
21
25
|
end
|
22
26
|
|
23
|
-
def narrate(
|
27
|
+
def narrate(
|
28
|
+
subject,
|
29
|
+
actor = current_user,
|
30
|
+
target = nil,
|
31
|
+
verb = params[:action],
|
32
|
+
context = nil
|
33
|
+
)
|
24
34
|
if subject.class.respond_to? :track_user_activity
|
25
35
|
# Add some config way of determining to use delayed jobs.
|
26
36
|
subject.class.track_user_activity(
|
@@ -10,25 +10,47 @@ module Narrator
|
|
10
10
|
###
|
11
11
|
# Associations
|
12
12
|
###
|
13
|
-
has_many
|
13
|
+
has_many :activities,
|
14
|
+
as: :subject,
|
15
|
+
class_name: 'Narrator::Activity',
|
16
|
+
dependent: :destroy
|
14
17
|
|
15
18
|
###
|
16
19
|
# Instance Methods
|
17
20
|
###
|
18
21
|
|
19
|
-
|
20
|
-
|
22
|
+
def track_user_activity(
|
23
|
+
subject_id,
|
24
|
+
subject_class,
|
25
|
+
actor_id,
|
26
|
+
actor_class,
|
27
|
+
target_id,
|
28
|
+
target_class,
|
29
|
+
verb,
|
30
|
+
context
|
31
|
+
)
|
21
32
|
actor = actor_id.blank? ? nil : actor_class.constantize.find_by_id(actor_id)
|
22
33
|
subject = subject_id.blank? ? nil : subject_class.constantize.find_by_id(subject_id)
|
23
34
|
target = target_id.blank? ? nil : target_class.constantize.find_by_id(target_id)
|
24
|
-
Narrator::Activity.create!(
|
35
|
+
Narrator::Activity.create!(
|
36
|
+
owner: nil,
|
37
|
+
subject: subject,
|
38
|
+
actor: actor,
|
39
|
+
target: target,
|
40
|
+
verb: verb,
|
41
|
+
context: context
|
42
|
+
)
|
25
43
|
end
|
26
44
|
end
|
45
|
+
|
27
46
|
def narratable_actor
|
28
47
|
###
|
29
48
|
# Associations
|
30
49
|
###
|
31
|
-
has_many
|
50
|
+
has_many :activities,
|
51
|
+
as: :actor,
|
52
|
+
class_name: 'Narrator::Activity',
|
53
|
+
dependent: :destroy
|
32
54
|
end
|
33
55
|
end
|
34
56
|
end
|
data/lib/narrator/version.rb
CHANGED
data/narrator.gemspec
CHANGED
@@ -4,21 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'narrator/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
7
|
+
gem.name = 'narrator'
|
8
8
|
gem.version = Narrator::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
11
|
-
gem.description = %q{Straightforward and flexable activity tracking for rails
|
9
|
+
gem.authors = ['Joe Weakley']
|
10
|
+
gem.email = ['joe.weakley@digitalaugment.com']
|
11
|
+
gem.description = %q{Straightforward and flexable activity tracking for rails.}
|
12
12
|
gem.summary = %q{Straightforward and flexable activity tracking for rails.}
|
13
|
-
gem.homepage =
|
13
|
+
gem.homepage = 'https://github.com/jweakley/narrator'
|
14
14
|
|
15
|
-
gem.files = `git ls-files`.split(
|
16
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
|
+
gem.files = `git ls-files`.split($RS)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = [
|
18
|
+
gem.require_paths = ['lib']
|
19
19
|
|
20
|
-
gem.
|
20
|
+
gem.required_ruby_version = '>= 1.9'
|
21
21
|
|
22
|
-
gem.
|
23
|
-
|
22
|
+
gem.add_dependency('rails', '~> 3.0')
|
23
|
+
|
24
|
+
gem.add_development_dependency 'rspec'
|
25
|
+
gem.add_development_dependency 'rake'
|
26
|
+
gem.add_development_dependency 'rubocop'
|
24
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: narrator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Weakley
|
@@ -52,8 +52,21 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
|
56
|
-
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Straightforward and flexable activity tracking for rails.
|
57
70
|
email:
|
58
71
|
- joe.weakley@digitalaugment.com
|
59
72
|
executables: []
|
@@ -92,12 +105,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
105
|
requirements:
|
93
106
|
- - '>='
|
94
107
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
108
|
+
version: '1.9'
|
96
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
110
|
requirements:
|
98
|
-
- - '
|
111
|
+
- - '>='
|
99
112
|
- !ruby/object:Gem::Version
|
100
|
-
version:
|
113
|
+
version: '0'
|
101
114
|
requirements: []
|
102
115
|
rubyforge_project:
|
103
116
|
rubygems_version: 2.0.3
|