utracker-mongodb 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6681c9dc22f7c1e4da8144cf567f748e1bdfc61d
4
+ data.tar.gz: b2764f1eb5460c2de25dfda57d975f1be16c9ba6
5
+ SHA512:
6
+ metadata.gz: 86911d58dcb31ed8474b2ed60b7256a9e3bfc1e96b8191377a3431c559c69078fcf8449905c8366cffa1ff89cae46e48922e14ef86cea4ca60dce7f68a62286d
7
+ data.tar.gz: f20705ed020be7a890933b4a746e8d518dba3138d88b99df8f8b7563775b2460e0279d7d1144d92289639be124ddc2d2591163b21a8ba3d72049f7ad77091488
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.2.0"
4
+ branches:
5
+ only:
6
+ - master
7
+ - development
8
+ services:
9
+ - mongodb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in utracker-sqlite.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Nicolas ZERMATI
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Micro-tracker MongoDB backend
2
+
3
+ [![Build Status](https://travis-ci.org/nicoolas25/micro-tracker-mongodb.svg)](https://travis-ci.org/nicoolas25/micro-tracker-mongodb)
4
+ [![Code Climate](https://codeclimate.com/github/nicoolas25/micro-tracker-mongodb/badges/gpa.svg)](https://codeclimate.com/github/nicoolas25/micro-tracker-mongodb)
5
+ [![Test Coverage](https://codeclimate.com/github/nicoolas25/micro-tracker-mongodb/badges/coverage.svg)](https://codeclimate.com/github/nicoolas25/micro-tracker-mongodb)
6
+
7
+ This is a MongoDB backend for the [utracker][utracker] gem.
8
+
9
+ ## Installation
10
+
11
+ Add `utracker-mongodb` in your Gemfile. It will add the dependency to the
12
+ `utracker` gem itself.
13
+
14
+ ## Usage
15
+
16
+ ``` ruby
17
+ require 'utracker'
18
+ require 'utracker/mongodb'
19
+
20
+ Utracker.configure do |config|
21
+ # ...
22
+
23
+ # Set the log to the MongoDB instance at the MONGODB_URI env variable.
24
+ # If no MONGODB_URI can be found, it will look MongoDB on localhost:27017.
25
+ config[:logger] = Utracker::MongoDB::Logger.new(database_name: 'utracker')
26
+
27
+ # ...
28
+ end
29
+ ```
30
+
31
+ There is some options available when you're using the logger:
32
+
33
+ * `database_name` allow you to choose the database you want to use, default to `utracker`
34
+ * `collection_name` allow you to choose the collection you want to use, default to `entries`
35
+
36
+ [utracker]: https://github.com/nicoolas25/micro-tracker
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,34 @@
1
+ require 'mongo'
2
+
3
+ module Utracker
4
+ module MongoDB
5
+ class Logger < Utracker::Logger
6
+ attr_reader :client
7
+ attr_reader :database
8
+
9
+ def initialize(database_name: "utracker", collection_name: "entries")
10
+ @client = Mongo::MongoClient.new
11
+ @database = @client[database_name]
12
+ @collection_name = collection_name
13
+ end
14
+
15
+ protected
16
+
17
+ def write(event)
18
+ event_collection << {
19
+ datetime: event.datetime,
20
+ service: event.service,
21
+ description: event.description,
22
+ uuid: event.message.uuid,
23
+ parent_uuid: event.message.parent_uuid,
24
+ payload: event.payload,
25
+ }
26
+ end
27
+
28
+ def event_collection
29
+ @event_collection ||= database[@collection_name]
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module Utracker
2
+ module MongoDB
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Utracker
2
+ module MongoDB
3
+ autoload :Logger, 'utracker/mongodb/logger'
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
4
+ require 'utracker'
5
+ require 'utracker/mongodb'
6
+
7
+ require 'pry-byebug'
8
+ require 'timecop'
9
+
10
+ RSpec.configure do |config|
11
+ config.expect_with :rspec do |expectations|
12
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
13
+ end
14
+
15
+ config.mock_with :rspec do |mocks|
16
+ mocks.verify_partial_doubles = true
17
+ end
18
+
19
+ config.disable_monkey_patching!
20
+
21
+ config.order = :random
22
+ Kernel.srand config.seed
23
+ end
@@ -0,0 +1,80 @@
1
+ RSpec.describe Utracker::MongoDB::Logger do
2
+ let(:instance) { described_class.new(database_name: database_name,
3
+ collection_name: collection_name) }
4
+
5
+ let(:database_name) { "utracker_test" }
6
+ let(:collection_name) { "entries" }
7
+ let(:collection) { instance.database[collection_name] }
8
+
9
+ before { instance.database.drop_collection(collection_name) }
10
+
11
+ describe "#client" do
12
+ subject { instance.client }
13
+ it { is_expected.to be_a Mongo::MongoClient }
14
+ end
15
+
16
+ describe "#database" do
17
+ subject { instance.database }
18
+ it { is_expected.to be_a Mongo::DB }
19
+
20
+ describe "the name of the database" do
21
+ subject { instance.database.name }
22
+ it { is_expected.to eq database_name }
23
+ end
24
+ end
25
+
26
+ describe "#write" do
27
+ subject { instance.__send__(:write, event) }
28
+
29
+ let(:datetime) { Time.now }
30
+ let(:event) do
31
+ double({
32
+ datetime: datetime,
33
+ service: "service_name",
34
+ description: "event_name",
35
+ message: double(parent_uuid: '1', uuid: '2'),
36
+ payload: "payload",
37
+ options: {},
38
+ })
39
+ end
40
+
41
+ it "writes an entry into the collection" do
42
+ expect { subject }.to change { collection.count }.by(1)
43
+ end
44
+
45
+ describe "the entry written in the collection" do
46
+ let(:entry) { collection.find.next }
47
+ before { instance.__send__(:write, event) }
48
+
49
+ describe "the datetime field" do
50
+ subject { entry['datetime'] }
51
+ it { is_expected.to be_within(0.001).of(datetime) }
52
+ end
53
+
54
+ describe "the service field" do
55
+ subject { entry['service'] }
56
+ it { is_expected.to eq 'service_name' }
57
+ end
58
+
59
+ describe "the description field" do
60
+ subject { entry['description'] }
61
+ it { is_expected.to eq 'event_name' }
62
+ end
63
+
64
+ describe "the uuid field" do
65
+ subject { entry['uuid'] }
66
+ it { is_expected.to eq '2' }
67
+ end
68
+
69
+ describe "the parent_uuid field" do
70
+ subject { entry['parent_uuid'] }
71
+ it { is_expected.to eq '1' }
72
+ end
73
+
74
+ describe "the payload field" do
75
+ subject { entry['payload'] }
76
+ it { is_expected.to eq 'payload' }
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'utracker/mongodb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "utracker-mongodb"
8
+ spec.version = Utracker::MongoDB::VERSION
9
+ spec.authors = ["Nicolas ZERMATI"]
10
+ spec.email = ["nicoolas25@gmail.com"]
11
+ spec.summary = %q{MongoDB backend for utracker.}
12
+ spec.homepage = "http://github.com/nicoolas25/micro-tracker-mongodb"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "utracker"
21
+ spec.add_dependency "bson_ext"
22
+ spec.add_dependency "mongo"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec", "~> 3.2"
27
+ spec.add_development_dependency "pry-byebug"
28
+ spec.add_development_dependency "timecop"
29
+ spec.add_development_dependency "codeclimate-test-reporter"
30
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: utracker-mongodb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas ZERMATI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: utracker
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bson_ext
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mongo
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: timecop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: codeclimate-test-reporter
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - nicoolas25@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".ruby-version"
149
+ - ".travis.yml"
150
+ - Gemfile
151
+ - LICENSE.txt
152
+ - README.md
153
+ - Rakefile
154
+ - lib/utracker/mongodb.rb
155
+ - lib/utracker/mongodb/logger.rb
156
+ - lib/utracker/mongodb/version.rb
157
+ - spec/spec_helper.rb
158
+ - spec/utracker/mongodb/logger_spec.rb
159
+ - utracker-mongodb.gemspec
160
+ homepage: http://github.com/nicoolas25/micro-tracker-mongodb
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.2.2
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: MongoDB backend for utracker.
184
+ test_files:
185
+ - spec/spec_helper.rb
186
+ - spec/utracker/mongodb/logger_spec.rb