redcrumbs 0.1.0 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/app/models/redcrumbs/crumb.rb +14 -9
- data/lib/redcrumbs/creation.rb +3 -4
- data/lib/redcrumbs/options.rb +2 -2
- data/lib/redcrumbs/users.rb +1 -1
- data/lib/redcrumbs/version.rb +1 -1
- metadata +6 -6
data/README.md
CHANGED
@@ -86,7 +86,7 @@ Not too shabby. But crumbs can also track the user that made the change (creator
|
|
86
86
|
=> #<User id: 2, name: "Jon" ... >
|
87
87
|
|
88
88
|
# and really cool, returns a limited (default 100) array of crumbs affecting a user in reverse order:
|
89
|
-
> user.
|
89
|
+
> user.crumbs_as_user(:limit => 20)
|
90
90
|
=> [#<Crumb id: 64 ... >, #<Crumb id: 53 ... >, #<Crumb id: 42 ... > ... ]
|
91
91
|
|
92
92
|
# or if you just want the crumbs created by the user
|
@@ -18,19 +18,19 @@ module Redcrumbs
|
|
18
18
|
DataMapper.setup(:default, {:adapter => "redis"})
|
19
19
|
|
20
20
|
property :id, Serial
|
21
|
-
property :subject_id, Integer, :index => true
|
22
|
-
property :subject_type, String, :index => true
|
23
|
-
property :modifications, Json, :default => "{}"
|
21
|
+
property :subject_id, Integer, :index => true, :lazy => false
|
22
|
+
property :subject_type, String, :index => true, :lazy => false
|
23
|
+
property :modifications, Json, :default => "{}", :lazy => false
|
24
24
|
property :created_at, DateTime
|
25
25
|
property :updated_at, DateTime
|
26
|
-
property :stored_creator, Json
|
27
|
-
property :stored_target, Json
|
28
|
-
property :stored_subject, Json
|
26
|
+
property :stored_creator, Json, :lazy => false
|
27
|
+
property :stored_target, Json, :lazy => false
|
28
|
+
property :stored_subject, Json, :lazy => false
|
29
29
|
property :creator_id, Integer, :index => true
|
30
30
|
property :target_id, Integer, :index => true
|
31
31
|
|
32
32
|
DataMapper.finalize
|
33
|
-
|
33
|
+
|
34
34
|
after :save, :set_mortality
|
35
35
|
|
36
36
|
attr_accessor :_subject, :_creator, :_target
|
@@ -43,8 +43,7 @@ module Redcrumbs
|
|
43
43
|
self.modifications = params[:modifications] unless !params[:modifications]
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
|
-
def self.build_from(subject)
|
46
|
+
def self.build_with_modifications(subject)
|
48
47
|
unless subject.watched_changes.empty?
|
49
48
|
params = {:modifications => subject.watched_changes}
|
50
49
|
params.merge!({:subject => subject})
|
@@ -52,6 +51,12 @@ module Redcrumbs
|
|
52
51
|
end
|
53
52
|
end
|
54
53
|
|
54
|
+
def set_context_from(subject)
|
55
|
+
self.subject = subject unless !!subject_id
|
56
|
+
self.target ||= self.subject.target if self.subject.respond_to?(:target)
|
57
|
+
self.creator ||= self.subject.creator if self.subject.respond_to?(:creator)
|
58
|
+
end
|
59
|
+
|
55
60
|
def redis_key
|
56
61
|
"redcrumbs_crumbs:#{id}"
|
57
62
|
end
|
data/lib/redcrumbs/creation.rb
CHANGED
@@ -20,11 +20,10 @@ module Redcrumbs
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def notify_changes
|
23
|
-
unless watched_changes.empty?
|
24
|
-
n = Crumb.build_from(self)
|
25
|
-
n.save
|
26
|
-
end
|
23
|
+
n = Crumb.build_with_modifications(self) unless watched_changes.empty?
|
27
24
|
yield
|
25
|
+
n.set_context_from(self) unless !n
|
26
|
+
n.save unless !n
|
28
27
|
end
|
29
28
|
end
|
30
29
|
end
|
data/lib/redcrumbs/options.rb
CHANGED
@@ -16,8 +16,8 @@ module Redcrumbs
|
|
16
16
|
options[:only] = Array(options[:only])
|
17
17
|
options[:store] = Array(options[:store])
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
class_attribute :redcrumbs_options
|
20
|
+
class_attribute :redcrumbs_callback_options
|
21
21
|
|
22
22
|
self.redcrumbs_options = options.dup
|
23
23
|
self.redcrumbs_callback_options = options.dup.select {|k,v| [:if, :unless].include?(k.to_sym)}
|
data/lib/redcrumbs/users.rb
CHANGED
data/lib/redcrumbs/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redcrumbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-31 00:00:00.000000000 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: data_mapper
|
17
|
-
requirement: &
|
17
|
+
requirement: &2157900720 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 1.2.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2157900720
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: dm-redis-adapter
|
28
|
-
requirement: &
|
28
|
+
requirement: &2157900220 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: 0.6.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2157900220
|
37
37
|
description: Fast and unobtrusive activity tracking of ActiveRecord models using DataMapper
|
38
38
|
and Redis
|
39
39
|
email:
|