fixturize 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/fixturize.rb +50 -43
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDc5MWIxMDQzMGRiM2VlMTg4MmU5NzM4MWYxYTY1MWE3N2E5OTRlZg==
4
+ OThmZTgwNzhmOWFiMzZhMWE2YWFmOGRiODM4NDdkMmRmMzI5ZWVkMw==
5
5
  data.tar.gz: !binary |-
6
- NmVhMTJhZmNhNWZmMTZkYzQ2NTU4YjI2Yzc4NzNjNjYyMjBhNTA2NA==
6
+ ZDhiMGU0NTJjZjIxZDAxYzFhNzE0YTliNzUyMzNkZGRhYjM0Zjk0Mg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZWVmY2I0OWU5NGE0YWFmMzZhOWYxMDJhM2M1NTFjOTk2NTk5Y2NiYjgxYjU2
10
- MmNiNzAwZTYwZGYwMmY1NGQwZTJiMTUxYzdjYjI2M2IyODA5NTUxNWJmOTZl
11
- NzU1MmQ2OGUxOGU1MjEyNjNmNGM4NGYyNDdhNTc0Y2Y2MTQ2Mjc=
9
+ NGEyYmZmNjQzYmM2MGFkNDQwNjAxNjNjNGU3YmQ1N2Q0YzcwY2ExZjFlNzAw
10
+ MzE5NzhmYzc0NzNmMTAzMjRkN2UzYmNjNGZiYWExZjgxNTEwZDk1N2NhNTQw
11
+ NzRjNDNkYjQ0MDQxZThhNjQ0OGI5NDU4MWNjMThmOTY3MWFkOGU=
12
12
  data.tar.gz: !binary |-
13
- NDU5YzE5OTJiYmZmMTU4NjhlYjljZjhhNWUyNGVjZGE3OGE2OWViM2Y5ODMz
14
- MmFkOWI1Yjg2ZmU0ZTE3MzdmNWQyN2FhMjEyMWZlOTYxZGI5MGNjM2QwZTUy
15
- Y2ZlZTQxNjljMDJmN2I1OWNjNTIwZGY2Y2VhNjczZWU5NzI5YjY=
13
+ N2EwOTU4NGVhYmQwNTExYTA4NjQ0MDM1ZDFjZDUyNDA2YjY5ZGYyZjZhM2Ri
14
+ NzZiMmM4ODMxMDE4Y2JiZmUxNTBlMmU5MWQ3NDgxMWIxMTE1MGNiYjZmY2I5
15
+ OTAxMDYyZTdhNjdjZGY2MGNiZTU1NjRlMTgzMTBmY2QzOGU0MDg=
data/lib/fixturize.rb CHANGED
@@ -20,8 +20,13 @@ class Fixturize
20
20
  class << self
21
21
  attr_accessor :database
22
22
  attr_accessor :current_instrumentation
23
+ attr_accessor :enabled
23
24
  attr_writer :database_version
24
25
 
26
+ def enabled?
27
+ enabled ? true : false
28
+ end
29
+
25
30
  def database_version
26
31
  @database_version ||= 0
27
32
  end
@@ -50,48 +55,6 @@ class Fixturize
50
55
  end
51
56
  end
52
57
 
53
- def instrument_database(collection_name, method_name, *args)
54
- collection.insert_aliased_from_fixturize({
55
- :type => INSTRUMENT_DATABASE,
56
- :name => current_instrumentation,
57
- :collection_name => collection_name.to_s,
58
- :method_name => method_name.to_s,
59
- :args => YAML.dump(args)
60
- })
61
- end
62
-
63
- def instrument_ivars(ivars, context)
64
- ivars.each do |ivar|
65
- obj = context.instance_variable_get(ivar)
66
-
67
- # TODO: Use duck typing?
68
- if defined?(MongoMapper) && obj.kind_of?(MongoMapper::Document)
69
- collection.insert_aliased_from_fixturize({
70
- :type => INSTRUMENT_IVARS,
71
- :name => current_instrumentation,
72
- :ivar => ivar,
73
- :model => obj.class.to_s,
74
- :id => obj.id
75
- })
76
- end
77
- end
78
- end
79
-
80
- def load_data_from(instrumentation)
81
- collection = database.collection(instrumentation['collection_name'])
82
- collection.send(instrumentation['method_name'], *YAML.load(instrumentation['args']))
83
- end
84
-
85
- def load_ivars_from(instrumentation, target_obj)
86
- ivar = instrumentation['ivar']
87
- model_str = instrumentation['model']
88
- id = instrumentation['id']
89
-
90
- model = Object.const_get(model_str)
91
- obj = model.find(id)
92
- target_obj.instance_variable_set(ivar, obj)
93
- end
94
-
95
58
  def refresh!(name = nil)
96
59
  if name
97
60
  collection.remove({ :name => name.to_s })
@@ -101,6 +64,8 @@ class Fixturize
101
64
  end
102
65
 
103
66
  def fixturize(name = nil, &block)
67
+ return yield if !enabled?
68
+
104
69
  if !name && block.respond_to?(:source_location)
105
70
  # is this portable?
106
71
  name = block.source_location.join(":")
@@ -133,8 +98,50 @@ class Fixturize
133
98
  end
134
99
  end
135
100
 
101
+ def _instrument_database(collection_name, method_name, *args)
102
+ collection.insert_aliased_from_fixturize({
103
+ :type => INSTRUMENT_DATABASE,
104
+ :name => current_instrumentation,
105
+ :collection_name => collection_name.to_s,
106
+ :method_name => method_name.to_s,
107
+ :args => YAML.dump(args)
108
+ })
109
+ end
110
+
136
111
  private
137
112
 
113
+ def instrument_ivars(ivars, context)
114
+ ivars.each do |ivar|
115
+ obj = context.instance_variable_get(ivar)
116
+
117
+ # TODO: Use duck typing?
118
+ if defined?(MongoMapper) && obj.kind_of?(MongoMapper::Document)
119
+ collection.insert_aliased_from_fixturize({
120
+ :type => INSTRUMENT_IVARS,
121
+ :name => current_instrumentation,
122
+ :ivar => ivar,
123
+ :model => obj.class.to_s,
124
+ :id => obj.id
125
+ })
126
+ end
127
+ end
128
+ end
129
+
130
+ def load_data_from(instrumentation)
131
+ collection = database.collection(instrumentation['collection_name'])
132
+ collection.send(instrumentation['method_name'], *YAML.load(instrumentation['args']))
133
+ end
134
+
135
+ def load_ivars_from(instrumentation, target_obj)
136
+ ivar = instrumentation['ivar']
137
+ model_str = instrumentation['model']
138
+ id = instrumentation['id']
139
+
140
+ model = Object.const_get(model_str)
141
+ obj = model.find(id)
142
+ target_obj.instance_variable_set(ivar, obj)
143
+ end
144
+
138
145
  def caller_of_block(block)
139
146
  block.binding.eval("self")
140
147
  end
@@ -153,7 +160,7 @@ class Fixturize
153
160
  alias_method :#{method_name}_aliased_from_fixturize, :#{method_name}
154
161
 
155
162
  def #{method_name}(*args, &block)
156
- Fixturize.instrument_database(@name, :#{method_name}, *args, &block)
163
+ Fixturize._instrument_database(@name, :#{method_name}, *args, &block)
157
164
  #{method_name}_aliased_from_fixturize(*args, &block)
158
165
  end
159
166
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixturize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Taylor