mongoid_activity_tracker 0.2.0 → 0.2.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 +3 -2
- data/lib/mongoid_activity_tracker.rb +1 -2
- data/lib/mongoid_activity_tracker/tracker.rb +12 -18
- data/lib/mongoid_activity_tracker/version.rb +1 -1
- data/mongoid_activity_tracker.gemspec +17 -17
- data/test/mongoid_activity_tracker/tracker_test.rb +5 -7
- data/test/test_helper.rb +4 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32a49fc10d42c73338ecf6b28d773809f33837d7
|
4
|
+
data.tar.gz: 022617ffb00f8062efd009fbfccc125db2ea7d13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf49dd625363086dc207b5a4173d710837f3f4065755151d119f2e2d1e6ba77da569af03378d761851d9aba4f72e29203688e29418010005158747a953b9a581
|
7
|
+
data.tar.gz: f341051bd51fd9c22286d622332f870434cad04b4f1077ca89b7d749689b523073126f27dfd12b5832b8ab3f638bc94659423df217df616f07296c1505bdde7a
|
data/.travis.yml
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
3
|
script: 'bundle exec rake'
|
4
|
+
sudo: false
|
4
5
|
rvm:
|
5
|
-
- 2.
|
6
|
+
- 2.2.2
|
6
7
|
services:
|
7
8
|
- mongodb
|
8
9
|
|
@@ -11,4 +12,4 @@ notifications:
|
|
11
12
|
recipients:
|
12
13
|
- tomas.celizna@gmail.com
|
13
14
|
on_failure: change
|
14
|
-
on_success: never
|
15
|
+
on_success: never
|
@@ -3,20 +3,16 @@ require 'ostruct'
|
|
3
3
|
|
4
4
|
module MongoidActivityTracker
|
5
5
|
module Tracker
|
6
|
-
|
7
6
|
attr_accessor :actor_cache_methods
|
8
7
|
|
9
8
|
module ClassMethods
|
10
|
-
|
11
|
-
|
12
|
-
self.create(
|
13
|
-
{ action: _action, actor: _actor }.merge(options)
|
14
|
-
)
|
9
|
+
def track(_actor, _action, options = {})
|
10
|
+
create({ action: _action, actor: _actor }.merge(options))
|
15
11
|
end
|
16
12
|
|
17
13
|
# ---------------------------------------------------------------------
|
18
|
-
|
19
|
-
def tracks
|
14
|
+
|
15
|
+
def tracks(relation_name, cache_methods: %i(to_s))
|
20
16
|
belongs_to relation_name, polymorphic: true
|
21
17
|
|
22
18
|
field "#{relation_name}_cache", type: Hash, default: {}
|
@@ -38,7 +34,7 @@ module MongoidActivityTracker
|
|
38
34
|
|
39
35
|
# ---------------------------------------------------------------------
|
40
36
|
|
41
|
-
def self.included
|
37
|
+
def self.included(base)
|
42
38
|
base.extend ClassMethods
|
43
39
|
base.class_eval do
|
44
40
|
include Mongoid::Document
|
@@ -50,26 +46,24 @@ module MongoidActivityTracker
|
|
50
46
|
validates :actor, presence: true
|
51
47
|
validates :action, presence: true
|
52
48
|
end
|
53
|
-
|
54
49
|
end
|
55
50
|
|
56
51
|
# =====================================================================
|
57
52
|
|
58
53
|
def created_at
|
59
|
-
|
54
|
+
id.generation_time.in_time_zone(Time.zone)
|
60
55
|
end
|
61
56
|
|
62
57
|
private # =============================================================
|
63
58
|
|
64
|
-
def set_cache
|
65
|
-
return unless
|
66
|
-
return unless
|
59
|
+
def set_cache(name)
|
60
|
+
return unless send("#{name}_cache_methods").present?
|
61
|
+
return unless send(name).present?
|
67
62
|
|
68
|
-
|
69
|
-
next if
|
70
|
-
|
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)
|
71
66
|
end
|
72
67
|
end
|
73
|
-
|
74
68
|
end
|
75
69
|
end
|
@@ -4,27 +4,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'mongoid_activity_tracker/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'mongoid_activity_tracker'
|
8
8
|
spec.version = MongoidActivityTracker::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
9
|
+
spec.authors = ['Tomas Celizna']
|
10
|
+
spec.email = ['tomas.celizna@gmail.com']
|
11
|
+
spec.description = 'Minimal set of classes and modules to help with activity tracking.'
|
12
|
+
spec.summary = 'Minimal set of classes and modules to help with activity tracking.'
|
13
|
+
spec.homepage = 'https://github.com/tomasc/mongoid_activity_tracker'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
|
-
spec.files = `git ls-files`.split(
|
16
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency
|
21
|
+
spec.add_dependency 'mongoid', '~> 5'
|
22
22
|
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
spec.add_development_dependency 'coveralls'
|
25
|
+
spec.add_development_dependency 'database_cleaner', '>= 1.5.1'
|
26
|
+
spec.add_development_dependency 'guard'
|
27
|
+
spec.add_development_dependency 'guard-minitest'
|
28
|
+
spec.add_development_dependency 'minitest'
|
29
|
+
spec.add_development_dependency 'rake'
|
30
30
|
end
|
@@ -2,7 +2,6 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module MongoidActivityTracker
|
4
4
|
describe Tracker do
|
5
|
-
|
6
5
|
let(:actor) { TestActor.new }
|
7
6
|
let(:sub) { TestSubject.new }
|
8
7
|
subject { TestTracker.new }
|
@@ -24,7 +23,7 @@ module MongoidActivityTracker
|
|
24
23
|
end
|
25
24
|
|
26
25
|
# ---------------------------------------------------------------------
|
27
|
-
|
26
|
+
|
28
27
|
describe '.track' do
|
29
28
|
before do
|
30
29
|
@result = TestTracker.track(actor, :create, subject: sub)
|
@@ -36,7 +35,7 @@ module MongoidActivityTracker
|
|
36
35
|
@result.actor.must_equal actor
|
37
36
|
end
|
38
37
|
it 'sets the :actor_cache with :to_s by default' do
|
39
|
-
@result.actor_cache.must_equal(
|
38
|
+
@result.actor_cache.must_equal(to_s: actor.to_s)
|
40
39
|
end
|
41
40
|
it 'sets the :action' do
|
42
41
|
@result.action.must_equal :create
|
@@ -72,9 +71,9 @@ module MongoidActivityTracker
|
|
72
71
|
subject.subject_cache.fetch(:to_s).must_equal test_subject.to_s
|
73
72
|
end
|
74
73
|
end
|
75
|
-
|
74
|
+
|
76
75
|
# ---------------------------------------------------------------------
|
77
|
-
|
76
|
+
|
78
77
|
describe ':created_at' do
|
79
78
|
it 'infers time from BSON id' do
|
80
79
|
subject.must_respond_to :created_at
|
@@ -110,6 +109,5 @@ module MongoidActivityTracker
|
|
110
109
|
subject.actor_cache_object.must_respond_to :to_s
|
111
110
|
end
|
112
111
|
end
|
113
|
-
|
114
112
|
end
|
115
|
-
end
|
113
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -7,11 +7,13 @@ require 'minitest/spec'
|
|
7
7
|
require 'mongoid'
|
8
8
|
require 'mongoid_activity_tracker'
|
9
9
|
|
10
|
-
if ENV[
|
11
|
-
require
|
10
|
+
if ENV['CI']
|
11
|
+
require 'coveralls'
|
12
12
|
Coveralls.wear!
|
13
13
|
end
|
14
14
|
|
15
|
+
Mongoid.logger.level = Logger::INFO
|
16
|
+
Mongo::Logger.logger.level = Logger::INFO
|
15
17
|
Mongoid.configure do |config|
|
16
18
|
config.connect_to('mongoid_activity_tracker_test')
|
17
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Celizna
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '5
|
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
|
-
version: '5
|
26
|
+
version: '5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|