mongoid_paranoia 0.5.0 → 0.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec456afdb66a1a23fdb5dc73db06b9dc6344932f8aa3c95b378ca60560aea474
4
- data.tar.gz: b80b6cfaedfb9523b9dbfe791d586493eb4c9d3e65b7286d3cdc2010d8f9874e
3
+ metadata.gz: c03b7dee0f348835ab02ae6dd3543c6af25a9593a2b3655192d35516dbe6eeec
4
+ data.tar.gz: 43bf43f4fa43bff574b843213beb54e5a2d3ed4b6c80205d3443212e6ac1ca2a
5
5
  SHA512:
6
- metadata.gz: 3aff3ad8f7f06f0a1498143baf6cf72d58c24b99b3a4f0bfb19fd314ec836625356291989293ddee2dc230d148dda65f84bc153660bd00566ba8bc727e21ee9f
7
- data.tar.gz: 5322c2f12d84591a8e0bc3463faf1e82571f09c5877bc3a3f7bcfbf7c10c87e198bb8be2add2ab42c6e71341df77fdbe7dbe368ccc476d7e44c8f41839c283cb
6
+ metadata.gz: b5a5b3bf5cf3074a00565798032c1b3fae4c23e2c4ed80091600305a11a52e981ad735503a1ddb6369aa17da4900e010b366e2af8b46db842a0c1b55bdff3e3c
7
+ data.tar.gz: fceeb94c3cf50a52dd90e500988f63c9e4e850153d31808604bf226a7099b33401df37e04448474f07511905371fd9f068390689509c2480f8b5862b521b4d44
data/README.md CHANGED
@@ -1,12 +1,21 @@
1
1
  # Paranoid Documents for Mongoid
2
2
  [![Build Status](https://travis-ci.org/simi/mongoid_paranoia.svg?branch=master)](https://travis-ci.org/simi/mongoid_paranoia) [![Gem Version](https://img.shields.io/gem/v/mongoid_paranoia.svg)](https://rubygems.org/gems/mongoid_paranoia) [![Gitter chat](https://badges.gitter.im/simi/mongoid_paranoia.svg)](https://gitter.im/simi/mongoid_paranoia)
3
3
 
4
- `Mongoid::Paranoia` enables a "soft delete" of Mongoid documents. Instead of being removed from the database, paranoid docs are flagged with a `deleted_at` timestamp and are ignored from queries by default.
4
+ `Mongoid::Paranoia` enables a "soft delete" of Mongoid documents.
5
+ Instead of being removed from the database, paranoid docs are flagged
6
+ with a `deleted_at` timestamp and are ignored from queries by default.
5
7
 
6
- The `Mongoid::Paranoia` functionality was originally supported in Mongoid itself, but was dropped from version 4.0.0 onwards. This gem was extracted from the [Mongoid 3.0.0-stable branch](https://github.com/mongoid/mongoid/tree/3.0.0-stable). This gem should not be used with Mongoid versions 3.x and prior. Current master branch targeted on Mongoid 6.0. With release 0.3.0 Mongoid 4 and 5 versions will be dropped.
8
+ The `Mongoid::Paranoia` functionality was originally supported in Mongoid
9
+ itself, but was dropped from version 4.0 onwards. This gem was extracted
10
+ from the [Mongoid 3.0.0-stable branch](https://github.com/mongodb/mongoid/tree/3.0.0-stable).
7
11
 
8
12
  **Caution:** This repo/gem `mongoid_paranoia` (underscored) is different than [mongoid-paranoia](https://github.com/haihappen/mongoid-paranoia) (hyphenated). The goal of `mongoid-paranoia` (hyphenated) is to stay API compatible and it only accepts security fixes.
9
13
 
14
+ ## Version Support
15
+
16
+ * The current release is compatible with Mongoid 7.3 and later, and Ruby 2.7 and later.
17
+ * Earlier Mongoid and Ruby versions are supported on earlier releases.
18
+
10
19
  ## Installation
11
20
 
12
21
  Add this line to your application's Gemfile:
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Mongoid
4
4
  module Paranoia
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
@@ -75,7 +75,7 @@ module Mongoid
75
75
  # @return [ true ] True.
76
76
  #
77
77
  # @since 1.0.0
78
- alias :orig_delete :delete
78
+ alias orig_delete delete
79
79
 
80
80
  def remove(_ = {})
81
81
  time = self.deleted_at = Time.now
@@ -84,8 +84,8 @@ module Mongoid
84
84
  true
85
85
  end
86
86
 
87
- alias :delete :remove
88
- alias :delete! :orig_delete
87
+ alias delete remove
88
+ alias delete! orig_delete
89
89
 
90
90
  # Delete the paranoid +Document+ from the database completely. This will
91
91
  # run the destroy and remove callbacks.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_paranoia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan
@@ -9,36 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-07-24 00:00:00.000000000 Z
12
+ date: 2023-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '7.3'
21
21
  type: :runtime
22
22
  prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '7.3'
28
- - !ruby/object:Gem::Dependency
29
- name: rubocop
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: 1.8.1
35
- type: :development
36
- prerelease: false
37
23
  version_requirements: !ruby/object:Gem::Requirement
38
24
  requirements:
39
25
  - - ">="
40
26
  - !ruby/object:Gem::Version
41
- version: 1.8.1
27
+ version: '7.3'
42
28
  description: Provides a Paranoia module documents which soft-deletes documents.
43
29
  email:
44
30
  - durran@gmail.com
@@ -55,29 +41,11 @@ files:
55
41
  - lib/mongoid/paranoia/monkey_patches.rb
56
42
  - lib/mongoid/paranoia/version.rb
57
43
  - lib/mongoid_paranoia.rb
58
- - perf/scope.rb
59
- - spec/app/models/address.rb
60
- - spec/app/models/appointment.rb
61
- - spec/app/models/author.rb
62
- - spec/app/models/fish.rb
63
- - spec/app/models/paranoid_phone.rb
64
- - spec/app/models/paranoid_post.rb
65
- - spec/app/models/person.rb
66
- - spec/app/models/phone.rb
67
- - spec/app/models/relations.rb
68
- - spec/app/models/tag.rb
69
- - spec/app/models/title.rb
70
- - spec/mongoid/configuration_spec.rb
71
- - spec/mongoid/document_spec.rb
72
- - spec/mongoid/nested_attributes_spec.rb
73
- - spec/mongoid/paranoia_spec.rb
74
- - spec/mongoid/scoping_spec.rb
75
- - spec/mongoid/validatable/uniqueness_spec.rb
76
- - spec/spec_helper.rb
77
44
  homepage: https://github.com/simi/mongoid-paranoia
78
45
  licenses:
79
46
  - MIT
80
- metadata: {}
47
+ metadata:
48
+ rubygems_mfa_required: 'true'
81
49
  post_install_message:
82
50
  rdoc_options: []
83
51
  require_paths:
@@ -93,27 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
61
  - !ruby/object:Gem::Version
94
62
  version: '0'
95
63
  requirements: []
96
- rubygems_version: 3.1.2
64
+ rubygems_version: 3.4.4
97
65
  signing_key:
98
66
  specification_version: 4
99
67
  summary: Paranoid documents
100
- test_files:
101
- - perf/scope.rb
102
- - spec/app/models/address.rb
103
- - spec/app/models/appointment.rb
104
- - spec/app/models/author.rb
105
- - spec/app/models/fish.rb
106
- - spec/app/models/paranoid_phone.rb
107
- - spec/app/models/paranoid_post.rb
108
- - spec/app/models/person.rb
109
- - spec/app/models/phone.rb
110
- - spec/app/models/relations.rb
111
- - spec/app/models/tag.rb
112
- - spec/app/models/title.rb
113
- - spec/mongoid/configuration_spec.rb
114
- - spec/mongoid/document_spec.rb
115
- - spec/mongoid/nested_attributes_spec.rb
116
- - spec/mongoid/paranoia_spec.rb
117
- - spec/mongoid/scoping_spec.rb
118
- - spec/mongoid/validatable/uniqueness_spec.rb
119
- - spec/spec_helper.rb
68
+ test_files: []
data/perf/scope.rb DELETED
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/setup'
4
- require 'mongoid'
5
- require 'mongoid/paranoia'
6
- require 'benchmark'
7
-
8
- Mongoid.configure do |config|
9
- config.connect_to('my_little_test')
10
- end
11
-
12
- class Model
13
- include Mongoid::Document
14
- field :text, type: String
15
-
16
- index({ text: 'text' })
17
- end
18
-
19
- class ParanoidModel
20
- include Mongoid::Document
21
- include Mongoid::Paranoia
22
- field :text, type: String
23
-
24
- index({ text: 'text' })
25
- end
26
-
27
- class MetaParanoidModel
28
- include Mongoid::Document
29
- field :text, type: String
30
- field :deleted_at, type: Time
31
- default_scope -> { where(deleted_at: nil) }
32
-
33
- index({ text: 'text' })
34
- end
35
-
36
- if ENV['FORCE']
37
- Mongoid.purge!
38
- ::Mongoid::Tasks::Database.create_indexes
39
-
40
- n = 50_000
41
- n.times {|i| Model.create(text: "text #{i}") }
42
- n.times {|i| ParanoidModel.create(text: "text #{i}") }
43
- n.times {|i| MetaParanoidModel.create(text: "text #{i}") }
44
- end
45
-
46
- n = 100
47
-
48
- puts 'text_search benchmark ***'
49
- Benchmark.bm(20) do |x|
50
- x.report('without') { n.times { Model.text_search('text').execute } }
51
- x.report('with') { n.times { ParanoidModel.text_search('text').execute } }
52
- x.report('meta') { n.times { MetaParanoidModel.text_search('text').execute } }
53
- x.report('unscoped meta') { n.times { MetaParanoidModel.unscoped.text_search('text').execute } }
54
- x.report('unscoped paranoid') { n.times { ParanoidModel.unscoped.text_search('text').execute } }
55
- end
56
-
57
- puts ''
58
- puts 'Pluck all ids benchmark ***'
59
- Benchmark.bm(20) do |x|
60
- x.report('without') { n.times { Model.all.pluck(:id) } }
61
- x.report('with') { n.times { ParanoidModel.all.pluck(:id) } }
62
- x.report('meta') { n.times { MetaParanoidModel.all.pluck(:id) } }
63
- x.report('unscoped meta') { n.times { MetaParanoidModel.unscoped.all.pluck(:id) } }
64
- x.report('unscoped paranoid') { n.times { ParanoidModel.unscoped.all.pluck(:id) } }
65
- end
@@ -1,71 +0,0 @@
1
- class Address
2
- include Mongoid::Document
3
-
4
- field :_id, type: String, default: ->{ street.try(:parameterize) }
5
-
6
- attr_accessor :mode
7
-
8
- field :address_type
9
- field :number, type: Integer
10
- field :street
11
- field :city
12
- field :state
13
- field :post_code
14
- field :parent_title
15
- field :services, type: Array
16
- field :latlng, type: Array
17
- field :map, type: Hash
18
- field :move_in, type: DateTime
19
- field :s, type: String, as: :suite
20
- field :name, localize: true
21
-
22
- embeds_one :code, validate: false
23
- embeds_one :target, as: :targetable, validate: false
24
-
25
- embedded_in :addressable, polymorphic: true do
26
- def extension
27
- "Testing"
28
- end
29
- def doctor?
30
- title == "Dr"
31
- end
32
- end
33
-
34
- accepts_nested_attributes_for :code, :target
35
-
36
- belongs_to :account
37
-
38
- scope :without_postcode, -> {where(postcode: nil)}
39
- scope :rodeo, -> {
40
- where(street: "Rodeo Dr") do
41
- def mansion?
42
- all? { |address| address.street == "Rodeo Dr" }
43
- end
44
- end
45
- }
46
-
47
- validates_presence_of :street, on: :update
48
- validates_format_of :street, with: /\D/, allow_nil: true
49
-
50
- def set_parent=(set = false)
51
- self.parent_title = addressable.title if set
52
- end
53
-
54
- def <=>(other)
55
- street <=> other.street
56
- end
57
-
58
- class << self
59
- def california
60
- where(state: "CA")
61
- end
62
-
63
- def homes
64
- where(address_type: "Home")
65
- end
66
-
67
- def streets
68
- all.map(&:street)
69
- end
70
- end
71
- end
@@ -1,7 +0,0 @@
1
- class Appointment
2
- include Mongoid::Document
3
- field :active, type: Boolean, default: true
4
- field :timed, type: Boolean, default: true
5
- embedded_in :person
6
- default_scope ->{where(active: true)}
7
- end
@@ -1,6 +0,0 @@
1
- class Author
2
- include Mongoid::Document
3
- field :name, type: String
4
-
5
- belongs_to :post, class_name: "ParanoidPost"
6
- end
@@ -1,8 +0,0 @@
1
- class Fish
2
- include Mongoid::Document
3
- include Mongoid::Paranoia
4
-
5
- def self.fresh
6
- where(fresh: true)
7
- end
8
- end
@@ -1,25 +0,0 @@
1
- class ParanoidPhone
2
- include Mongoid::Document
3
- include Mongoid::Paranoia
4
-
5
- attr_accessor :after_destroy_called, :before_destroy_called
6
-
7
- field :number, type: String
8
-
9
- embedded_in :person
10
-
11
- before_destroy :before_destroy_stub, :halt_me
12
- after_destroy :after_destroy_stub
13
-
14
- def before_destroy_stub
15
- self.before_destroy_called = true
16
- end
17
-
18
- def after_destroy_stub
19
- self.after_destroy_called = true
20
- end
21
-
22
- def halt_me
23
- throw :abort if person.age == 42
24
- end
25
- end
@@ -1,65 +0,0 @@
1
- class ParanoidPost
2
- include Mongoid::Document
3
- include Mongoid::Paranoia
4
-
5
- field :title, type: String
6
-
7
- attr_accessor :after_destroy_called, :before_destroy_called,
8
- :after_restore_called, :before_restore_called,
9
- :after_remove_called, :before_remove_called,
10
- :around_before_restore_called, :around_after_restore_called
11
-
12
- belongs_to :person
13
-
14
- has_and_belongs_to_many :tags
15
- has_many :authors, dependent: :delete_all, inverse_of: :post
16
- has_many :titles, dependent: :restrict_with_error
17
-
18
- scope :recent, -> {where(created_at: { "$lt" => Time.now, "$gt" => 30.days.ago })}
19
-
20
- before_destroy :before_destroy_stub
21
- after_destroy :after_destroy_stub
22
-
23
- before_remove :before_remove_stub
24
- after_remove :after_remove_stub
25
-
26
- before_restore :before_restore_stub
27
- after_restore :after_restore_stub
28
- around_restore :around_restore_stub
29
-
30
- def before_destroy_stub
31
- self.before_destroy_called = true
32
- end
33
-
34
- def after_destroy_stub
35
- self.after_destroy_called = true
36
- end
37
-
38
- def before_remove_stub
39
- self.before_remove_called = true
40
- end
41
-
42
- def after_remove_stub
43
- self.after_remove_called = true
44
- end
45
-
46
- def before_restore_stub
47
- self.before_restore_called = true
48
- end
49
-
50
- def after_restore_stub
51
- self.after_restore_called = true
52
- end
53
-
54
- def around_restore_stub
55
- self.around_before_restore_called = true
56
- yield
57
- self.around_after_restore_called = true
58
- end
59
-
60
- class << self
61
- def old
62
- where(created_at: { "$lt" => 30.days.ago })
63
- end
64
- end
65
- end
@@ -1,21 +0,0 @@
1
- class Person
2
- include Mongoid::Document
3
-
4
- field :age, type: Integer, default: "100"
5
- field :score, type: Integer
6
-
7
- attr_reader :rescored
8
-
9
- embeds_many :phone_numbers, class_name: "Phone", validate: false
10
- embeds_many :phones, store_as: :mobile_phones, validate: false
11
- embeds_many :addresses, as: :addressable, validate: false
12
-
13
- embeds_many :appointments, validate: false
14
- embeds_many :paranoid_phones, validate: false
15
-
16
- has_many :paranoid_posts, validate: false
17
- belongs_to :paranoid_post
18
-
19
- accepts_nested_attributes_for :addresses
20
- accepts_nested_attributes_for :paranoid_phones
21
- end
@@ -1,11 +0,0 @@
1
- class Phone
2
- include Mongoid::Document
3
-
4
- attr_accessor :number_in_observer
5
-
6
- field :_id, type: String, default: ->{ number }
7
-
8
- field :number
9
- embeds_one :country_code
10
- embedded_in :person
11
- end