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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32a49fc10d42c73338ecf6b28d773809f33837d7
4
- data.tar.gz: 022617ffb00f8062efd009fbfccc125db2ea7d13
3
+ metadata.gz: 970637cdf4055b8c9cf4374886b4bb8bd438c318
4
+ data.tar.gz: 689bfb1ab5c6e3b01a0a18cfd4cae48bf7392672
5
5
  SHA512:
6
- metadata.gz: bf49dd625363086dc207b5a4173d710837f3f4065755151d119f2e2d1e6ba77da569af03378d761851d9aba4f72e29203688e29418010005158747a953b9a581
7
- data.tar.gz: f341051bd51fd9c22286d622332f870434cad04b4f1077ca89b7d749689b523073126f27dfd12b5832b8ab3f638bc94659423df217df616f07296c1505bdde7a
6
+ metadata.gz: e53650908cc0b5cbf874215fa728862603b766247f9e946af239dce40857d6a37fe3ced400ad5a7de50cbdae361dcb0d3f4c50c71d486cb866e67d6853ce1974
7
+ data.tar.gz: bec8d7f1975e21b484b3a9ed5ce0f9bf14d6a0018b26959f95dfa764fb2d67a89a718477dcfea92af9a8c321c31edfeac25be4d40f4fb9e3d69d247d2a1e115b
@@ -3,7 +3,7 @@ cache: bundler
3
3
  script: 'bundle exec rake'
4
4
  sudo: false
5
5
  rvm:
6
- - 2.2.2
6
+ - 2.2.5
7
7
  services:
8
8
  - mongodb
9
9
 
data/Gemfile CHANGED
@@ -1,9 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in mongoid_permalink_extension.gemspec
4
3
  gemspec
5
-
6
- # TEMP
7
- group :test do
8
- gem 'database_cleaner', git: 'https://github.com/DatabaseCleaner/database_cleaner.git'
9
- end
@@ -6,26 +6,30 @@ module MongoidActivityTracker
6
6
  attr_accessor :actor_cache_methods
7
7
 
8
8
  module ClassMethods
9
- def track(_actor, _action, options = {})
10
- create({ action: _action, actor: _actor }.merge(options))
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
- belongs_to relation_name, polymorphic: true
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
- field "#{relation_name}_cache", type: Hash, default: {}
22
+ belongs_to relation_name, polymorphic: true
19
23
 
20
- attr_accessor "#{relation_name}_cache_methods"
24
+ attr_accessor accessor_name
21
25
 
22
- define_method "#{relation_name}_cache_methods" do
23
- instance_variable_set("@#{relation_name}_cache_methods", cache_methods) unless instance_variable_get("@#{relation_name}_cache_methods")
24
- instance_variable_get("@#{relation_name}_cache_methods")
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 "#{relation_name}_cache_object" do
28
- OpenStruct.new(send("#{relation_name}_cache"))
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(name)
60
- return unless send("#{name}_cache_methods").present?
61
- return unless send(name).present?
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("#{name}_cache_methods").each do |m|
64
- next if send("#{name}_cache")[m].present?
65
- send("#{name}_cache")[m] = send(name).send(m) if send(name).respond_to?(m)
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
@@ -1,3 +1,3 @@
1
1
  module MongoidActivityTracker
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  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', '~> 5'
21
+ spec.add_dependency 'mongoid', '>= 5'
22
22
 
23
- spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'bundler'
24
24
  spec.add_development_dependency 'coveralls'
25
- spec.add_development_dependency 'database_cleaner', '>= 1.5.1'
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
- before do
29
- @result = TestTracker.track(actor, :create, subject: sub)
30
- end
28
+ let(:result) { TestTracker.track(actor, :create, subject: sub) }
29
+
31
30
  it 'returns new object' do
32
- @result.must_be_kind_of TestTracker
31
+ result.must_be_kind_of TestTracker
33
32
  end
34
33
  it 'always sets the :actor' do
35
- @result.actor.must_equal actor
34
+ result.actor.must_equal actor
36
35
  end
37
36
  it 'sets the :actor_cache with :to_s by default' do
38
- @result.actor_cache.must_equal(to_s: actor.to_s)
37
+ result.actor_cache.must_equal(to_s: actor.to_s)
39
38
  end
40
39
  it 'sets the :action' do
41
- @result.action.must_equal :create
40
+ result.action.must_equal :create
42
41
  end
43
42
  it 'sets any other attributes' do
44
- @result.subject.must_equal sub
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.1
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-03-27 00:00:00.000000000 Z
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: '1.3'
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: '1.3'
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: 1.5.1
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: 1.5.1
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.8
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.