mongoid-clerk 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.
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3 --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mongoid-clerk.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mongoid-clerk (0.0.1)
5
+ activesupport
6
+ bson_ext
7
+ foreman
8
+ mongoid
9
+ mongoid-rspec
10
+ rake
11
+ rspec
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ activemodel (3.2.7)
17
+ activesupport (= 3.2.7)
18
+ builder (~> 3.0.0)
19
+ activesupport (3.2.7)
20
+ i18n (~> 0.6)
21
+ multi_json (~> 1.0)
22
+ bson (1.6.4)
23
+ bson_ext (1.6.4)
24
+ bson (~> 1.6.4)
25
+ builder (3.0.0)
26
+ diff-lcs (1.1.3)
27
+ foreman (0.53.0)
28
+ thor (>= 0.13.6)
29
+ i18n (0.6.0)
30
+ mongo (1.6.2)
31
+ bson (~> 1.6.2)
32
+ mongoid (2.4.11)
33
+ activemodel (~> 3.1)
34
+ mongo (<= 1.6.2)
35
+ tzinfo (~> 0.3.22)
36
+ mongoid-rspec (1.4.5)
37
+ mongoid (>= 2.4.6)
38
+ rake
39
+ rspec (>= 2.9)
40
+ multi_json (1.3.6)
41
+ rake (0.9.2.2)
42
+ rspec (2.11.0)
43
+ rspec-core (~> 2.11.0)
44
+ rspec-expectations (~> 2.11.0)
45
+ rspec-mocks (~> 2.11.0)
46
+ rspec-core (2.11.1)
47
+ rspec-expectations (2.11.2)
48
+ diff-lcs (~> 1.1.3)
49
+ rspec-mocks (2.11.1)
50
+ thor (0.15.4)
51
+ tzinfo (0.3.33)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ mongoid-clerk!
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 80beans
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Procfile ADDED
@@ -0,0 +1 @@
1
+ MongoDB: mongod run --config /usr/local/etc/mongod.conf
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Mongoid::Clerk
2
+
3
+ [![Build Status](https://secure.travis-ci.org/80beans/mongoid-clerk.png?branch=master)](http://travis-ci.org/80beans/mongoid-clerk)
4
+
5
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/80beans/mongoid-clerk)
6
+
7
+ A simple logger for Mongoid.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'mongoid-clerk'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mongoid-clerk
22
+
23
+ ## Usage
24
+
25
+ Include `Clerk::Logger` in your model, then log anything with `log()`. The first argument is the message and the second the level.
26
+
27
+ You can add default fields to your log entry by adding `clerk_always_include` this method accepts an array of fields it should include, or a hash if you want to rename a field.
28
+
29
+ Clerk adds a polymorphic relation to the model `log_items` so you can scope log entries on this model.
30
+
31
+ `Clerk::Log` behaves like a regular mongoid model for easy access to your log entries.
32
+
33
+ example model:
34
+
35
+ class User
36
+ include Clerk::Logger
37
+
38
+ field :name
39
+ field :address
40
+
41
+ clerk_always_include :name, :address => :place
42
+
43
+ def something
44
+ log('Something went wrong!', :error)
45
+ end
46
+
47
+ end
48
+
49
+
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require 'rake'
3
+ require 'rspec'
4
+
5
+ require "bundler/gem_tasks"
6
+ require File.expand_path('../spec/spec_helper', __FILE__)
7
+
8
+ task :default do
9
+ system 'bundle exec rspec spec'
10
+ end
data/lib/clerk/log.rb ADDED
@@ -0,0 +1,10 @@
1
+ class Clerk::Log
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+
5
+ field :message
6
+ field :level, :type => Symbol
7
+
8
+ belongs_to :logable, :polymorphic => true
9
+
10
+ end
@@ -0,0 +1,54 @@
1
+ module Clerk::Logger
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+
6
+ def default_fields
7
+ @default_fields ||= {}
8
+ end
9
+
10
+ def clerk_always_include(*new_default_fields)
11
+ new_default_fields.each do |default_field|
12
+ default_field = { default_field => default_field } unless default_field.is_a?(Hash)
13
+ Clerk::Log.send(:field, default_field.values.first)
14
+ default_fields.merge!(default_field)
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ def log(msg, level = :info)
21
+ Clerk::Log.create!(
22
+ included_fields.merge(
23
+ :message => msg,
24
+ :level => level
25
+ )
26
+ )
27
+ end
28
+
29
+ def included_fields
30
+ {}.tap do |return_hash|
31
+ self.class.default_fields.each do |source_field, target_field|
32
+ return_hash[target_field.to_sym] = read_attribute(source_field.to_sym)
33
+ end
34
+ end
35
+ end
36
+
37
+ included do
38
+ has_many :log_items, :as => :logable
39
+ end
40
+ end
41
+
42
+ #### usage
43
+ #
44
+ # class InputStream
45
+ # include Clerk::Logger
46
+ #
47
+ # clerk_always_include :id => :input_stream_id, :company_id
48
+ #
49
+ # def something
50
+ # log('Something went wrong!', :error)
51
+ # end
52
+ #
53
+ # end
54
+ #
@@ -0,0 +1,3 @@
1
+ module Clerk
2
+ VERSION = "0.0.1"
3
+ end
data/lib/clerk.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "clerk/version"
2
+
3
+ module Clerk
4
+ end
5
+
6
+ require 'clerk/log'
7
+ require 'clerk/logger'
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/clerk/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Robert Beekman"]
6
+ gem.email = ["robert@80beans.com"]
7
+ gem.description = %q{A simple logger for mongoid}
8
+ gem.summary = %q{A simple logger for mongoid}
9
+ gem.homepage = "http://github.com/80beans/mongoid-clerk"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "mongoid-clerk"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Clerk::VERSION
17
+
18
+ gem.add_dependency 'mongoid'
19
+ gem.add_dependency 'bson_ext'
20
+ gem.add_dependency 'rspec'
21
+ gem.add_dependency 'mongoid-rspec'
22
+ gem.add_dependency 'activesupport'
23
+ gem.add_dependency 'rake'
24
+ gem.add_dependency 'foreman'
25
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Clerk::Log do
4
+
5
+ it { should be_timestamped_document }
6
+
7
+ it { should have_field(:message) }
8
+ it { should have_field(:level).of_type(Symbol) }
9
+
10
+ it { should belong_to :logable }
11
+
12
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ class MongoidDocumentWithClerk
4
+ include Mongoid::Document
5
+ include Clerk::Logger
6
+
7
+ field :name
8
+ field :address
9
+
10
+ clerk_always_include :name, :address => :place
11
+
12
+ end
13
+
14
+ describe MongoidDocumentWithClerk do
15
+
16
+ context "class methods" do
17
+ subject { MongoidDocumentWithClerk }
18
+
19
+ it { should respond_to :default_fields }
20
+ it { should respond_to :clerk_always_include }
21
+ end
22
+
23
+ context "instance methods" do
24
+ subject { MongoidDocumentWithClerk.new }
25
+
26
+ it { should respond_to :log }
27
+ it { should respond_to :included_fields }
28
+ it { should have_many :log_items }
29
+ end
30
+
31
+ describe ".clerk_always_include" do
32
+
33
+ describe "dynamic Clerk::Log fields" do
34
+ subject { Clerk::Log }
35
+
36
+ it { should have_field :name }
37
+ it { should have_field :place }
38
+ end
39
+
40
+ describe "default fields" do
41
+ subject { MongoidDocumentWithClerk.default_fields }
42
+
43
+ it "should contain the field mapping" do
44
+ should == {:name => :name, :address => :place}
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+ describe "#included_fields" do
52
+ let(:document_with_clerk) { MongoidDocumentWithClerk.new(:name => 'James Bond', :address => 'Secret') }
53
+ subject { document_with_clerk.included_fields }
54
+
55
+ it { should == {:name => 'James Bond', :place => 'Secret'} }
56
+ end
57
+
58
+ describe "#log" do
59
+ let(:document_with_clerk) { MongoidDocumentWithClerk.new(:name => 'James Bond', :address => 'Secret') }
60
+
61
+ context "with default values" do
62
+
63
+ it "should call Clerk::Log with the correct params" do
64
+ Clerk::Log.should_receive(:create!).with(
65
+ :name => 'James Bond',
66
+ :place => 'Secret',
67
+ :message => 'bananas',
68
+ :level => :info
69
+ )
70
+ end
71
+
72
+ after { document_with_clerk.log('bananas') }
73
+ end
74
+
75
+ context "with overriden status level" do
76
+
77
+ it "should call Clerk::Log with the correct params" do
78
+ Clerk::Log.should_receive(:create!).with(
79
+ :name => 'James Bond',
80
+ :place => 'Secret',
81
+ :message => 'bananas',
82
+ :level => :error
83
+ )
84
+ end
85
+
86
+ after { document_with_clerk.log('bananas', :error) }
87
+ end
88
+
89
+ end
90
+
91
+ end
data/spec/mongoid.yml ADDED
@@ -0,0 +1,4 @@
1
+ test:
2
+ host: 127.0.0.1
3
+ port: 27017
4
+ database: mongoid_clerk_test
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+
6
+ require 'active_support/all'
7
+ require 'mongoid'
8
+ require 'mongo'
9
+ require 'uri'
10
+ require 'mongoid-rspec'
11
+
12
+ mongoid_config = YAML.load_file(File.join(File.dirname(__FILE__),"mongoid.yml"))['test']
13
+ Mongoid.configure do |config|
14
+ if !mongoid_config['uri'].blank?
15
+ config.master = Mongo::Connection.from_uri(mongoid_config['uri']).db(mongoid_config['uri'].split('/').last)
16
+ else
17
+ config.master = Mongo::Connection.new(mongoid_config['host'], mongoid_config['port']).db(mongoid_config['database'])
18
+ end
19
+ end
20
+
21
+
22
+ RSpec.configure do |config|
23
+ config.mock_with :rspec
24
+ config.include Mongoid::Matchers
25
+
26
+ config.after :suite do
27
+ Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
28
+ end
29
+ end
30
+
31
+ require 'clerk'
data/travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm: 1.9.3
2
+
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid-clerk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Robert Beekman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mongoid
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bson_ext
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: mongoid-rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: activesupport
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: foreman
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: A simple logger for mongoid
127
+ email:
128
+ - robert@80beans.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - !binary |-
134
+ LmdpdGlnbm9yZQ==
135
+ - !binary |-
136
+ LnJzcGVj
137
+ - !binary |-
138
+ LnJ2bXJj
139
+ - !binary |-
140
+ R2VtZmlsZQ==
141
+ - !binary |-
142
+ R2VtZmlsZS5sb2Nr
143
+ - !binary |-
144
+ TElDRU5TRQ==
145
+ - !binary |-
146
+ UHJvY2ZpbGU=
147
+ - !binary |-
148
+ UkVBRE1FLm1k
149
+ - !binary |-
150
+ UmFrZWZpbGU=
151
+ - !binary |-
152
+ bGliL2NsZXJrLnJi
153
+ - !binary |-
154
+ bGliL2NsZXJrL2xvZy5yYg==
155
+ - !binary |-
156
+ bGliL2NsZXJrL2xvZ2dlci5yYg==
157
+ - !binary |-
158
+ bGliL2NsZXJrL3ZlcnNpb24ucmI=
159
+ - !binary |-
160
+ bW9uZ29pZC1jbGVyay5nZW1zcGVj
161
+ - !binary |-
162
+ c3BlYy9tb25nb2lkLWNsZXJrL2xvZ19zcGVjLnJi
163
+ - !binary |-
164
+ c3BlYy9tb25nb2lkLWNsZXJrL2xvZ2dlcl9zcGVjLnJi
165
+ - !binary |-
166
+ c3BlYy9tb25nb2lkLnltbA==
167
+ - !binary |-
168
+ c3BlYy9zcGVjX2hlbHBlci5yYg==
169
+ - !binary |-
170
+ dHJhdmlzLnltbA==
171
+ homepage: http://github.com/80beans/mongoid-clerk
172
+ licenses: []
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ none: false
179
+ requirements:
180
+ - - ! '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ none: false
185
+ requirements:
186
+ - - ! '>='
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ requirements: []
190
+ rubyforge_project:
191
+ rubygems_version: 1.8.24
192
+ signing_key:
193
+ specification_version: 3
194
+ summary: A simple logger for mongoid
195
+ test_files:
196
+ - !binary |-
197
+ c3BlYy9tb25nb2lkLWNsZXJrL2xvZ19zcGVjLnJi
198
+ - !binary |-
199
+ c3BlYy9tb25nb2lkLWNsZXJrL2xvZ2dlcl9zcGVjLnJi
200
+ - !binary |-
201
+ c3BlYy9tb25nb2lkLnltbA==
202
+ - !binary |-
203
+ c3BlYy9zcGVjX2hlbHBlci5yYg==