mongoid-versioning 1.2.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: 49bb27c097cf3fdb0f285754a0a2e76a2bf6a109
4
- data.tar.gz: 77215e96a879e24f61444baf4c756afd6b22f7ab
3
+ metadata.gz: ba0af3d7de417dd975815741af4b9ca7d9a481f1
4
+ data.tar.gz: 12a26c18dc271d597d6416218b6ef5895e3d8aa7
5
5
  SHA512:
6
- metadata.gz: a75794032f6a722cde9d5b4f162d9bcd781df2b918de7a051ebf1350d31e23a928741873f277a434459de694cbc343486480caf1ea03674947d8c58c4772cf27
7
- data.tar.gz: 6c481710e94d7507418aba52b3319c66e3d65e294dfef91bf29315a871ec5b1c0343536b88ba6d9f3e545947602d4bd59a7367968d7226cd9a0b3e3c88e3589a
6
+ metadata.gz: 43b1158de271a86a3a9de372c35c86e99443dc4f3e29c26f0097f16ffb45cee1a82664967743b6729030f36d896ae2db9144387e6a9f61c2e56628e1d61bb355
7
+ data.tar.gz: 9f6ee04088d25cd74a1b5caa3893ae1e8a16fa80d1abc6f62c916fa51896f9370701120e1b2d9bc153f18a60e518e6d419b51a1f110a5001e2a98fdf812720bf
@@ -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,14 @@
1
1
  language: ruby
2
2
  services: mongodb
3
3
 
4
+ before_install:
5
+ - gem install bundler
6
+
4
7
  rvm:
5
- - 1.9.3
6
8
  - 2.0.0
7
9
  - 2.1.0
8
10
  - 2.2.0
11
+ - 2.3.0
9
12
 
10
13
  gemfile:
11
14
  - Gemfile
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # mongoid-versioning [![Build Status](https://travis-ci.org/haihappen/mongoid-versioning.png)](https://travis-ci.org/haihappen/mongoid-versioning)
2
2
 
3
- **Important:** This gem is an extraction of [Mongoid::Versioning](http://mongoid.org/en/mongoid/v3/extras.html#versioning) from the official [mongoid](http://mongoid.org) gem.
3
+ **Important:** This gem is an extraction of [Mongoid::Versioning](http://mongoid.github.io/en/mongoid/docs/extras.html#versioning) from the official [mongoid](http://mongoid.org) gem.
4
4
  Since Mongoid::Versioning was removed in the `4.0.0` release of Mongoid, this gem re-enables the functionality of versioned documents.
5
5
 
6
- **Please submit only bug and security fixes**. Neighter I will accept new features nor changes to existing APIs. Please consider forking the project if you want new features to appear! :)
6
+ **Please submit only bug and security fixes**. Neither I will accept new features nor changes to existing APIs. Please consider forking the project if you want new features to appear! :)
7
7
 
8
8
  ---
9
9
 
@@ -58,7 +58,7 @@ end
58
58
 
59
59
  (The MIT license)
60
60
 
61
- Copyright (c) 2013-2015 Mario Uher
61
+ Copyright (c) 2009-2013 Durran Jordan, 2013-2015 Mario Uher
62
62
 
63
63
  Permission is hereby granted, free of charge, to any person obtaining
64
64
  a copy of this software and associated documentation files (the
@@ -1,10 +1,8 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
3
  module Errors
4
-
5
4
  # This error is raised when attempting to version an embedded document.
6
5
  class VersioningNotOnRoot < MongoidError
7
-
8
6
  # Create the new error.
9
7
  #
10
8
  # @example Create the new error.
@@ -15,7 +13,7 @@ module Mongoid
15
13
  # @since 3.0.0
16
14
  def initialize(klass)
17
15
  super(
18
- compose_message("versioning_not_on_root", { klass: klass })
16
+ compose_message('versioning_not_on_root', klass: klass)
19
17
  )
20
18
  end
21
19
  end
@@ -10,11 +10,10 @@ module Mongoid
10
10
  # @since 2.0.0.rc.1
11
11
  def cascade!
12
12
  cascades.each do |name|
13
- if !relation_metadata || !relation_metadata.versioned?
14
- if meta = relations[name]
15
- strategy = meta.cascade_strategy
16
- strategy.new(self, meta).cascade if strategy
17
- end
13
+ next unless !relation_metadata || !relation_metadata.versioned?
14
+ if meta = relations[name]
15
+ strategy = meta.cascade_strategy
16
+ strategy.new(self, meta).cascade if strategy
18
17
  end
19
18
  end
20
19
  end
@@ -12,22 +12,22 @@ module Mongoid
12
12
  #
13
13
  # @since 2.0.0.rc.1
14
14
  def inspect
15
- %Q{#<Mongoid::Relations::Metadata
16
- autobuild: #{autobuilding?}
17
- class_name: #{class_name}
18
- cyclic: #{cyclic.inspect}
19
- counter_cache:#{counter_cached?}
20
- dependent: #{dependent.inspect}
21
- inverse_of: #{inverse_of.inspect}
22
- key: #{key}
23
- macro: #{macro}
24
- name: #{name}
25
- order: #{order.inspect}
26
- polymorphic: #{polymorphic?}
27
- relation: #{relation}
28
- setter: #{setter}
29
- versioned: #{versioned?}>
30
- }
15
+ %(#<Mongoid::Relations::Metadata
16
+ autobuild: #{autobuilding?}
17
+ class_name: #{class_name}
18
+ cyclic: #{cyclic.inspect}
19
+ counter_cache:#{counter_cached?}
20
+ dependent: #{dependent.inspect}
21
+ inverse_of: #{inverse_of.inspect}
22
+ key: #{key}
23
+ macro: #{macro}
24
+ name: #{name}
25
+ order: #{order.inspect}
26
+ polymorphic: #{polymorphic?}
27
+ relation: #{relation}
28
+ setter: #{setter}
29
+ versioned: #{versioned?}>
30
+ )
31
31
  end
32
32
 
33
33
  # Is this relation using Mongoid's internal versioning system?
@@ -2,6 +2,7 @@ module Mongoid
2
2
  module Threaded
3
3
  module Lifecycle
4
4
  private
5
+
5
6
  # Execute a block in loading revision mode.
6
7
  #
7
8
  # @example Execute in loading revision mode.
@@ -13,10 +14,10 @@ module Mongoid
13
14
  #
14
15
  # @since 2.3.4
15
16
  def _loading_revision
16
- Threaded.begin_execution("load_revision")
17
+ Threaded.begin_execution('load_revision')
17
18
  yield
18
19
  ensure
19
- Threaded.exit_execution("load_revision")
20
+ Threaded.exit_execution('load_revision')
20
21
  end
21
22
 
22
23
  module ClassMethods
@@ -29,7 +30,7 @@ module Mongoid
29
30
  #
30
31
  # @since 2.3.4
31
32
  def _loading_revision?
32
- Threaded.executing?("load_revision")
33
+ Threaded.executing?('load_revision')
33
34
  end
34
35
  end
35
36
  end
@@ -1,6 +1,5 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid
3
-
4
3
  # Include this module to get automatic versioning of root level documents.
5
4
  # This will add a version field to the +Document+ and a has_many association
6
5
  # with all the versions contained in it.
@@ -12,7 +11,7 @@ module Mongoid
12
11
 
13
12
  embeds_many \
14
13
  :versions,
15
- class_name: self.name,
14
+ class_name: name,
16
15
  validate: false,
17
16
  cyclic: true,
18
17
  inverse_of: nil,
@@ -42,19 +41,20 @@ module Mongoid
42
41
  )
43
42
  new_version._id = nil
44
43
  if version_max.present? && versions.length > version_max
45
- deleted = versions.first
46
- if deleted.respond_to?(:paranoid?) && deleted.paranoid?
47
- versions.delete_one(deleted)
44
+ to_delete = versions.first
45
+ version_to_delete = to_delete.version
46
+ if to_delete.respond_to?(:paranoid?) && to_delete.paranoid?
47
+ versions.delete_one(to_delete)
48
48
 
49
49
  query = collection.find(atomic_selector)
50
50
  query.respond_to?(:update_one) ?
51
- query.update_one({ "$pull" => { "versions" => { "version" => deleted.version }}}) :
52
- query.update({ "$pull" => { "versions" => { "version" => deleted.version }}})
51
+ query.update_one('$pull' => { 'versions' => { 'version' => version_to_delete } }) :
52
+ query.update('$pull' => { 'versions' => { 'version' => version_to_delete } })
53
53
  else
54
- versions.delete(deleted)
54
+ versions.where(version: version_to_delete).delete_all
55
55
  end
56
56
  end
57
- self.version = (version || 1 ) + 1
57
+ self.version = (version || 1) + 1
58
58
  end
59
59
  end
60
60
 
@@ -70,7 +70,7 @@ module Mongoid
70
70
  (previous_revision || self).versioned_attributes
71
71
  )
72
72
  versions.shift if version_max.present? && versions.length > version_max
73
- self.version = (version || 1 ) + 1
73
+ self.version = (version || 1) + 1
74
74
  save
75
75
  end
76
76
 
@@ -81,7 +81,7 @@ module Mongoid
81
81
  #
82
82
  # @since 2.1.0
83
83
  def versioned_changes
84
- only_versioned_attributes(changes.except("updated_at"))
84
+ only_versioned_attributes(changes.except('updated_at'))
85
85
  end
86
86
 
87
87
  # Filters the results of +attributes+ by removing any fields that should
@@ -134,15 +134,15 @@ module Mongoid
134
134
  # @todo Remove Mongoid 4 support.
135
135
  # @since 2.0.0
136
136
  def previous_revision
137
- options = self.respond_to?(:mongo_client) ?
138
- self.mongo_client.options.symbolize_keys :
139
- self.mongo_session.options
137
+ options = respond_to?(:mongo_client) ?
138
+ mongo_client.options.symbolize_keys :
139
+ mongo_session.options
140
140
 
141
141
  _loading_revision do
142
- self.class.unscoped.
143
- with(options).
144
- where(_id: id).
145
- any_of({ version: version }, { version: nil }).first
142
+ self.class.unscoped
143
+ .with(options)
144
+ .where(_id: id)
145
+ .any_of({ version: version }, version: nil).first
146
146
  end
147
147
  end
148
148
 
@@ -182,7 +182,7 @@ module Mongoid
182
182
  # @since 2.1.0
183
183
  def only_versioned_attributes(hash)
184
184
  versioned = {}
185
- hash.except("versions").each_pair do |name, value|
185
+ hash.except('versions').each_pair do |name, value|
186
186
  add_versioned_attribute(versioned, name, value)
187
187
  end
188
188
  versioned
@@ -210,7 +210,6 @@ module Mongoid
210
210
  end
211
211
 
212
212
  module ClassMethods
213
-
214
213
  # Sets the maximum number of versions to store.
215
214
  #
216
215
  # @example Set the maximum.
@@ -1,18 +1,18 @@
1
- require "mongoid/core_ext/errors/versioning_not_on_root.rb"
2
- require "mongoid/core_ext/fields/standard.rb"
3
- require "mongoid/core_ext/fields/validators/macro.rb"
4
- require "mongoid/core_ext/hierarchy.rb"
5
- require "mongoid/core_ext/relations/bindings/embedded/many.rb"
6
- require "mongoid/core_ext/relations/cascading.rb"
7
- require "mongoid/core_ext/relations/embedded/batchable.rb"
8
- require "mongoid/core_ext/relations/embedded/many.rb"
9
- require "mongoid/core_ext/relations/macros.rb"
10
- require "mongoid/core_ext/relations/metadata.rb"
11
- require "mongoid/core_ext/relations/options.rb"
12
- require "mongoid/core_ext/threaded/lifecycle.rb"
13
- require "mongoid/core_ext/versioning.rb"
1
+ require 'mongoid/core_ext/errors/versioning_not_on_root.rb'
2
+ require 'mongoid/core_ext/fields/standard.rb'
3
+ require 'mongoid/core_ext/fields/validators/macro.rb'
4
+ require 'mongoid/core_ext/hierarchy.rb'
5
+ require 'mongoid/core_ext/relations/bindings/embedded/many.rb'
6
+ require 'mongoid/core_ext/relations/cascading.rb'
7
+ require 'mongoid/core_ext/relations/embedded/batchable.rb'
8
+ require 'mongoid/core_ext/relations/embedded/many.rb'
9
+ require 'mongoid/core_ext/relations/macros.rb'
10
+ require 'mongoid/core_ext/relations/metadata.rb'
11
+ require 'mongoid/core_ext/relations/options.rb'
12
+ require 'mongoid/core_ext/threaded/lifecycle.rb'
13
+ require 'mongoid/core_ext/versioning.rb'
14
14
 
15
- I18n.load_path << File.join(File.dirname(__FILE__), "config", "locales", "en.yml")
15
+ I18n.load_path << File.join(File.dirname(__FILE__), 'config', 'locales', 'en.yml')
16
16
 
17
17
  module Mongoid
18
18
  module Versioning
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Versioning
3
- VERSION = '1.2.0'
3
+ VERSION = '2.0.0'.freeze
4
4
  end
5
5
  end
@@ -1,14 +1,14 @@
1
- $: << File.expand_path('../lib', __FILE__)
1
+ $LOAD_PATH << File.expand_path('../lib', __FILE__)
2
2
  require 'mongoid/versioning/version'
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = 'mongoid-versioning'
6
6
  gem.version = Mongoid::Versioning::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-versioning'
10
10
  gem.summary = 'Extraction of mongoid-versioning into its own gem.'
11
- gem.description = "Mongoid supports simple versioning through inclusion of the Mongoid::Versioning module."
11
+ gem.description = 'Mongoid supports simple versioning through inclusion of the Mongoid::Versioning module.'
12
12
  gem.licenses = ['MIT']
13
13
 
14
14
  gem.files = `git ls-files`.split("\n")
@@ -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
@@ -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
@@ -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
@@ -10,6 +10,6 @@ class WikiPage
10
10
  max_versions 5
11
11
 
12
12
  has_many :comments, dependent: :destroy, validate: false
13
- has_many :child_pages, class_name: "WikiPage", dependent: :delete, inverse_of: :parent_pages
14
- belongs_to :parent_pages, class_name: "WikiPage", inverse_of: :child_pages
13
+ has_many :child_pages, class_name: 'WikiPage', dependent: :delete, inverse_of: :parent_pages
14
+ belongs_to :parent_pages, class_name: 'WikiPage', inverse_of: :child_pages
15
15
  end
@@ -1,28 +1,26 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Mongoid::Errors::VersioningNotOnRoot do
4
-
5
- describe "#message" do
6
-
4
+ describe '#message' do
7
5
  let(:error) do
8
6
  described_class.new(Address)
9
7
  end
10
8
 
11
- it "contains the problem in the message" do
9
+ it 'contains the problem in the message' do
12
10
  expect(error.message).to include(
13
- "Versioning not allowed on embedded document: Address."
11
+ 'Versioning not allowed on embedded document: Address.'
14
12
  )
15
13
  end
16
14
 
17
- it "contains the summary in the message" do
15
+ it 'contains the summary in the message' do
18
16
  expect(error.message).to include(
19
- "Mongoid::Versioning behaviour is only allowed on documents"
17
+ 'Mongoid::Versioning behaviour is only allowed on documents'
20
18
  )
21
19
  end
22
20
 
23
- it "contains the resolution in the message" do
21
+ it 'contains the resolution in the message' do
24
22
  expect(error.message).to include(
25
- "Remove the versioning from the embedded Address"
23
+ 'Remove the versioning from the embedded Address'
26
24
  )
27
25
  end
28
26
  end