mongoid-uuid 1.0.0 → 1.1.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: b0abaac86a8c23dac35a3484295b612839eb2ebb
4
- data.tar.gz: 5d53bf1275db9562c841228d29e20167d303213e
3
+ metadata.gz: dc79151091e3889ad8aae258fc42bfc97a69145c
4
+ data.tar.gz: a19fc565e632bdc27d97e6dfab604eed7566954b
5
5
  SHA512:
6
- metadata.gz: 2dc5a78674147e1735d6517619a89573c7db200ebaac62a12b59bbe663795fdf4c4f2b684f42d0d144eef6894a5151a978deb8a1121c16831b40c932138fb22e
7
- data.tar.gz: 3a60b5992d3a4d07b2e58dc67064ecad8315a13a8228b6eaee674b71dfae3eaf330d8000149d222a268f37a49662d8cf64e7c077f9d79d9ea55d85e5faa27a12
6
+ metadata.gz: 629ce700e71b8ce08c1f78669019f9dbbe85a06ef607fae2a4e815f41e5efa5a4f8de7b6351a59418aeef3e806b2aa9a8f84e0a5ed7d6f49fad12d26940fe847
7
+ data.tar.gz: 3a22a78054ca630736ca36ec12e3bd37cf459fa3954c1c460d97db2f230e468d0535880c4f2bdba4b02ba98676142163f81842a1a1fdd4f28d403c38ba30499c
@@ -6,12 +6,23 @@ module Mongoid # :nodoc:
6
6
 
7
7
  included do
8
8
  field :uuid
9
- index({:uuid => 1}, {:unique => true})
9
+ index({ uuid: 1 }, unique: true)
10
10
  before_validation :generate_uuid
11
- validates :uuid, :uniqueness => true, :uuid => true
11
+ validates :uuid, uniqueness: true, uuid: true
12
12
  attr_readonly :uuid
13
13
  end
14
14
 
15
+ module ClassMethods
16
+ def uuid_options(*fields)
17
+ options = fields.extract_options!
18
+
19
+ if options[:background_index]
20
+ index_spec = index_specification(uuid: 1)
21
+ index_spec.options[:background] = true
22
+ end
23
+ end
24
+ end
25
+
15
26
  private
16
27
 
17
28
  # Sets unique UUID unless uuid is present.
@@ -2,7 +2,6 @@ module Mongoid
2
2
  module Uuid
3
3
  module Validator
4
4
  class UuidValidator < ActiveModel::EachValidator
5
-
6
5
  # Ensures that every value is of a valid compact UUID format.
7
6
  def validate_each(record, attribute, value)
8
7
  unless Mongoid::Uuid.validate(value)
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Uuid
3
- VERSION = "1.0.0"
3
+ VERSION = '1.1.0'.freeze
4
4
  end
5
5
  end
data/lib/mongoid/uuid.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # encoding: utf-8
2
- require "uuid"
3
- require "mongoid"
4
- require "mongoid/uuid/version"
5
- require "mongoid/uuid/uuid"
6
- require "mongoid/uuid/validator"
2
+ require 'uuid'
3
+ require 'mongoid'
4
+ require 'mongoid/uuid/version'
5
+ require 'mongoid/uuid/uuid'
6
+ require 'mongoid/uuid/validator'
7
7
 
8
8
  module Mongoid
9
9
  module Uuid
@@ -13,9 +13,7 @@ module Mongoid
13
13
  def self.validate(uuid)
14
14
  UUID.validate(uuid)
15
15
  end
16
-
17
16
  end
18
17
  end
19
18
 
20
-
21
19
  ActiveModel::Validations.send(:include, Mongoid::Uuid::Validator)
data/spec/spec_helper.rb CHANGED
@@ -3,16 +3,16 @@ require 'bundler/setup'
3
3
 
4
4
  require 'mongoid'
5
5
  require 'mongoid/uuid'
6
- require 'mongoid-rspec'
6
+
7
7
 
8
8
  require 'rspec'
9
9
 
10
- if ENV["CI"]
11
- require "simplecov"
12
- require "coveralls"
10
+ if ENV['CI']
11
+ require 'simplecov'
12
+ require 'coveralls'
13
13
  SimpleCov.formatter = Coveralls::SimpleCov::Formatter
14
14
  SimpleCov.start do
15
- add_filter "spec"
15
+ add_filter 'spec'
16
16
  end
17
17
  end
18
18
 
@@ -27,7 +27,7 @@ RSpec.configure do |config|
27
27
  c.syntax = :expect
28
28
  end
29
29
  config.include RSpec::Matchers
30
- config.include Mongoid::Matchers
30
+
31
31
  config.mock_with :rspec
32
32
  config.after :all do
33
33
  Mongoid::Config.purge!
data/spec/uuid_spec.rb CHANGED
@@ -1,46 +1,44 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- require "uuid"
3
+ require 'uuid'
4
4
 
5
5
  describe Mongoid::Uuid do
6
- describe "Create with uuid" do
7
- it "create with default uuid" do
6
+ describe 'Create with uuid' do
7
+ it 'create with default uuid' do
8
8
  item = ItemWithUuid.create!(name: 'foo')
9
9
  expect(item.uuid.length).to eq(36)
10
10
  end
11
11
 
12
- it "create with generated uuid" do
12
+ it 'create with generated uuid' do
13
13
  uuid = UUID.generate
14
14
  item = ItemWithUuid.create!(name: 'foo', uuid: uuid)
15
15
  expect(item.uuid).to eq(uuid)
16
16
  end
17
17
 
18
- it "create with invalid uuid exception" do
18
+ it 'create with invalid uuid exception' do
19
19
  invalid_uuid = 'baz-baz1'
20
- expect {
20
+ expect do
21
21
  ItemWithUuid.create!(name: 'foo', uuid: invalid_uuid)
22
- }.to raise_error(Mongoid::Errors::Validations)
22
+ end.to raise_error(Mongoid::Errors::Validations)
23
23
  end
24
24
 
25
- it "create with invalid uuid" do
26
- invalid_uuid = 'baz-baz2'
27
- expect(ItemWithUuid.create(name: 'foo', uuid: invalid_uuid).valid?).to eq(false)
25
+ it 'create with invalid uuid' do
26
+ invalid_uuid = 'baz-baz2'
27
+ expect(ItemWithUuid.create(name: 'foo', uuid: invalid_uuid).valid?).to eq(false)
28
28
  end
29
-
30
29
  end
31
30
 
32
- describe "Test read only uuid" do
33
- it "attempt to remove the uuid" do
34
- expect {
31
+ describe 'Test read only uuid' do
32
+ it 'attempt to remove the uuid' do
33
+ expect do
35
34
  ItemWithUuid.create!(name: 'foo').remove_attribute(:uuid)
36
- }.to raise_error(Mongoid::Errors::ReadonlyAttribute)
35
+ end.to raise_error(Mongoid::Errors::ReadonlyAttribute)
37
36
  end
38
37
 
39
- it "attempt to update the uuid" do
40
- expect {
38
+ it 'attempt to update the uuid' do
39
+ expect do
41
40
  ItemWithUuid.create!(name: 'foo').update_attribute(:uuid, 'baz')
42
- }.to raise_error(Mongoid::Errors::ReadonlyAttribute)
41
+ end.to raise_error(Mongoid::Errors::ReadonlyAttribute)
43
42
  end
44
43
  end
45
-
46
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-uuid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Druzkov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-08 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uuid
@@ -45,13 +45,13 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '6'
47
47
  - !ruby/object:Gem::Dependency
48
- name: yard
48
+ name: rake
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
- type: :development
54
+ type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
@@ -59,7 +59,7 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
- name: rake
62
+ name: yard
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ">="
@@ -73,21 +73,21 @@ dependencies:
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  - !ruby/object:Gem::Dependency
76
- name: rspec
76
+ name: rubocop
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - "~>"
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: '3.0'
81
+ version: '0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - "~>"
86
+ - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: '3.0'
88
+ version: '0'
89
89
  - !ruby/object:Gem::Dependency
90
- name: mongoid-rspec
90
+ name: rspec
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - ">="
128
128
  - !ruby/object:Gem::Version
129
- version: '1.9'
129
+ version: '2.0'
130
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  requirements:
132
132
  - - ">="
@@ -139,6 +139,7 @@ signing_key:
139
139
  specification_version: 4
140
140
  summary: Uuid fields for mongoid
141
141
  test_files:
142
- - spec/spec_helper.rb
143
142
  - spec/uuid_spec.rb
144
143
  - spec/model.rb
144
+ - spec/spec_helper.rb
145
+ has_rdoc: