mongoid-paranoia 1.3.0 → 2.0.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
2
  SHA1:
3
- metadata.gz: e2cadcf3b4063c6ad95cdd9c72aeedf8000166bb
4
- data.tar.gz: 16fc73e78b17b5bb7091e38afa52eeaa177fcadd
3
+ metadata.gz: f9d063648fd0353a0d35ebf228c001fa23768746
4
+ data.tar.gz: 45d30f5c118fea59f4105da8f5780d5efe120a41
5
5
  SHA512:
6
- metadata.gz: 036e55c67d31d6efbe45da862532e373500a1a4530efa46c62d50289aadfd4dd20ba6af825133e89a92f544a97f5aed25b42760a470069cc72150fd66e9378fb
7
- data.tar.gz: a9dd85df18376228c86d20b62cf03ac374cd29eaee4037a659903f5e0ca118a4c78e54f1c02bce1a59c889edb23bf92ea7ad1c23875cd2ae89c7fdcabf62b001
6
+ metadata.gz: d3d00fdac7bc5d5b995d0888f33c6ee5fd1f61ecd61a72798a7958ba1d3141cd7cfceea7a8a09bcdc3249afd5c03cfb0fd1e46b813a228f3f0d59056f2c2e6b7
7
+ data.tar.gz: b69102aff52a05aae1bfb282389d1cf30251ce9b1499378aca300fbd8b754f23628f68f5579737bac6a63e70286cac692635f3743624b3716fc792daba6f1835
@@ -0,0 +1,20 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.2
3
+
4
+ Documentation:
5
+ Enabled: false
6
+
7
+ Style/AlignParameters:
8
+ EnforcedStyle: with_fixed_indentation
9
+
10
+ Style/Alias:
11
+ EnforcedStyle: prefer_alias_method
12
+
13
+ Style/IndentArray:
14
+ EnforcedStyle: consistent
15
+
16
+ Style/IndentHash:
17
+ EnforcedStyle: consistent
18
+
19
+ Style/MultilineMethodCallIndentation:
20
+ EnforcedStyle: indented
@@ -1,11 +1,12 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  services: mongodb
3
4
 
4
5
  rvm:
5
- - 1.9.3
6
6
  - 2.0.0
7
7
  - 2.1.0
8
8
  - 2.2.0
9
+ - 2.3.0
9
10
 
10
11
  gemfile:
11
12
  - Gemfile
data/README.md CHANGED
@@ -56,7 +56,7 @@ Person.deleted # Returns documents that have been "flagged" as deleted.
56
56
 
57
57
  (The MIT license)
58
58
 
59
- Copyright (c) 2013-2015 Mario Uher
59
+ Copyright (c) 2009-2013 Durran Jordan, 2013-2015 Mario Uher
60
60
 
61
61
  Permission is hereby granted, free of charge, to any person obtaining
62
62
  a copy of this software and associated documentation files (the
@@ -3,7 +3,6 @@ module Mongoid
3
3
  module Relations
4
4
  module Embedded
5
5
  class Many < Relations::Many
6
-
7
6
  # Delete the supplied document from the target. This method is proxied
8
7
  # in order to reindex the array after the operation occurs.
9
8
  #
@@ -1,7 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
3
  module Validatable
4
-
5
4
  # Validates whether or not a field is unique against the documents in the
6
5
  # database.
7
6
  #
@@ -14,7 +13,6 @@ module Mongoid
14
13
  # validates_uniqueness_of :title
15
14
  # end
16
15
  class UniquenessValidator < ActiveModel::EachValidator
17
-
18
16
  # Scope the criteria to the scope options provided.
19
17
  #
20
18
  # @api private
@@ -28,7 +26,7 @@ module Mongoid
28
26
  # @return [ Criteria ] The scoped criteria.
29
27
  #
30
28
  # @since 2.3.0
31
- def scope(criteria, document, attribute)
29
+ def scope(criteria, document, _attribute)
32
30
  Array.wrap(options[:scope]).each do |item|
33
31
  name = document.database_field_name(item)
34
32
  criteria = criteria.where(item => document.attributes[name])
@@ -5,7 +5,6 @@ require 'mongoid/core_ext/validatable/uniqueness'
5
5
 
6
6
  # encoding: utf-8
7
7
  module Mongoid
8
-
9
8
  # Include this module to get soft deletion of root level documents.
10
9
  # This will add a deleted_at field to the +Document+, managed automatically.
11
10
  # Potentially incompatible with unique indices. (if collisions with deleted items)
@@ -23,8 +22,8 @@ module Mongoid
23
22
  field :deleted_at, type: Time
24
23
  self.paranoid = true
25
24
 
26
- default_scope ->{ where(deleted_at: nil) }
27
- scope :deleted, ->{ ne(deleted_at: nil) }
25
+ default_scope -> { where(deleted_at: nil) }
26
+ scope :deleted, -> { ne(deleted_at: nil) }
28
27
  end
29
28
 
30
29
  # Delete the paranoid +Document+ from the database completely. This will
@@ -52,19 +51,19 @@ module Mongoid
52
51
  #
53
52
  # @todo Remove Mongoid 4 support.
54
53
  # @since 1.0.0
55
- def remove_with_paranoia(options = {})
54
+ def remove_with_paranoia(_options = {})
56
55
  cascade!
57
56
  time = self.deleted_at = Time.now
58
57
  query = paranoid_collection.find(atomic_selector)
59
58
  query.respond_to?(:update_one) ?
60
- query.update_one({ "$set" => { paranoid_field => time }}) :
61
- query.update({ "$set" => { paranoid_field => time }})
59
+ query.update_one('$set' => { paranoid_field => time }) :
60
+ query.update('$set' => { paranoid_field => time })
62
61
 
63
62
  @destroyed = true
64
63
  true
65
64
  end
66
65
  alias_method_chain :remove, :paranoia
67
- alias :delete :remove_with_paranoia
66
+ alias_method :delete, :remove_with_paranoia
68
67
 
69
68
  # Delete the paranoid +Document+ from the database completely.
70
69
  #
@@ -89,7 +88,7 @@ module Mongoid
89
88
  def destroyed?
90
89
  (@destroyed ||= false) || !!deleted_at
91
90
  end
92
- alias :deleted? :destroyed?
91
+ alias_method :deleted?, :destroyed?
93
92
 
94
93
  def persisted?
95
94
  !new_record? && !(@destroyed ||= false)
@@ -108,10 +107,10 @@ module Mongoid
108
107
  def restore
109
108
  query = paranoid_collection.find(atomic_selector)
110
109
  query.respond_to?(:update_one) ?
111
- query.update_one({ "$unset" => { paranoid_field => true }}) :
112
- query.update({ "$unset" => { paranoid_field => true }})
110
+ query.update_one('$unset' => { paranoid_field => true }) :
111
+ query.update('$unset' => { paranoid_field => true })
113
112
 
114
- attributes.delete("deleted_at")
113
+ attributes.delete('deleted_at')
115
114
  @destroyed = false
116
115
  true
117
116
  end
@@ -132,7 +131,7 @@ module Mongoid
132
131
  #
133
132
  # @since 2.3.1
134
133
  def paranoid_collection
135
- embedded? ? _root.collection : self.collection
134
+ embedded? ? _root.collection : collection
136
135
  end
137
136
 
138
137
  # Get the field to be used for paranoid operations.
@@ -144,7 +143,7 @@ module Mongoid
144
143
  #
145
144
  # @since 2.3.1
146
145
  def paranoid_field
147
- embedded? ? "#{atomic_position}.deleted_at" : "deleted_at"
146
+ embedded? ? "#{atomic_position}.deleted_at" : 'deleted_at'
148
147
  end
149
148
  end
150
149
  end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Paranoia
3
- VERSION = '1.3.0'
3
+ VERSION = '2.0.0'.freeze
4
4
  end
5
5
  end
@@ -1,11 +1,11 @@
1
- $: << File.expand_path('../lib', __FILE__)
1
+ $LOAD_PATH << File.expand_path('../lib', __FILE__)
2
2
  require 'mongoid/paranoia/version'
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = 'mongoid-paranoia'
6
6
  gem.version = Mongoid::Paranoia::VERSION
7
- gem.authors = 'Mario Uher'
8
- gem.email = 'uher.mario@gmail.com'
7
+ gem.authors = ['Durran Jordan', 'Mario Uher']
8
+ gem.email = ['durran@gmail.com', 'uher.mario@gmail.com']
9
9
  gem.homepage = 'https://github.com/haihappen/mongoid-paranoia'
10
10
  gem.summary = 'Extraction of mongoid-paranoia into its own gem.'
11
11
  gem.description = "There may be times when you don't want documents to actually get deleted from the database, but \"flagged\" as deleted."
@@ -1,7 +1,7 @@
1
1
  class Address
2
2
  include Mongoid::Document
3
3
 
4
- field :_id, type: String, default: ->{ street.try(:parameterize) }
4
+ field :_id, type: String, default: -> { street.try(:parameterize) }
5
5
 
6
6
  attr_accessor :mode
7
7
 
@@ -25,10 +25,11 @@ class Address
25
25
 
26
26
  embedded_in :addressable, polymorphic: true do
27
27
  def extension
28
- "Testing"
28
+ 'Testing'
29
29
  end
30
+
30
31
  def doctor?
31
- title == "Dr"
32
+ title == 'Dr'
32
33
  end
33
34
  end
34
35
 
@@ -38,10 +39,10 @@ class Address
38
39
  belongs_to :account
39
40
  belongs_to :band
40
41
 
41
- scope :without_postcode, ->{ where(postcode: nil) }
42
- scope :rodeo, ->{ where(street: "Rodeo Dr") } do
42
+ scope :without_postcode, -> { where(postcode: nil) }
43
+ scope :rodeo, -> { where(street: 'Rodeo Dr') } do
43
44
  def mansion?
44
- all? { |address| address.street == "Rodeo Dr" }
45
+ all? { |address| address.street == 'Rodeo Dr' }
45
46
  end
46
47
  end
47
48
 
@@ -58,11 +59,11 @@ class Address
58
59
 
59
60
  class << self
60
61
  def california
61
- where(state: "CA")
62
+ where(state: 'CA')
62
63
  end
63
64
 
64
65
  def homes
65
- where(address_type: "Home")
66
+ where(address_type: 'Home')
66
67
  end
67
68
 
68
69
  def streets
@@ -3,5 +3,5 @@ class Appointment
3
3
  field :active, type: Boolean, default: true
4
4
  field :timed, type: Boolean, default: true
5
5
  embedded_in :person
6
- default_scope ->{ where(active: true) }
6
+ default_scope -> { where(active: true) }
7
7
  end
@@ -17,7 +17,7 @@ class ParanoidPost
17
17
  has_many :authors, dependent: :delete
18
18
  has_many :titles, dependent: :restrict
19
19
 
20
- scope :recent, ->{ where(created_at: { "$lt" => Time.now, "$gt" => 30.days.ago }) }
20
+ scope :recent, -> { where(created_at: { '$lt' => Time.now, '$gt' => 30.days.ago }) }
21
21
 
22
22
  before_destroy :before_destroy_stub
23
23
  after_destroy :after_destroy_stub
@@ -32,7 +32,7 @@ class ParanoidPost
32
32
 
33
33
  class << self
34
34
  def old
35
- where(created_at: { "$lt" => 30.days.ago })
35
+ where(created_at: { '$lt' => 30.days.ago })
36
36
  end
37
37
  end
38
38
  end
@@ -9,7 +9,7 @@ class Person
9
9
  field :title
10
10
  field :terms, type: Boolean
11
11
  field :pets, type: Boolean, default: false
12
- field :age, type: Integer, default: "100"
12
+ field :age, type: Integer, default: '100'
13
13
  field :dob, type: Date
14
14
  field :employer_id
15
15
  field :lunch_time, type: Time
@@ -17,7 +17,7 @@ class Person
17
17
  field :map, type: Hash
18
18
  field :map_with_default, type: Hash, default: {}
19
19
  field :score, type: Integer
20
- field :blood_alcohol_content, type: Float, default: ->{ 0.0 }
20
+ field :blood_alcohol_content, type: Float, default: -> { 0.0 }
21
21
  field :last_drink_taken_at, type: Date
22
22
  field :ssn
23
23
  field :owner_id, type: Integer
@@ -37,18 +37,19 @@ class Person
37
37
  index name: 1
38
38
  index title: 1
39
39
 
40
- index({ ssn: 1 }, { unique: true })
40
+ index({ ssn: 1 }, unique: true)
41
41
 
42
42
  attr_reader :rescored
43
43
 
44
44
  embeds_many :favorites, order: :title.desc, inverse_of: :perp, validate: false
45
- embeds_many :videos, order: [[ :title, :asc ]], validate: false
46
- embeds_many :phone_numbers, class_name: "Phone", validate: false
45
+ embeds_many :videos, order: [[:title, :asc]], validate: false
46
+ embeds_many :phone_numbers, class_name: 'Phone', validate: false
47
47
  embeds_many :phones, store_as: :mobile_phones, validate: false
48
48
  embeds_many :addresses, as: :addressable, validate: false do
49
49
  def extension
50
- "Testing"
50
+ 'Testing'
51
51
  end
52
+
52
53
  def find_by_street(street)
53
54
  where(street: street).first
54
55
  end
@@ -61,20 +62,21 @@ class Person
61
62
  embeds_many :appointments, validate: false
62
63
 
63
64
  embeds_one :passport, autobuild: true, store_as: :pass, validate: false
64
- embeds_one :pet, class_name: "Animal", validate: false
65
+ embeds_one :pet, class_name: 'Animal', validate: false
65
66
  embeds_one :name, as: :namable, validate: false do
66
67
  def extension
67
- "Testing"
68
+ 'Testing'
68
69
  end
70
+
69
71
  def dawkins?
70
- first_name == "Richard" && last_name == "Dawkins"
72
+ first_name == 'Richard' && last_name == 'Dawkins'
71
73
  end
72
74
  end
73
75
  embeds_one :quiz, validate: false
74
76
 
75
77
  has_one :game, dependent: :destroy, validate: false do
76
78
  def extension
77
- "Testing"
79
+ 'Testing'
78
80
  end
79
81
  end
80
82
 
@@ -83,7 +85,7 @@ class Person
83
85
  dependent: :delete,
84
86
  validate: false do
85
87
  def extension
86
- "Testing"
88
+ 'Testing'
87
89
  end
88
90
  end
89
91
  has_many :ordered_posts, order: :rating.desc, validate: false
@@ -121,9 +123,9 @@ class Person
121
123
  accepts_nested_attributes_for :quiz
122
124
  accepts_nested_attributes_for :services, allow_destroy: true
123
125
 
124
- scope :minor, ->{ where(:age.lt => 18) }
125
- scope :without_ssn, ->{ without(:ssn) }
126
- scope :search, ->(query){ any_of({ title: query }) }
126
+ scope :minor, -> { where(:age.lt => 18) }
127
+ scope :without_ssn, -> { without(:ssn) }
128
+ scope :search, ->(query) { any_of(title: query) }
127
129
 
128
130
  def score_with_rescoring=(score)
129
131
  @rescored = score.to_i + 20
@@ -134,7 +136,7 @@ class Person
134
136
 
135
137
  def update_addresses
136
138
  addresses.each do |address|
137
- address.street = "Updated Address"
139
+ address.street = 'Updated Address'
138
140
  end
139
141
  end
140
142
 
@@ -154,11 +156,13 @@ class Person
154
156
  def accepted
155
157
  scoped.where(terms: true)
156
158
  end
159
+
157
160
  def knight
158
- scoped.where(title: "Sir")
161
+ scoped.where(title: 'Sir')
159
162
  end
163
+
160
164
  def old
161
- scoped.where(age: { "$gt" => 50 })
165
+ scoped.where(age: { '$gt' => 50 })
162
166
  end
163
167
  end
164
168
 
@@ -175,10 +179,10 @@ class Person
175
179
  end
176
180
 
177
181
  def preference_names=(names)
178
- names.split(",").each do |name|
182
+ names.split(',').each do |name|
179
183
  preference = Preference.where(name: name).first
180
184
  if preference
181
- self.preferences << preference
185
+ preferences << preference
182
186
  else
183
187
  preferences.build(name: name)
184
188
  end
@@ -186,7 +190,7 @@ class Person
186
190
  end
187
191
 
188
192
  def set_on_map_with_default=(value)
189
- self.map_with_default["key"] = value
193
+ map_with_default['key'] = value
190
194
  end
191
195
 
192
196
  reset_callbacks(:validate)
@@ -195,4 +199,4 @@ class Person
195
199
  reset_callbacks(:destroy)
196
200
  end
197
201
 
198
- require "app/models/doctor"
202
+ require 'app/models/doctor'
@@ -3,7 +3,7 @@ class Phone
3
3
 
4
4
  attr_accessor :number_in_observer
5
5
 
6
- field :_id, type: String, default: ->{ number }
6
+ field :_id, type: String, default: -> { number }
7
7
 
8
8
  field :number
9
9
  embeds_one :country_code
@@ -5,7 +5,7 @@ class Service
5
5
  field :after_destroy_called, type: Boolean, default: false
6
6
  field :after_initialize_called, type: Boolean, default: false
7
7
  embedded_in :person
8
- belongs_to :target, class_name: "User"
8
+ belongs_to :target, class_name: 'User'
9
9
  validates_numericality_of :sid
10
10
 
11
11
  before_destroy do |doc|
@@ -2,5 +2,5 @@ class Symptom
2
2
  include Mongoid::Document
3
3
  field :name, type: String
4
4
  embedded_in :person
5
- default_scope ->{ asc(:name) }
5
+ default_scope -> { asc(:name) }
6
6
  end
@@ -4,5 +4,5 @@ class Tag
4
4
  has_and_belongs_to_many :actors
5
5
  has_and_belongs_to_many :articles
6
6
  has_and_belongs_to_many :posts
7
- has_and_belongs_to_many :related, class_name: "Tag", inverse_of: :related
7
+ has_and_belongs_to_many :related, class_name: 'Tag', inverse_of: :related
8
8
  end