fixturize 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/fixturize.rb +16 -28
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWY0MTQ2YWI0NTg4YWU1MGE0ZmNmYjZkYjc3MGQ2NzViYjE3ZWY0Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmFlMGQ4OTlkOTZmNGQxM2Q3MzA0YjUxNDUxMGY2MTI0ODg3MzQ1Yg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MGVjZmFiMjE2NTZhY2RkNDQ3ZjQ4YmYzOGU3M2E0NWI2NGFlYWRjOWNjYjIz
|
10
|
+
NDhmZjhlZDY3NmMxMWViMWMyMmJhMjczMmVhOWFmODk2ZmM3MTMyMmU5ZjBj
|
11
|
+
MzYxNzc1NzkyZGQ5NzZmMGIyZGYyNjA5ZDA4NjExNTQxNzQ5ODY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTJiNmY3Y2RlYzI2ZTdjOWMxNmY1ZTc4M2QwNDAzY2QzMTRlMWQzMDUyYTJm
|
14
|
+
Mzk5ZjVhMzY5ZDU2NGZjZTM4ZTRiNDE5OGI1ZjVkYmQ3ZjEwMjY5Y2QzNWQw
|
15
|
+
YWZmOTUwYWU0NTVkY2ZmZDA3ZjIyNzI3YzAwZDVjMjZlZWM2ODU=
|
data/lib/fixturize.rb
CHANGED
@@ -12,6 +12,11 @@ class Fixturize
|
|
12
12
|
:rename,
|
13
13
|
]
|
14
14
|
|
15
|
+
INSERT_TYPES = [
|
16
|
+
INSTRUMENT_DATABASE = "instrument_database",
|
17
|
+
INSTRUMENT_IVARS = "instrument_ivar"
|
18
|
+
]
|
19
|
+
|
15
20
|
class << self
|
16
21
|
attr_accessor :database
|
17
22
|
attr_accessor :current_instrumentation
|
@@ -25,35 +30,16 @@ class Fixturize
|
|
25
30
|
@database_version = nil
|
26
31
|
end
|
27
32
|
|
28
|
-
def
|
29
|
-
[
|
30
|
-
db_updates_collection_name,
|
31
|
-
db_saved_ivars_collection_name,
|
32
|
-
]
|
33
|
-
end
|
34
|
-
|
35
|
-
def db_updates_collection_name
|
33
|
+
def collection_name
|
36
34
|
"mongo_saved_contexts_#{database_version}_"
|
37
35
|
end
|
38
36
|
|
39
|
-
def
|
40
|
-
"mongo_saved_ivars_#{database_version}_"
|
41
|
-
end
|
42
|
-
|
43
|
-
def saved_contexts_collection
|
44
|
-
if !database
|
45
|
-
raise "Fixturize is not yet setup! Make sure the database is set!"
|
46
|
-
end
|
47
|
-
|
48
|
-
database.collection(db_updates_collection_name)
|
49
|
-
end
|
50
|
-
|
51
|
-
def saved_ivars_collection
|
37
|
+
def collection
|
52
38
|
if !database
|
53
39
|
raise "Fixturize is not yet setup! Make sure the database is set!"
|
54
40
|
end
|
55
41
|
|
56
|
-
database.collection(
|
42
|
+
database.collection(collection_name)
|
57
43
|
end
|
58
44
|
|
59
45
|
def clear_cache!
|
@@ -65,7 +51,8 @@ class Fixturize
|
|
65
51
|
end
|
66
52
|
|
67
53
|
def instrument_database(collection_name, method_name, *args)
|
68
|
-
|
54
|
+
collection.insert_aliased_from_mongo_saved_context({
|
55
|
+
:type => INSTRUMENT_DATABASE,
|
69
56
|
:name => current_instrumentation,
|
70
57
|
:collection_name => collection_name.to_s,
|
71
58
|
:method_name => method_name.to_s,
|
@@ -79,7 +66,8 @@ class Fixturize
|
|
79
66
|
|
80
67
|
# TODO: Use duck typing?
|
81
68
|
if defined?(MongoMapper) && obj.kind_of?(MongoMapper::Document)
|
82
|
-
|
69
|
+
collection.insert({
|
70
|
+
:type => INSTRUMENT_IVARS,
|
83
71
|
:name => current_instrumentation,
|
84
72
|
:ivar => ivar,
|
85
73
|
:model => obj.class.to_s,
|
@@ -106,9 +94,9 @@ class Fixturize
|
|
106
94
|
|
107
95
|
def refresh!(name = nil)
|
108
96
|
if name
|
109
|
-
|
97
|
+
collection.remove({ :name => name.to_s })
|
110
98
|
else
|
111
|
-
|
99
|
+
collection.drop()
|
112
100
|
end
|
113
101
|
end
|
114
102
|
|
@@ -124,8 +112,8 @@ class Fixturize
|
|
124
112
|
|
125
113
|
name = name.to_s
|
126
114
|
self.current_instrumentation = name
|
127
|
-
db_instrumentations =
|
128
|
-
ivar_instrumentations =
|
115
|
+
db_instrumentations = collection.find({ :name => name, :type => INSTRUMENT_DATABASE }).to_a
|
116
|
+
ivar_instrumentations = collection.find({ :name => name, :type => INSTRUMENT_IVARS }).to_a
|
129
117
|
|
130
118
|
if db_instrumentations.any? || ivar_instrumentations.any?
|
131
119
|
uninstall!
|