mongoid_activity_tracker 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +0 -6
- data/lib/mongoid_activity_tracker/tracker.rb +23 -16
- data/lib/mongoid_activity_tracker/version.rb +1 -1
- data/mongoid_activity_tracker.gemspec +4 -4
- data/test/mongoid_activity_tracker/tracker_test.rb +7 -8
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 970637cdf4055b8c9cf4374886b4bb8bd438c318
|
4
|
+
data.tar.gz: 689bfb1ab5c6e3b01a0a18cfd4cae48bf7392672
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e53650908cc0b5cbf874215fa728862603b766247f9e946af239dce40857d6a37fe3ced400ad5a7de50cbdae361dcb0d3f4c50c71d486cb866e67d6853ce1974
|
7
|
+
data.tar.gz: bec8d7f1975e21b484b3a9ed5ce0f9bf14d6a0018b26959f95dfa764fb2d67a89a718477dcfea92af9a8c321c31edfeac25be4d40f4fb9e3d69d247d2a1e115b
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -6,26 +6,30 @@ module MongoidActivityTracker
|
|
6
6
|
attr_accessor :actor_cache_methods
|
7
7
|
|
8
8
|
module ClassMethods
|
9
|
-
def track(
|
10
|
-
create({ action:
|
9
|
+
def track(actor, action, options = {})
|
10
|
+
create({ action: action, actor: actor }.merge(options))
|
11
11
|
end
|
12
12
|
|
13
13
|
# ---------------------------------------------------------------------
|
14
14
|
|
15
15
|
def tracks(relation_name, cache_methods: %i(to_s))
|
16
|
-
|
16
|
+
field_name = [relation_name, 'cache'].join('_')
|
17
|
+
accessor_name = [relation_name, 'cache_methods'].join('_')
|
18
|
+
instance_variable_name = ['@', accessor_name].join
|
19
|
+
|
20
|
+
field field_name, type: Hash, default: {}
|
17
21
|
|
18
|
-
|
22
|
+
belongs_to relation_name, polymorphic: true
|
19
23
|
|
20
|
-
attr_accessor
|
24
|
+
attr_accessor accessor_name
|
21
25
|
|
22
|
-
define_method
|
23
|
-
instance_variable_set(
|
24
|
-
instance_variable_get(
|
26
|
+
define_method accessor_name do
|
27
|
+
instance_variable_set(instance_variable_name, cache_methods) unless instance_variable_get(instance_variable_name)
|
28
|
+
instance_variable_get(instance_variable_name)
|
25
29
|
end
|
26
30
|
|
27
|
-
define_method
|
28
|
-
OpenStruct.new(send(
|
31
|
+
define_method [relation_name, 'cache_object'].join('_') do
|
32
|
+
OpenStruct.new(send(field_name))
|
29
33
|
end
|
30
34
|
|
31
35
|
before_save -> { set_cache(relation_name) }
|
@@ -56,13 +60,16 @@ module MongoidActivityTracker
|
|
56
60
|
|
57
61
|
private # =============================================================
|
58
62
|
|
59
|
-
def set_cache(
|
60
|
-
|
61
|
-
|
63
|
+
def set_cache(relation_name)
|
64
|
+
accessor_name = [relation_name, 'cache_methods'].join('_')
|
65
|
+
field_name = [relation_name, 'cache'].join('_')
|
66
|
+
|
67
|
+
return unless send(accessor_name).present?
|
68
|
+
return unless send(relation_name).present?
|
62
69
|
|
63
|
-
send(
|
64
|
-
next if send(
|
65
|
-
send(
|
70
|
+
send(accessor_name).each do |m|
|
71
|
+
next if send(field_name)[m].present?
|
72
|
+
send(field_name)[m] = send(relation_name).send(m) if send(relation_name).respond_to?(m)
|
66
73
|
end
|
67
74
|
end
|
68
75
|
end
|
@@ -18,13 +18,13 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'mongoid', '
|
21
|
+
spec.add_dependency 'mongoid', '>= 5'
|
22
22
|
|
23
|
-
spec.add_development_dependency 'bundler'
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
24
|
spec.add_development_dependency 'coveralls'
|
25
|
-
spec.add_development_dependency 'database_cleaner'
|
25
|
+
spec.add_development_dependency 'database_cleaner'
|
26
26
|
spec.add_development_dependency 'guard'
|
27
27
|
spec.add_development_dependency 'guard-minitest'
|
28
28
|
spec.add_development_dependency 'minitest'
|
29
|
-
spec.add_development_dependency 'rake'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
30
|
end
|
@@ -25,23 +25,22 @@ module MongoidActivityTracker
|
|
25
25
|
# ---------------------------------------------------------------------
|
26
26
|
|
27
27
|
describe '.track' do
|
28
|
-
|
29
|
-
|
30
|
-
end
|
28
|
+
let(:result) { TestTracker.track(actor, :create, subject: sub) }
|
29
|
+
|
31
30
|
it 'returns new object' do
|
32
|
-
|
31
|
+
result.must_be_kind_of TestTracker
|
33
32
|
end
|
34
33
|
it 'always sets the :actor' do
|
35
|
-
|
34
|
+
result.actor.must_equal actor
|
36
35
|
end
|
37
36
|
it 'sets the :actor_cache with :to_s by default' do
|
38
|
-
|
37
|
+
result.actor_cache.must_equal(to_s: actor.to_s)
|
39
38
|
end
|
40
39
|
it 'sets the :action' do
|
41
|
-
|
40
|
+
result.action.must_equal :create
|
42
41
|
end
|
43
42
|
it 'sets any other attributes' do
|
44
|
-
|
43
|
+
result.subject.must_equal sub
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_activity_tracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Celizna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: coveralls
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: guard
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,16 +112,16 @@ dependencies:
|
|
112
112
|
name: rake
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
117
|
+
version: '10.0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
124
|
+
version: '10.0'
|
125
125
|
description: Minimal set of classes and modules to help with activity tracking.
|
126
126
|
email:
|
127
127
|
- tomas.celizna@gmail.com
|
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
162
|
version: '0'
|
163
163
|
requirements: []
|
164
164
|
rubyforge_project:
|
165
|
-
rubygems_version: 2.4.
|
165
|
+
rubygems_version: 2.4.5.1
|
166
166
|
signing_key:
|
167
167
|
specification_version: 4
|
168
168
|
summary: Minimal set of classes and modules to help with activity tracking.
|