mongoid_userstamp 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODA4YmMxOWYzZTRjMTQ3MzhjYTcwYjEyNTE3YjJkMzZmZjQzOGM4MQ==
4
+ ODZhMzk0MmJlYTI2NDZiMzFkZDM4N2JkNzZkOTU4ZGNlMTVmMDFlZg==
5
5
  data.tar.gz: !binary |-
6
- MTIwZTFlMTM3YjEzODA0ZWUwMzliYzYwMWI1ODVmN2ZkZWJhZDFkNw==
6
+ NzNiZjUxYzc3ZWNkNTc4ZDQyOGNkNTE3NmEwOGYzOGU4M2QxYWE1NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmZiN2E0ODk1YWRhMWM5ODkzMzljOWM2NzVkZmVkOGFiM2UzNzcxYTA1YTBi
10
- MzBlMmFlZWUyMGQ1NDhkNjY1YTdkMjUyZThjNjc4NTA2YzJlMGM1ZDZlODEy
11
- MWFkOGEyMTYyM2Q4NDJiMmY3ZTllZWM5MTJlMjlhOWEyN2ZmMmY=
9
+ NDRiMDkzOGNmYTJhY2Y4ZjljYTRiNmJmODM1Mjg2ZjliYzc2ODJhMzgwMzE2
10
+ MmNiM2I5NTkzZWVjNzlhYmIxOTVjZDFmMTkzY2E5ZGI4YjMwNDNmZDJkOGE2
11
+ YWQ0MzY5NDAyM2E0MTdlYjI1YzA1Y2I5MWExMmRhMzVmZTFhZDg=
12
12
  data.tar.gz: !binary |-
13
- ZDdlMmYyZWI2ZjA0MDA0ZTg0NmJjYTVhOTY2MWJkN2I4ZWVkMzdlZTIwZTM0
14
- YzcyZDRjNDYxNmU4NzUyNjdjZGZiMWE2MWVhMDYzYmQ1NjdmNDRhZGYyZjY1
15
- ZGZjOGUxOGY3YTIyMWE5ZDkzNTFlNzU4YmVmM2JmZjUwYjk1Mjc=
13
+ OWNhNGYyMzY1NTc3NzI3ZWMwZjFhZjZlOTdkYjQwOTQxYTQxMzE1MzczY2Yy
14
+ OWJiZDA4MjBmMTI0NzdjMmIzZmZkZDViN2M2NjgyY2RlMTk5NjM5MGVkZmRj
15
+ MDQzODg4ODQxMDZiY2UyNTU0OGU5ODVhMDFlY2ZhN2RmZDQwOWE=
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .DS_Store
2
+
3
+ /.idea
4
+ /.yardoc
5
+ /.bundle
6
+
7
+ /pkg
8
+ /doc
9
+
10
+ /.ruby-version
11
+ /.rbenv-version
12
+ /*.gem
13
+ /Gemfile.lock
data/.travis.yml CHANGED
@@ -1,8 +1,20 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0
4
- - 1.9.3
5
- - jruby-19mode
6
- - rbx-19mode
7
-
8
- services: mongodb
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - ruby-head
7
+ - jruby
8
+ - jruby-19mode
9
+ - rbx
10
+ - rbx-19mode
11
+
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: ruby-head
15
+ - rvm: jruby
16
+ - rvm: jruby-19mode
17
+ - rvm: rbx
18
+ - rvm: rbx-19mode
19
+
20
+ services: mongodb
data/CHANGELOG.md CHANGED
@@ -1,26 +1,41 @@
1
- # Changelog
2
-
3
- ## [0.3.0](https://github.com/tbpro/mongoid_userstamp/releases/tag/v0.3.0) - 2013-10-02
4
-
5
- * Improvement
6
- * BREAKING: Default value for `updated_accessor` was `:updator`, is now `:updater` (@johnnyshields)
7
- * DEPRECATION: `#configure` is now an alias for `#config` and is deprecated (@johnnyshields)
8
- * Replace `Mongoid::Userstamp.configuration` and `Mongoid::Userstamp.configure` with `#config` (@johnnyshields)
9
- * Replace usages of `id` with `_id`, since there are many gems which override the behavior of `id` (@johnnyshields)
10
- * Do not overwrite creator if it has already been set manually (@johnnyshields)
11
- * Define setter methods for updated_accessor/created_accessor which assign the user id. Accepts both `Mongoid::Document` and `BSON::ObjectID` types (@johnnyshields)
12
- * Allow pass-in of Mongoid field options for updated_column/created_column. Useful to set field aliases, default value, etc. (@johnnyshields)
13
- * Expose current_user as `Mongoid::Userstamp.current_user` (@johnnyshields)
14
- * Field type is now `::Moped::BSON::ObjectID` instead of Object (@johnnyshields)
15
- * Query for creator/updater user using `unscoped` (@johnnyshields)
16
- * Improve code readability (@johnnyshields)
17
- * Improve test coverage, including adding tests for config (@johnnyshields)
18
-
19
- * Bugfix
20
- * Catch error if creator/updater has been deleted and return nil (@johnnyshields)
21
-
22
- ## [0.2.1](https://github.com/tbpro/mongoid_userstamp/releases/tag/v0.2.1) - 2013-03-24
23
-
24
- * Improvement
25
- * Added some specs for test coverage (@johnnyshields)
26
- * Removed dependecy for `Mongoid::Timestamps` (@johnnyshields)
1
+ # Changelog
2
+
3
+ ## [0.3.2](https://github.com/tbpro/mongoid_userstamp/releases/tag/v0.3.2) - 2014-01-12
4
+
5
+ * Fix bad gem release
6
+
7
+ ## [0.3.1](https://github.com/tbpro/mongoid_userstamp/releases/tag/v0.3.1) - 2014-01-11
8
+
9
+ * Improvement
10
+ * Remove autoload and replace with require in gem root lib file
11
+ * Add log warning for `#configure` deprecation
12
+
13
+ * Admin
14
+ * Remove Jeweler dependency, replace with gem-release gem
15
+ * Add Gemfile.lock to .gitignore (best practice for gems)
16
+ * Simplify version file
17
+
18
+ ## [0.3.0](https://github.com/tbpro/mongoid_userstamp/releases/tag/v0.3.0) - 2013-10-02
19
+
20
+ * Improvement
21
+ * BREAKING: Default value for `updated_accessor` was `:updator`, is now `:updater` (@johnnyshields)
22
+ * DEPRECATION: `#configure` is now an alias for `#config` and is deprecated (@johnnyshields)
23
+ * Replace `Mongoid::Userstamp.configuration` and `Mongoid::Userstamp.configure` with `#config` (@johnnyshields)
24
+ * Replace usages of `id` with `_id`, since there are many gems which override the behavior of `id` (@johnnyshields)
25
+ * Do not overwrite creator if it has already been set manually (@johnnyshields)
26
+ * Define setter methods for updated_accessor/created_accessor which assign the user id. Accepts both `Mongoid::Document` and `BSON::ObjectID` types (@johnnyshields)
27
+ * Allow pass-in of Mongoid field options for updated_column/created_column. Useful to set field aliases, default value, etc. (@johnnyshields)
28
+ * Expose current_user as `Mongoid::Userstamp.current_user` (@johnnyshields)
29
+ * Field type is now `::Moped::BSON::ObjectID` instead of Object (@johnnyshields)
30
+ * Query for creator/updater user using `unscoped` (@johnnyshields)
31
+ * Improve code readability (@johnnyshields)
32
+ * Improve test coverage, including adding tests for config (@johnnyshields)
33
+
34
+ * Bugfix
35
+ * Catch error if creator/updater has been deleted and return nil (@johnnyshields)
36
+
37
+ ## [0.2.1](https://github.com/tbpro/mongoid_userstamp/releases/tag/v0.2.1) - 2013-03-24
38
+
39
+ * Improvement
40
+ * Added some specs for test coverage (@johnnyshields)
41
+ * Removed dependecy for `Mongoid::Timestamps` (@johnnyshields)
data/Gemfile CHANGED
@@ -1,9 +1,3 @@
1
- source 'http://rubygems.org'
2
-
3
- gem 'mongoid', '>= 3.0.4'
4
-
5
- group :development do
6
- gem 'rspec', '>= 2.13.0'
7
- gem 'yard', '>= 0.8.2.1'
8
- gem 'jeweler', '>= 1.8.3'
9
- end
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -1,20 +1,22 @@
1
- Copyright (c) 2013 Thomas Boerger Programmierung <http://www.tbpro.de>
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.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2012 Thomas Boerger Programmierung <http://www.tbpro.de>
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 CHANGED
@@ -1,72 +1,92 @@
1
- # MongoidUserstamp [![Build Status](https://secure.travis-ci.org/tbpro/mongoid_userstamp.png)](https://travis-ci.org/tbpro/mongoid_userstamp) [![Code Climate](https://codeclimate.com/github/tbpro/mongoid_userstamp.png)](https://codeclimate.com/github/tbpro/mongoid_userstamp)
2
-
3
- MongoidUserstamp adds stamp columns for created by and updated by
4
- informations within rails applications. Mongoid requires a ruby
5
- version above 1.8, so i've written the gem on the new 1.9 hash syntax.
6
-
7
- ## Install
8
-
9
- ```ruby
10
- gem 'mongoid_userstamp'
11
- ```
12
-
13
- ## Usage
14
-
15
- ```ruby
16
- # Default config
17
- Mongoid::Userstamp.config do |c|
18
-
19
- # Default config values
20
-
21
- c.user_reader = :current_user
22
- c.user_model = :user
23
-
24
- c.created_column = :created_by
25
- c.created_accessor = :creator
26
-
27
- c.updated_column = :updated_by
28
- c.updated_accessor = :updater
29
-
30
- # Optional config values
31
-
32
- # c.created_alias = :c
33
- # c.updated_alias = :u
34
- end
35
-
36
- # Example model
37
- class Person
38
- include Mongoid::Document
39
- include Mongoid::Userstamp
40
- end
41
-
42
- # Create instance
43
- p = Person.create
44
-
45
- # Updater ObjectID or nil
46
- p.updated_by
47
- # => BSON::ObjectId('4f7c719f476da850ba000039')
48
-
49
- # Updater instance or nil
50
- p.updater
51
- # => <User _id: 4f7c719f476da850ba000039>
52
-
53
- # Set updater manually (usually not required)
54
- p.updater = my_user # can be a Mongoid::Document or a BSON::ObjectID
55
- # => sets updated_by to my_user's ObjectID
56
-
57
- # Creator ObjectID or nil
58
- p.created_by
59
- # => BSON::ObjectId('4f7c719f476da850ba000039')
60
-
61
- # Creator instance or nil
62
- p.creator
63
- # => <User _id: 4f7c719f476da850ba000039>
64
-
65
- # Set creator manually (usually not required)
66
- p.creator = my_user # can be a Mongoid::Document or a BSON::ObjectID
67
- # => sets created_by to my_user._id
68
- ```
69
-
70
- ## Credits
71
-
72
- Copyright (c) 2012-2013 Thomas Boerger Programmierung <http://www.tbpro.de>
1
+ # MongoidUserstamp [![Build Status](https://secure.travis-ci.org/tbpro/mongoid_userstamp.png)](https://travis-ci.org/tbpro/mongoid_userstamp) [![Code Climate](https://codeclimate.com/github/tbpro/mongoid_userstamp.png)](https://codeclimate.com/github/tbpro/mongoid_userstamp)
2
+
3
+ MongoidUserstamp adds stamp columns for created by and updated by
4
+ information within Rails applications using Mongoid ORM.
5
+
6
+ ## Version Support
7
+
8
+ MongoidUserstamp is tested on the following versions:
9
+
10
+ * Ruby 1.9.3 and 2.0.0
11
+ * Rails 3
12
+ * Mongoid 3
13
+
14
+ ## Install
15
+
16
+ ```ruby
17
+ gem 'mongoid_userstamp'
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ # Default config
24
+ Mongoid::Userstamp.config do |c|
25
+
26
+ # Default config values
27
+
28
+ c.user_reader = :current_user
29
+ c.user_model = :user
30
+
31
+ c.created_column = :created_by
32
+ c.created_accessor = :creator
33
+
34
+ c.updated_column = :updated_by
35
+ c.updated_accessor = :updater
36
+
37
+ # Optional config values
38
+
39
+ # c.created_alias = :c
40
+ # c.updated_alias = :u
41
+ end
42
+
43
+ # Example model
44
+ class Person
45
+ include Mongoid::Document
46
+ include Mongoid::Userstamp
47
+ end
48
+
49
+ # Create instance
50
+ p = Person.create
51
+
52
+ # Updater ObjectID or nil
53
+ p.updated_by
54
+ # => BSON::ObjectId('4f7c719f476da850ba000039')
55
+
56
+ # Updater instance or nil
57
+ p.updater
58
+ # => <User _id: 4f7c719f476da850ba000039>
59
+
60
+ # Set updater manually (usually not required)
61
+ p.updater = my_user # can be a Mongoid::Document or a BSON::ObjectID
62
+ # => sets updated_by to my_user's ObjectID
63
+
64
+ # Creator ObjectID or nil
65
+ p.created_by
66
+ # => BSON::ObjectId('4f7c719f476da850ba000039')
67
+
68
+ # Creator instance or nil
69
+ p.creator
70
+ # => <User _id: 4f7c719f476da850ba000039>
71
+
72
+ # Set creator manually (usually not required)
73
+ p.creator = my_user # can be a Mongoid::Document or a BSON::ObjectID
74
+ # => sets created_by to my_user._id
75
+ ```
76
+
77
+ ## Contributing
78
+
79
+ Fork -> Patch -> Spec -> Push -> Pull Request
80
+
81
+ Please use Ruby 1.9.3 hash syntax, as Mongoid 3 requires Ruby >= 1.9.3
82
+
83
+ ## Authors
84
+
85
+ * [Thomas Boerger](http://www.tbpro.de)
86
+ * [John Shields](https://github.com/johnnyshields)
87
+
88
+ ## Copyright
89
+
90
+ Copyright (c) 2012-2013 Thomas Boerger Programmierung <http://www.tbpro.de>
91
+
92
+ Licensed under the MIT License (MIT). Refer to LICENSE for details.
data/Rakefile CHANGED
@@ -1,41 +1,23 @@
1
- require 'rubygems'
2
-
3
- begin
4
- require 'bundler'
5
- Bundler.setup(:default, :development)
6
- rescue Bundler::BundlerError => e
7
- $stderr.puts e.message
8
- $stderr.puts 'Run `bundle install` to install missing gems'
9
-
10
- exit e.status_code
11
- end
12
-
13
- require 'rake'
14
- require 'jeweler'
15
- require 'yard'
16
-
17
- $:.push File.expand_path('../lib', __FILE__)
18
- require 'mongoid/userstamp/version'
19
-
20
- Jeweler::Tasks.new do |gem|
21
- gem.name = 'mongoid_userstamp'
22
- gem.version = Mongoid::Userstamp::Version::STRING
23
- gem.homepage = 'https://github.com/tbpro/mongoid_userstamp'
24
- gem.license = 'MIT'
25
- gem.summary = %Q{Userstamp for mongoid}
26
- gem.description = %Q{Userstamp for created and updated columns within mongoid}
27
- gem.email = 'tboerger@tbpro.de'
28
- gem.authors = ['Thomas Boerger', 'Johnny Shields']
29
- end
30
-
31
- YARD::Rake::YardocTask.new
32
-
33
- require 'rspec/core'
34
- require 'rspec/core/rake_task'
35
-
36
- RSpec::Core::RakeTask.new(:spec) do |spec|
37
- spec.pattern = FileList['spec/**/*_spec.rb']
38
- spec.rspec_opts = '--color --format progress'
39
- end
40
-
41
- task default: :spec
1
+ begin
2
+ require 'bundler'
3
+ Bundler.setup(:default, :development)
4
+ rescue Bundler::BundlerError => e
5
+ $stderr.puts e.message
6
+ $stderr.puts 'Run `bundle install` to install missing gems'
7
+ exit e.status_code
8
+ end
9
+
10
+ require 'bundler/gem_tasks'
11
+ require 'yard'
12
+
13
+ YARD::Rake::YardocTask.new
14
+
15
+ require 'rspec/core'
16
+ require 'rspec/core/rake_task'
17
+
18
+ RSpec::Core::RakeTask.new(:spec) do |spec|
19
+ spec.pattern = FileList['spec/**/*_spec.rb']
20
+ spec.rspec_opts = '--color --format progress'
21
+ end
22
+
23
+ task default: :spec
data/init.rb CHANGED
@@ -1,2 +1,2 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'mongoid_userstamp'
1
+ # -*- encoding : utf-8 -*-
2
+ require 'mongoid_userstamp'
@@ -1,86 +1,89 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- module Mongoid
4
- module Userstamp
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- field Userstamp.config.updated_column, Userstamp.field_opts(Userstamp.config.updated_column_opts)
9
- field Userstamp.config.created_column, Userstamp.field_opts(Userstamp.config.created_column_opts)
10
-
11
- before_save :set_updater
12
- before_create :set_creator
13
-
14
- define_method Userstamp.config.updated_accessor do
15
- Userstamp.find_user self.send(Userstamp.config.updated_column)
16
- end
17
-
18
- define_method Userstamp.config.created_accessor do
19
- Userstamp.find_user self.send(Userstamp.config.created_column)
20
- end
21
-
22
- define_method "#{Userstamp.config.updated_accessor}=" do |user|
23
- self.send("#{Userstamp.config.updated_column}=", Userstamp.extract_bson_id(user))
24
- end
25
-
26
- define_method "#{Userstamp.config.created_accessor}=" do |user|
27
- self.send("#{Userstamp.config.created_column}=", Userstamp.extract_bson_id(user))
28
- end
29
-
30
- protected
31
-
32
- def set_updater
33
- return if !Userstamp.has_current_user?
34
- self.send("#{Userstamp.config.updated_accessor}=", Userstamp.current_user)
35
- end
36
-
37
- def set_creator
38
- return if !Userstamp.has_current_user? || self.send(Userstamp.config.created_column)
39
- self.send("#{Userstamp.config.created_accessor}=", Userstamp.current_user)
40
- end
41
- end
42
-
43
- class << self
44
- def config(&block)
45
- if block_given?
46
- @@config = Userstamp::Config.new(&block)
47
- else
48
- @@config ||= Userstamp::Config.new
49
- end
50
- end
51
-
52
- # @deprecated Use {#config} instead
53
- alias :configure :config
54
-
55
- def field_opts(opts)
56
- {type: ::Moped::BSON::ObjectId}.reverse_merge(opts || {})
57
- end
58
-
59
- def has_current_user?
60
- config.user_model.respond_to?(:current)
61
- end
62
-
63
- def current_user
64
- config.user_model.try(:current)
65
- end
66
-
67
- def extract_bson_id(value)
68
- if value.respond_to?(:_id)
69
- value.try(:_id)
70
- elsif value.present?
71
- ::Moped::BSON::ObjectId.from_string(value.to_s)
72
- else
73
- nil
74
- end
75
- end
76
-
77
- def find_user(user_id)
78
- begin
79
- user_id ? Userstamp.config.user_model.unscoped.find(user_id) : nil
80
- rescue Mongoid::Errors::DocumentNotFound => e
81
- nil
82
- end
83
- end
84
- end
85
- end
86
- end
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ module Mongoid
4
+ module Userstamp
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ field Userstamp.config.updated_column, Userstamp.field_opts(Userstamp.config.updated_column_opts)
9
+ field Userstamp.config.created_column, Userstamp.field_opts(Userstamp.config.created_column_opts)
10
+
11
+ before_save :set_updater
12
+ before_create :set_creator
13
+
14
+ define_method Userstamp.config.updated_accessor do
15
+ Userstamp.find_user self.send(Userstamp.config.updated_column)
16
+ end
17
+
18
+ define_method Userstamp.config.created_accessor do
19
+ Userstamp.find_user self.send(Userstamp.config.created_column)
20
+ end
21
+
22
+ define_method "#{Userstamp.config.updated_accessor}=" do |user|
23
+ self.send("#{Userstamp.config.updated_column}=", Userstamp.extract_bson_id(user))
24
+ end
25
+
26
+ define_method "#{Userstamp.config.created_accessor}=" do |user|
27
+ self.send("#{Userstamp.config.created_column}=", Userstamp.extract_bson_id(user))
28
+ end
29
+
30
+ protected
31
+
32
+ def set_updater
33
+ return if !Userstamp.has_current_user?
34
+ self.send("#{Userstamp.config.updated_accessor}=", Userstamp.current_user)
35
+ end
36
+
37
+ def set_creator
38
+ return if !Userstamp.has_current_user? || self.send(Userstamp.config.created_column)
39
+ self.send("#{Userstamp.config.created_accessor}=", Userstamp.current_user)
40
+ end
41
+ end
42
+
43
+ class << self
44
+ def config(&block)
45
+ if block_given?
46
+ @@config = Userstamp::Config.new(&block)
47
+ else
48
+ @@config ||= Userstamp::Config.new
49
+ end
50
+ end
51
+
52
+ # DEPRECATED
53
+ def configure(&block)
54
+ warn 'Mongoid::Userstamp.configure is deprecated. Please use Mongoid::Userstamp.config instead'
55
+ config(block)
56
+ end
57
+
58
+ def field_opts(opts)
59
+ {type: ::Moped::BSON::ObjectId}.reverse_merge(opts || {})
60
+ end
61
+
62
+ def has_current_user?
63
+ config.user_model.respond_to?(:current)
64
+ end
65
+
66
+ def current_user
67
+ config.user_model.try(:current)
68
+ end
69
+
70
+ def extract_bson_id(value)
71
+ if value.respond_to?(:_id)
72
+ value.try(:_id)
73
+ elsif value.present?
74
+ ::Moped::BSON::ObjectId.from_string(value.to_s)
75
+ else
76
+ nil
77
+ end
78
+ end
79
+
80
+ def find_user(user_id)
81
+ begin
82
+ user_id ? Userstamp.config.user_model.unscoped.find(user_id) : nil
83
+ rescue Mongoid::Errors::DocumentNotFound => e
84
+ nil
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end