mongoid-userstamps 3.1.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d1dac6e0316bd40bb00fee04954197bf457d7186
4
- data.tar.gz: 13b38ba6f7a730291c988016f7dc74768488b87b
2
+ SHA256:
3
+ metadata.gz: 85b23de4375ea2e8b1ac086aba81768247140873a94326df70d1c70c6d1084a8
4
+ data.tar.gz: 9aa08d63999497c7960f942dd50a8b47bddf0101a1e656d89cc686c4f79258c1
5
5
  SHA512:
6
- metadata.gz: 4ebf29e9719ebdef6df480d1d4232de2ca739e9866bd653eca4a20caa4ccb00f6494c085886356369fa9ebb623d9b68c31df046db3240c6ed06aa405d764c4d7
7
- data.tar.gz: eadea41c16f9b433a5befd23e89edfb192ed879666a7a73bf56c55258287a69db312b18976e725f4482f8bd3c87077180537e1f40f64978d7e8106f92cb2f11c
6
+ metadata.gz: a44d56d797831d102fcc6bf11b64a28c3310321182f85984a0164fe2aef318efe5d1aa04a4eba4856687c73dd92673e5c59a1cb3261e07787fb4a2cbd8763d91
7
+ data.tar.gz: 8a3c2f14885f76b5155700036e157d25226ff340fb5232440b4587e9615bbdcc17fd1fb322d00635c99078dca330be7c94c2b5bfd6960b075d2a7a6c795b32c8
@@ -0,0 +1,6 @@
1
+ inherit_gem:
2
+ standard: config/base.yml
3
+
4
+ require:
5
+ - standard
6
+ - rubocop-performance
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.4.9
5
+ - 2.5.7
6
+ - 2.6.5
7
+ before_install:
8
+ - gem install bundler
9
+ install: bundle update --jobs=3 --retry=3
10
+ services:
11
+ - mongodb
12
+ env:
13
+ - "MONGOID_VERSION=6.2.0"
14
+ - "MONGOID_VERSION=6.3.0"
15
+ - "MONGOID_VERSION=6.4.0"
16
+ - "MONGOID_VERSION=7.0.0"
17
+ - "MONGOID_VERSION=7.1.0"
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.2.0
4
+
5
+ * Mongoid 7.0 support
6
+
7
+ ## 3.1.3
8
+
9
+ * Mongoid 6.2 support
10
+ * Rails 5.1 support
11
+
12
+ ## 3.1.2
13
+
14
+ * Mongoid 6.1 support
15
+
16
+ ## 3.1.1
17
+
18
+ * Remove rails 5 warnings
19
+
20
+ ## 3.1.0
21
+
22
+ * Mongoid 6 support
23
+
24
+ ## 3.0.0.alpha1
25
+
26
+ * Mongoid 5 support
27
+
28
+ ## 2.0.0
29
+
30
+ Gem has been imported and rewrote.
31
+
3
32
  ## [0.4.1](https://github.com/tbpro/mongoid_userstamp/releases/tag/v0.4.1) - 2014-08-21
4
33
 
5
34
  * Improvement
data/Gemfile CHANGED
@@ -1,9 +1,17 @@
1
- source 'http://rubygems.org'
1
+ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'request_store', require: false
5
+ mongoid_version = ENV["MONGOID_VERSION"] || "7.0.0"
6
6
 
7
- gem 'simplecov', :require => false
8
- gem 'pry-nav', '~> 0.2.4'
7
+ gem "rake"
8
+ gem "mongoid", "~> #{mongoid_version}"
9
+ gem "request_store", require: false
9
10
 
11
+ group :development do
12
+ gem "simplecov", require: false
13
+ gem "pry-nav", "~> 0.2.4"
14
+ gem "standard", "~> 0.1.0"
15
+ gem "rubocop"
16
+ gem "rubocop-performance"
17
+ end
data/Rakefile CHANGED
@@ -1,15 +1,14 @@
1
1
  #!/usr/bin/env rake
2
- require 'bundler/gem_tasks'
3
- require 'rake/testtask'
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
4
 
5
- desc 'Default: run unit tests'
6
- task :default => :test
5
+ desc "Default: run unit tests"
6
+ task default: :test
7
7
 
8
- desc 'Run tests'
8
+ desc "Run tests"
9
9
  Rake::TestTask.new(:test) do |t|
10
- t.libs << 'lib'
11
- t.libs << 'test'
12
- t.pattern = 'test/**/*_test.rb'
13
- t.verbose = true
10
+ t.libs << "lib"
11
+ t.libs << "test"
12
+ t.pattern = "test/**/*_test.rb"
13
+ t.warning = false
14
14
  end
15
-
data/init.rb CHANGED
@@ -1,2 +1 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'mongoid_userstamp'
1
+ require "mongoid_userstamp"
@@ -1,4 +1 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- require 'mongoid/userstamps'
4
-
1
+ require "mongoid/userstamps"
@@ -1,13 +1,11 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- require 'mongoid/userstamps/version'
4
- require 'mongoid/userstamps/config'
5
- require 'mongoid/userstamps/user'
6
- require 'mongoid/userstamps/model'
7
- require 'mongoid/userstamps/created'
8
- require 'mongoid/userstamps/updated'
9
- require 'mongoid/userstamps/deleted'
10
- require 'mongoid/userstamps/railtie' if defined? Rails
1
+ require "mongoid/userstamps/version"
2
+ require "mongoid/userstamps/config"
3
+ require "mongoid/userstamps/user"
4
+ require "mongoid/userstamps/model"
5
+ require "mongoid/userstamps/created"
6
+ require "mongoid/userstamps/updated"
7
+ require "mongoid/userstamps/deleted"
8
+ require "mongoid/userstamps/railtie" if defined? Rails
11
9
 
12
10
  module Mongoid
13
11
  module Userstamps
@@ -27,4 +25,3 @@ module Mongoid
27
25
  end
28
26
  end
29
27
  end
30
-
@@ -1,16 +1,10 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
- require 'mongoid/userstamps/config/model'
4
- require 'mongoid/userstamps/config/user'
1
+ require "mongoid/userstamps/config/model"
2
+ require "mongoid/userstamps/config/user"
5
3
 
6
4
  module Mongoid
7
5
  module Userstamps
8
6
  module Config
9
7
  class << self
10
- attr_accessor :created_name
11
- attr_accessor :updated_name
12
- attr_accessor :deleted_name
13
-
14
8
  DEFAULT_CREATED_NAME = :created_by
15
9
  DEFAULT_UPDATED_NAME = :updated_by
16
10
  DEFAULT_DELETED_NAME = :deleted_by
@@ -34,14 +28,20 @@ module Mongoid
34
28
  model_classes << klass
35
29
  end
36
30
 
31
+ attr_writer :created_name
32
+
37
33
  def created_name
38
34
  @created_name ||= DEFAULT_CREATED_NAME
39
35
  end
40
36
 
37
+ attr_writer :updated_name
38
+
41
39
  def updated_name
42
40
  @updated_name ||= DEFAULT_UPDATED_NAME
43
41
  end
44
42
 
43
+ attr_writer :deleted_name
44
+
45
45
  def deleted_name
46
46
  @deleted_name ||= DEFAULT_DELETED_NAME
47
47
  end
@@ -55,7 +55,7 @@ module Mongoid
55
55
  end
56
56
 
57
57
  def store(model, value = false)
58
- return if !model
58
+ return unless model
59
59
  key = "mongoid-userstamps/#{model.to_s.underscore}".to_sym
60
60
  store = defined?(RequestStore) ? RequestStore.store : Thread.current
61
61
  if value == false
@@ -74,4 +74,3 @@ module Mongoid
74
74
  end
75
75
  end
76
76
  end
77
-
@@ -1,13 +1,10 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
1
  module Mongoid
4
2
  module Userstamps
5
3
  module Config
6
4
  class Model
7
- attr_accessor :user_model
8
-
9
5
  def initialize(model)
10
6
  @model = model
7
+ @user_model = nil
11
8
  end
12
9
 
13
10
  def config
@@ -24,12 +21,20 @@ module Mongoid
24
21
  end
25
22
 
26
23
  def set_user_model!
27
- @model.relations[config.created_name.to_s].try(:[]=, :class_name, user_model)
28
- @model.relations[config.updated_name.to_s].try(:[]=, :class_name, user_model)
29
- @model.relations[config.deleted_name.to_s].try(:[]=, :class_name, user_model)
24
+ if Mongoid::VERSION.to_f < 7.0
25
+ %i[created_name updated_name deleted_name].each do |attr|
26
+ @model.relations[config.send(attr).to_s].try(:[]=, :class_name, user_model)
27
+ end
28
+ else
29
+ %i[created_name updated_name deleted_name].each do |attr|
30
+ if @model.relations[config.send(attr).to_s]
31
+ @model.relations[config.send(attr).to_s].instance_variable_set :@class_name, user_model
32
+ @model.relations[config.send(attr).to_s].options[:class_name] = user_model
33
+ end
34
+ end
35
+ end
30
36
  end
31
37
  end
32
38
  end
33
39
  end
34
40
  end
35
-
@@ -1,5 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
1
  module Mongoid
4
2
  module Userstamps
5
3
  module Config
@@ -13,4 +11,3 @@ module Mongoid
13
11
  end
14
12
  end
15
13
  end
16
-
@@ -1,19 +1,17 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
1
  module Mongoid
4
2
  module Userstamps
5
3
  module Created
6
4
  extend ActiveSupport::Concern
7
5
 
8
6
  included do
9
- if !self.included_modules.include?(Mongoid::Userstamps::Model)
7
+ unless included_modules.include?(Mongoid::Userstamps::Model)
10
8
  include Mongoid::Userstamps::Model
11
9
  end
12
10
 
13
11
  belongs_to userstamps_config.created_name, {
14
12
  class_name: userstamps_model.user_model,
15
13
  inverse_of: nil,
16
- optional: true
14
+ optional: true,
17
15
  }
18
16
 
19
17
  set_callback :create, :before, :set_created_by
@@ -21,10 +19,9 @@ module Mongoid
21
19
 
22
20
  def set_created_by
23
21
  user = self.class.current_user
24
- return if !user || self.public_send(userstamps_config.created_name)
25
- self.public_send("#{userstamps_config.created_name}=", user)
22
+ return if !user || public_send(userstamps_config.created_name)
23
+ public_send("#{userstamps_config.created_name}=", user)
26
24
  end
27
25
  end
28
26
  end
29
27
  end
30
-
@@ -1,19 +1,17 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
1
  module Mongoid
4
2
  module Userstamps
5
3
  module Deleted
6
4
  extend ActiveSupport::Concern
7
5
 
8
6
  included do
9
- if !self.included_modules.include?(Mongoid::Userstamps::Model)
7
+ unless included_modules.include?(Mongoid::Userstamps::Model)
10
8
  include Mongoid::Userstamps::Model
11
9
  end
12
10
 
13
11
  belongs_to userstamps_config.deleted_name, {
14
12
  class_name: userstamps_model.user_model,
15
13
  inverse_of: nil,
16
- optional: true
14
+ optional: true,
17
15
  }
18
16
 
19
17
  set_callback :destroy, :before, :set_deleted_by
@@ -21,10 +19,9 @@ module Mongoid
21
19
 
22
20
  def set_deleted_by
23
21
  user = self.class.current_user
24
- return if !user || self.public_send("#{userstamps_config.deleted_name}_id_changed?")
25
- self.public_send("#{userstamps_config.deleted_name}=", user)
22
+ return if !user || public_send("#{userstamps_config.deleted_name}_id_changed?")
23
+ public_send("#{userstamps_config.deleted_name}=", user)
26
24
  end
27
25
  end
28
26
  end
29
27
  end
30
-
@@ -27,4 +27,3 @@ module Mongoid
27
27
  end
28
28
  end
29
29
  end
30
-
@@ -1,20 +1,15 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
1
  module Mongoid
4
2
  module Userstamps
5
3
  class Railtie < Rails::Railtie
6
4
  # Set current_user from controller reader method
7
5
  ActiveSupport.on_load :action_controller do
8
- before_filter do |c|
6
+ before_action do |c|
9
7
  Mongoid::Userstamps::Config.user_classes.each do |user_class|
10
- begin
11
- user_class.current = c.public_send(user_class.userstamps_user.reader)
12
- rescue
13
- end
8
+ user_class.current = c.public_send(user_class.userstamps_user.reader)
9
+ rescue
14
10
  end
15
11
  end
16
12
  end
17
13
  end
18
14
  end
19
15
  end
20
-
@@ -1,19 +1,17 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
1
  module Mongoid
4
2
  module Userstamps
5
3
  module Updated
6
4
  extend ActiveSupport::Concern
7
5
 
8
6
  included do
9
- if !self.included_modules.include?(Mongoid::Userstamps::Model)
7
+ unless included_modules.include?(Mongoid::Userstamps::Model)
10
8
  include Mongoid::Userstamps::Model
11
9
  end
12
10
 
13
11
  belongs_to userstamps_config.updated_name, {
14
12
  class_name: userstamps_model.user_model,
15
13
  inverse_of: nil,
16
- optional: true
14
+ optional: true,
17
15
  }
18
16
 
19
17
  set_callback :save, :before, :set_updated_by
@@ -21,10 +19,9 @@ module Mongoid
21
19
 
22
20
  def set_updated_by
23
21
  user = self.class.current_user
24
- return if !user || self.public_send("#{userstamps_config.updated_name}_id_changed?")
25
- self.public_send("#{userstamps_config.updated_name}=", user)
22
+ return if !user || public_send("#{userstamps_config.updated_name}_id_changed?")
23
+ public_send("#{userstamps_config.updated_name}=", user)
26
24
  end
27
25
  end
28
26
  end
29
27
  end
30
-
@@ -1,4 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
1
  module Mongoid
3
2
  module Userstamps
4
3
  module User
@@ -9,7 +8,7 @@ module Mongoid
9
8
  end
10
9
 
11
10
  def current?
12
- self.id == self.class.current.try(:id)
11
+ id == self.class.current.try(:id)
13
12
  end
14
13
 
15
14
  class_methods do
@@ -22,7 +21,7 @@ module Mongoid
22
21
  end
23
22
 
24
23
  def sudo(user)
25
- old = self.current
24
+ old = current
26
25
  self.current = user
27
26
  yield
28
27
  ensure
@@ -36,4 +35,3 @@ module Mongoid
36
35
  end
37
36
  end
38
37
  end
39
-
@@ -1,8 +1,5 @@
1
- # -*- encoding : utf-8 -*-
2
-
3
1
  module Mongoid
4
2
  module Userstamps
5
- VERSION = '3.1.0'
3
+ VERSION = "3.3.0"
6
4
  end
7
5
  end
8
-
@@ -1,26 +1,24 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path('../lib', __FILE__)
1
+ $:.push File.expand_path("../lib", __FILE__)
3
2
 
4
- require 'mongoid/userstamps/version'
3
+ require "mongoid/userstamps/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = 'mongoid-userstamps'
8
- s.version = Mongoid::Userstamps::VERSION
9
- s.authors = ['Geoffroy Planquart', 'Thomas Boerger', 'Johnny Shields', 'Bharat Gupta']
10
- s.homepage = 'https://github.com/tbpro/mongoid_userstamp'
11
- s.license = 'MIT'
12
- s.summary = 'Userstamps for Mongoid'
13
- s.description = 'Userstamps for creator and updater fields using Mongoid'
14
- s.email = ['geoffroy@planquart.fr', 'tboerger@tbpro.de']
6
+ s.name = "mongoid-userstamps"
7
+ s.version = Mongoid::Userstamps::VERSION
8
+ s.authors = ["Geoffroy Planquart", "Thomas Boerger", "Johnny Shields", "Bharat Gupta"]
9
+ s.homepage = "https://github.com/tbpro/mongoid_userstamp"
10
+ s.license = "MIT"
11
+ s.summary = "Userstamps for Mongoid"
12
+ s.description = "Userstamps for creator and updater fields using Mongoid"
13
+ s.email = ["geoffroy@planquart.fr", "tboerger@tbpro.de"]
15
14
 
16
- s.files = `git ls-files`.split($/)
17
- s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
- s.require_paths = ['lib']
15
+ s.files = `git ls-files`.split($/)
16
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+ s.require_paths = ["lib"]
20
19
 
21
- s.post_install_message = File.read('UPGRADING') if File.exists?('UPGRADING')
20
+ s.post_install_message = File.read("UPGRADING") if File.exist?("UPGRADING")
22
21
 
23
- s.add_dependency 'mongoid', '>= 5.0.0', '< 6.1.0'
24
- s.add_dependency 'activesupport', '>= 4.2.0', '< 5.1.0'
22
+ s.add_dependency "mongoid", ">= 5.0.0", "< 7.2.0"
23
+ s.add_dependency "activesupport", ">= 4.2.0", "< 6.1.0"
25
24
  end
26
-