perpetuity 0.4 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/lib/perpetuity/mapper.rb +8 -3
- data/lib/perpetuity/mongodb.rb +10 -0
- data/lib/perpetuity/version.rb +1 -1
- data/spec/perpetuity/mongodb_spec.rb +7 -1
- data/spec/perpetuity_spec.rb +12 -7
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## Version 0.4.1
|
2
|
+
|
3
|
+
- Add `Mapper#remove_index!` to remove DB indexes
|
4
|
+
- Fix index declarations in mappers to take unique/order options
|
5
|
+
- These were intended to be there from the beginning, but the API wasn't made available in the mapper
|
6
|
+
|
1
7
|
## Version 0.4
|
2
8
|
|
3
9
|
- Mapper select DSL now more closely resembles `Enumerable` syntax
|
data/lib/perpetuity/mapper.rb
CHANGED
@@ -10,8 +10,9 @@ module Perpetuity
|
|
10
10
|
include DataInjectable
|
11
11
|
|
12
12
|
def self.generate_for(klass, &block)
|
13
|
-
mapper = Class.new(base_class
|
13
|
+
mapper = Class.new(base_class)
|
14
14
|
mapper.map klass
|
15
|
+
mapper.instance_exec &block if block_given?
|
15
16
|
end
|
16
17
|
|
17
18
|
def self.map klass
|
@@ -32,8 +33,12 @@ module Perpetuity
|
|
32
33
|
attribute_set.map(&:name)
|
33
34
|
end
|
34
35
|
|
35
|
-
def self.index attribute
|
36
|
-
data_source.index mapped_class, attribute_set[attribute]
|
36
|
+
def self.index attribute, options={}
|
37
|
+
data_source.index mapped_class, attribute_set[attribute], options
|
38
|
+
end
|
39
|
+
|
40
|
+
def remove_index! index
|
41
|
+
data_source.remove_index index
|
37
42
|
end
|
38
43
|
|
39
44
|
def indexes
|
data/lib/perpetuity/mongodb.rb
CHANGED
@@ -140,6 +140,16 @@ module Perpetuity
|
|
140
140
|
index.activate!
|
141
141
|
end
|
142
142
|
|
143
|
+
def remove_index index
|
144
|
+
coll = collection(index.collection)
|
145
|
+
db_indexes = coll.index_information.select do |name, info|
|
146
|
+
name =~ /#{index.attribute}/
|
147
|
+
end
|
148
|
+
if db_indexes.any?
|
149
|
+
collection(index.collection).drop_index db_indexes.first.first
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
143
153
|
private
|
144
154
|
def serializable_types
|
145
155
|
@serializable_types ||= [NilClass, TrueClass, FalseClass, Fixnum, Float, String, Array, Hash, Time]
|
data/lib/perpetuity/version.rb
CHANGED
@@ -119,12 +119,18 @@ module Perpetuity
|
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'creates indexes on the database collection' do
|
122
|
-
mongo.delete_all collection
|
123
122
|
index = mongo.index collection, 'real_index', order: :descending, unique: true
|
124
123
|
mongo.activate_index! index
|
125
124
|
|
126
125
|
mongo.active_indexes(collection).should include index
|
127
126
|
end
|
127
|
+
|
128
|
+
it 'removes indexes' do
|
129
|
+
index = mongo.index collection, 'real_index', order: :descending, unique: true
|
130
|
+
mongo.activate_index! index
|
131
|
+
mongo.remove_index index
|
132
|
+
mongo.active_indexes(collection).should_not include index
|
133
|
+
end
|
128
134
|
end
|
129
135
|
end
|
130
136
|
end
|
data/spec/perpetuity_spec.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'perpetuity'
|
2
|
+
|
3
|
+
mongodb = Perpetuity::MongoDB.new db: 'perpetuity_gem_test'
|
4
|
+
Perpetuity.configure { data_source mongodb }
|
5
|
+
|
2
6
|
require 'test_classes'
|
3
7
|
|
4
8
|
describe Perpetuity do
|
5
|
-
before(:all) do
|
6
|
-
# Use MongoDB for now as its the only one supported.
|
7
|
-
mongodb = Perpetuity::MongoDB.new db: 'perpetuity_gem_test'
|
8
|
-
Perpetuity.configure { data_source mongodb }
|
9
|
-
end
|
10
|
-
|
11
9
|
describe 'mapper generation' do
|
12
10
|
it 'generates mappers' do
|
13
11
|
Perpetuity.generate_mapper_for Object
|
@@ -409,7 +407,7 @@ describe Perpetuity do
|
|
409
407
|
Class.new(Perpetuity::Mapper) do
|
410
408
|
map Object
|
411
409
|
attribute :name
|
412
|
-
index :name
|
410
|
+
index :name, unique: true
|
413
411
|
end
|
414
412
|
end
|
415
413
|
let(:mapper) { mapper_class.new }
|
@@ -419,6 +417,8 @@ describe Perpetuity do
|
|
419
417
|
end
|
420
418
|
end
|
421
419
|
|
420
|
+
after { mapper.data_source.database.drop_collection 'Object' }
|
421
|
+
|
422
422
|
it 'adds indexes to database collections/tables' do
|
423
423
|
name_index.attribute.name.should be == :name
|
424
424
|
end
|
@@ -430,6 +430,11 @@ describe Perpetuity do
|
|
430
430
|
it 'creates indexes' do
|
431
431
|
mapper.reindex!
|
432
432
|
name_index.should be_active
|
433
|
+
mapper.remove_index! name_index
|
434
|
+
end
|
435
|
+
|
436
|
+
it 'specifies uniqueness of the index' do
|
437
|
+
name_index.should be_unique
|
433
438
|
end
|
434
439
|
end
|
435
440
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perpetuity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|