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 +8 -8
- data/.gitignore +13 -0
- data/.travis.yml +20 -8
- data/CHANGELOG.md +41 -26
- data/Gemfile +3 -9
- data/{LICENSE.md → LICENSE} +22 -20
- data/README.md +92 -72
- data/Rakefile +23 -41
- data/init.rb +2 -2
- data/lib/mongoid/userstamp.rb +89 -86
- data/lib/mongoid/userstamp/config.rb +30 -30
- data/lib/mongoid/userstamp/railtie.rb +22 -19
- data/lib/mongoid/userstamp/user.rb +37 -37
- data/lib/mongoid/userstamp/version.rb +6 -13
- data/lib/mongoid_userstamp.rb +6 -6
- data/mongoid_userstamp.gemspec +26 -69
- data/spec/mongoid/userstamp_spec.rb +163 -163
- data/spec/spec_helper.rb +26 -26
- data/spec/support/book.rb +7 -7
- data/spec/support/user.rb +7 -7
- metadata +32 -17
- data/.ruby-version +0 -1
- data/Gemfile.lock +0 -50
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODZhMzk0MmJlYTI2NDZiMzFkZDM4N2JkNzZkOTU4ZGNlMTVmMDFlZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzNiZjUxYzc3ZWNkNTc4ZDQyOGNkNTE3NmEwOGYzOGU4M2QxYWE1NQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDRiMDkzOGNmYTJhY2Y4ZjljYTRiNmJmODM1Mjg2ZjliYzc2ODJhMzgwMzE2
|
10
|
+
MmNiM2I5NTkzZWVjNzlhYmIxOTVjZDFmMTkzY2E5ZGI4YjMwNDNmZDJkOGE2
|
11
|
+
YWQ0MzY5NDAyM2E0MTdlYjI1YzA1Y2I5MWExMmRhMzVmZTFhZDg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWNhNGYyMzY1NTc3NzI3ZWMwZjFhZjZlOTdkYjQwOTQxYTQxMzE1MzczY2Yy
|
14
|
+
OWJiZDA4MjBmMTI0NzdjMmIzZmZkZDViN2M2NjgyY2RlMTk5NjM5MGVkZmRj
|
15
|
+
MDQzODg4ODQxMDZiY2UyNTU0OGU5ODVhMDFlY2ZhN2RmZDQwOWE=
|
data/.gitignore
ADDED
data/.travis.yml
CHANGED
@@ -1,8 +1,20 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.
|
4
|
-
-
|
5
|
-
-
|
6
|
-
-
|
7
|
-
|
8
|
-
|
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.
|
4
|
-
|
5
|
-
*
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
*
|
11
|
-
*
|
12
|
-
|
13
|
-
|
14
|
-
*
|
15
|
-
*
|
16
|
-
*
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
*
|
25
|
-
*
|
26
|
-
*
|
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
data/{LICENSE.md → LICENSE}
RENAMED
@@ -1,20 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
the
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
#
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
require '
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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'
|
data/lib/mongoid/userstamp.rb
CHANGED
@@ -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
|
-
#
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|