mack-data_factory 0.6.1.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +22 -23
- data/doc/classes/Kernel.html +15 -15
- data/doc/classes/Mack.html +0 -6
- data/doc/classes/Mack/Data/Bridge.html +36 -36
- data/doc/classes/Mack/Data/Factory/ClassMethods.html +44 -16
- data/doc/classes/Mack/Data/Factory/FieldContentGenerator.html +324 -305
- data/doc/classes/Mack/Data/Field.html +81 -77
- data/doc/classes/Mack/Data/FieldMgr.html +23 -23
- data/doc/classes/Mack/Data/OrmBridge/ActiveRecord.html +36 -36
- data/doc/classes/Mack/Data/OrmBridge/DataMapper.html +36 -36
- data/doc/classes/Mack/Data/OrmBridge/Default.html +45 -45
- data/doc/created.rid +1 -1
- data/doc/files/README.html +1 -1
- data/doc/files/lib/mack-data_factory/content_generator_rb.html +8 -1
- data/doc/files/lib/mack-data_factory/core_extensions/kernel_rb.html +1 -1
- data/doc/files/lib/mack-data_factory/data_factory_rb.html +1 -1
- data/doc/files/lib/mack-data_factory/field_manager_rb.html +1 -1
- data/doc/files/lib/mack-data_factory/field_rb.html +1 -1
- data/doc/files/lib/mack-data_factory/orm_api_bridge/bridge_rb.html +1 -1
- data/doc/files/lib/mack-data_factory/orm_api_bridge/orm/default_rb.html +1 -1
- data/doc/fr_class_index.html +0 -5
- data/doc/fr_method_index.html +50 -49
- data/lib/mack-data_factory/content_generator.rb +22 -7
- data/lib/mack-data_factory/core_extensions/kernel.rb +1 -1
- data/lib/mack-data_factory/data_factory.rb +11 -4
- data/lib/mack-data_factory/field.rb +18 -14
- data/lib/mack-data_factory/field_manager.rb +3 -3
- data/lib/mack-data_factory/orm_api_bridge/bridge.rb +1 -1
- data/lib/mack-data_factory/orm_api_bridge/orm/default.rb +18 -18
- metadata +2 -2
data/README
CHANGED
@@ -16,34 +16,36 @@ Let's say that I have 2 models: Item and User, and Item belongs to user. So the
|
|
16
16
|
class ItemFactory
|
17
17
|
include Mack::Data::Factory
|
18
18
|
|
19
|
-
field :title, "MyItem"
|
20
|
-
|
19
|
+
field :title, :default => "MyItem"
|
20
|
+
association :owner_id, {:user => 'id'}
|
21
21
|
end
|
22
22
|
|
23
23
|
class UserFactory
|
24
24
|
include Mack::Data::Factory
|
25
25
|
|
26
|
-
field :username, "planters", :length => 25, :content => :alpha
|
27
|
-
field :password, "roastedPeanuts", :immutable => true
|
26
|
+
field :username, :default => "planters", :length => 25, :content => :alpha
|
27
|
+
field :password, :default => "roastedPeanuts", :immutable => true
|
28
28
|
end
|
29
29
|
|
30
|
-
So, the 2 classes above defined the factory for item and user. As you can see, each factory will need to explicitly
|
31
|
-
|
30
|
+
So, the 2 classes above defined the factory for item and user. As you can see, each factory will need to explicitly list all the fields that it will populate, and for each field, you can define rules on how the content is generated.
|
31
|
+
|
32
32
|
Important: For each field defined in the factory, you will need to make sure that there's a corresponding setter
|
33
33
|
method in the model class (e.g. Item class is required to have title= and owner_id=).
|
34
34
|
|
35
|
-
For numeric content, you can specify the start number and end number, and the content generator will generate a random number
|
36
|
-
between that range.
|
35
|
+
For numeric content, you can specify the start number and end number, and the content generator will generate a random number between that range.
|
37
36
|
|
38
|
-
For all fields, you can specify :immutable to true, which means for all instances created, the
|
39
|
-
will not change.
|
37
|
+
For all fields, you can specify :immutable to true, which means for all instances created, the default value for that field will not change.
|
40
38
|
|
39
|
+
To define a default value for a field, you use the :default options (e.g. field :username, :default => 'planters')
|
41
40
|
|
42
41
|
Supported content types:
|
43
42
|
# Strings and Numbers
|
44
43
|
- :alpha --> alphabets. rules: [:length, :min_length, :max_length]
|
45
44
|
- :alphanumeric --> alphabets and number. rules: same as :alpha
|
46
45
|
- :numeric --> numbers [optional, because if the field's default value is number, its content type will automatically set to numeric)
|
46
|
+
# Time and Money
|
47
|
+
- :time --> generate random time object. rules: [:start_time, :end_time]. It will generate random time between the given start and end time if available, otherwise it'll generate random time between 'now' and 1 day from 'now'
|
48
|
+
- :money --> generate random amount of money. rules: [:min, :max]. It will generate random money amount (of BigDecimal type) between the given min and max amount.
|
47
49
|
# Internet related content
|
48
50
|
- :email --> generate random email address
|
49
51
|
- :username --> generate random username
|
@@ -69,21 +71,18 @@ Supported content types:
|
|
69
71
|
class ItemFactory
|
70
72
|
include Mack::Data::Factory
|
71
73
|
|
72
|
-
field :title, "MyItem"
|
73
|
-
|
74
|
+
field :title, :default => "MyItem"
|
75
|
+
association :owner_id, {:user => 'id'}, :first
|
74
76
|
end
|
75
77
|
|
76
78
|
class UserFactory
|
77
79
|
include Mack::Data::Factory
|
78
80
|
|
79
|
-
field :username, "planters", :length => 25, :content => :alpha
|
80
|
-
field :password, "roastedPeanuts", :immutable => true
|
81
|
+
field :username, :default => "planters", :length => 25, :content => :alpha
|
82
|
+
field :password, :default => "roastedPeanuts", :immutable => true
|
81
83
|
end
|
82
84
|
|
83
|
-
In the above example, the ItemFactory define the owner_id field
|
84
|
-
it will generate value for owner_id as 'the id of the user #x'. You can also pass in rules to define which instance
|
85
|
-
of user that the id will be retrieved from. The rules are: :first, :last, :random, and :spread. The default is :spread.
|
86
|
-
Definition of the association rules:
|
85
|
+
In the above example, the ItemFactory define the owner_id field as an association to {:user => 'id'}. When the factory is run, it will generate value for owner_id as 'the id of the user #x'. You can also pass in rules to define which instance of user that the id will be retrieved from. The rules are: :first, :last, :random, and :spread. The default is :spread. Definition of the association rules:
|
87
86
|
:first --> always associate with the first object that this object belongs to. If there are 10 users [id = 0 - 10], then the item will always get associated with user #0 (i.e. item's owner_id always == 0)
|
88
87
|
:last --> always associate with the last object that this object belongs to. If there are 10 users [id = 0 - 10], then the item will always get associated with user #10 (i.e. item's owner_id always == 9)
|
89
88
|
:random --> always associate with the Nth object that this object belongs to (and N is random). If there are 10 users [id = 0 - 10], then the item will get associated with user #n (i.e. item's owner_id == rand(10))
|
@@ -121,11 +120,11 @@ the following:
|
|
121
120
|
class UserFactory
|
122
121
|
include Mack::Data::Factory
|
123
122
|
|
124
|
-
field :username, "planters", :length => 25, :content => :alpha
|
125
|
-
field :password, "roastedPeanuts", :immutable => true
|
123
|
+
field :username, :default => "planters", :length => 25, :content => :alpha
|
124
|
+
field :password, :default => "roastedPeanuts", :immutable => true
|
126
125
|
|
127
126
|
scope_for(:long_username) do
|
128
|
-
field :username, "planters", :length => 128, :content => :alpha
|
127
|
+
field :username, :default => "planters", :length => 128, :content => :alpha
|
129
128
|
end
|
130
129
|
end
|
131
130
|
|
@@ -147,10 +146,10 @@ accomplish that:
|
|
147
146
|
class UserFactory
|
148
147
|
include Mack::Data::Factory
|
149
148
|
|
150
|
-
field :username, "planters" do |def_value, rules, index|
|
149
|
+
field :username, :default => "planters" do |def_value, rules, index|
|
151
150
|
"#{def_value}#{index}"
|
152
151
|
end
|
153
|
-
field :password, "roastedPeanuts", :immutable => true
|
152
|
+
field :password, :default => "roastedPeanuts", :immutable => true
|
154
153
|
|
155
154
|
end
|
156
155
|
|
data/doc/classes/Kernel.html
CHANGED
@@ -80,8 +80,8 @@
|
|
80
80
|
<h3 class="section-bar">Methods</h3>
|
81
81
|
|
82
82
|
<div class="name-list">
|
83
|
-
<a href="#
|
84
|
-
<a href="#
|
83
|
+
<a href="#M000052">factories</a>
|
84
|
+
<a href="#M000053">run_factories</a>
|
85
85
|
</div>
|
86
86
|
</div>
|
87
87
|
|
@@ -103,11 +103,11 @@
|
|
103
103
|
<div id="methods">
|
104
104
|
<h3 class="section-bar">Public Instance methods</h3>
|
105
105
|
|
106
|
-
<div id="method-
|
107
|
-
<a name="
|
106
|
+
<div id="method-M000052" class="method-detail">
|
107
|
+
<a name="M000052"></a>
|
108
108
|
|
109
109
|
<div class="method-heading">
|
110
|
-
<a href="#
|
110
|
+
<a href="#M000052" class="method-signature">
|
111
111
|
<span class="method-name">factories</span><span class="method-args">(tag, &block)</span>
|
112
112
|
</a>
|
113
113
|
</div>
|
@@ -115,7 +115,7 @@
|
|
115
115
|
<div class="method-description">
|
116
116
|
<p>
|
117
117
|
Convenient routine to create an execution chain of <a
|
118
|
-
href="Kernel.html#
|
118
|
+
href="Kernel.html#M000052">factories</a>
|
119
119
|
</p>
|
120
120
|
<p>
|
121
121
|
Example:
|
@@ -128,7 +128,7 @@ Example:
|
|
128
128
|
</pre>
|
129
129
|
<p>
|
130
130
|
Then to execute the chains, you‘ll need to call <a
|
131
|
-
href="Kernel.html#
|
131
|
+
href="Kernel.html#M000053">run_factories</a>, and pass in the name of the
|
132
132
|
chain you want to execute.
|
133
133
|
</p>
|
134
134
|
<p>
|
@@ -142,8 +142,8 @@ Example:
|
|
142
142
|
executed later
|
143
143
|
</p>
|
144
144
|
<p><a class="source-toggle" href="#"
|
145
|
-
onclick="toggleCode('
|
146
|
-
<div class="method-source-code" id="
|
145
|
+
onclick="toggleCode('M000052-source');return false;">[Source]</a></p>
|
146
|
+
<div class="method-source-code" id="M000052-source">
|
147
147
|
<pre>
|
148
148
|
<span class="ruby-comment cmt"># File lib/mack-data_factory/core_extensions/kernel.rb, line 28</span>
|
149
149
|
28: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">factories</span>(<span class="ruby-identifier">tag</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
@@ -155,11 +155,11 @@ executed later
|
|
155
155
|
</div>
|
156
156
|
</div>
|
157
157
|
|
158
|
-
<div id="method-
|
159
|
-
<a name="
|
158
|
+
<div id="method-M000053" class="method-detail">
|
159
|
+
<a name="M000053"></a>
|
160
160
|
|
161
161
|
<div class="method-heading">
|
162
|
-
<a href="#
|
162
|
+
<a href="#M000053" class="method-signature">
|
163
163
|
<span class="method-name">run_factories</span><span class="method-args">(tag)</span>
|
164
164
|
</a>
|
165
165
|
</div>
|
@@ -169,12 +169,12 @@ executed later
|
|
169
169
|
Run defined factory chain
|
170
170
|
</p>
|
171
171
|
<p>
|
172
|
-
@see <a href="Kernel.html#
|
172
|
+
@see <a href="Kernel.html#M000052">factories</a> @tag — the name of
|
173
173
|
the factory chain to be run @return true if successful, false otherwise
|
174
174
|
</p>
|
175
175
|
<p><a class="source-toggle" href="#"
|
176
|
-
onclick="toggleCode('
|
177
|
-
<div class="method-source-code" id="
|
176
|
+
onclick="toggleCode('M000053-source');return false;">[Source]</a></p>
|
177
|
+
<div class="method-source-code" id="M000053-source">
|
178
178
|
<pre>
|
179
179
|
<span class="ruby-comment cmt"># File lib/mack-data_factory/core_extensions/kernel.rb, line 39</span>
|
180
180
|
39: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run_factories</span>(<span class="ruby-identifier">tag</span>)
|
data/doc/classes/Mack.html
CHANGED
@@ -86,12 +86,12 @@
|
|
86
86
|
<h3 class="section-bar">Methods</h3>
|
87
87
|
|
88
88
|
<div class="name-list">
|
89
|
-
<a href="#
|
90
|
-
<a href="#
|
91
|
-
<a href="#
|
92
|
-
<a href="#
|
93
|
-
<a href="#
|
94
|
-
<a href="#
|
89
|
+
<a href="#M000050">count</a>
|
90
|
+
<a href="#M000047">get</a>
|
91
|
+
<a href="#M000048">get_all</a>
|
92
|
+
<a href="#M000049">get_first</a>
|
93
|
+
<a href="#M000046">new</a>
|
94
|
+
<a href="#M000051">save</a>
|
95
95
|
</div>
|
96
96
|
</div>
|
97
97
|
|
@@ -113,19 +113,19 @@
|
|
113
113
|
<div id="methods">
|
114
114
|
<h3 class="section-bar">Public Class methods</h3>
|
115
115
|
|
116
|
-
<div id="method-
|
117
|
-
<a name="
|
116
|
+
<div id="method-M000046" class="method-detail">
|
117
|
+
<a name="M000046"></a>
|
118
118
|
|
119
119
|
<div class="method-heading">
|
120
|
-
<a href="#
|
120
|
+
<a href="#M000046" class="method-signature">
|
121
121
|
<span class="method-name">new</span><span class="method-args">()</span>
|
122
122
|
</a>
|
123
123
|
</div>
|
124
124
|
|
125
125
|
<div class="method-description">
|
126
126
|
<p><a class="source-toggle" href="#"
|
127
|
-
onclick="toggleCode('
|
128
|
-
<div class="method-source-code" id="
|
127
|
+
onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
|
128
|
+
<div class="method-source-code" id="M000046-source">
|
129
129
|
<pre>
|
130
130
|
<span class="ruby-comment cmt"># File lib/mack-data_factory/orm_api_bridge/bridge.rb, line 9</span>
|
131
131
|
9: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>
|
@@ -139,19 +139,19 @@
|
|
139
139
|
|
140
140
|
<h3 class="section-bar">Public Instance methods</h3>
|
141
141
|
|
142
|
-
<div id="method-
|
143
|
-
<a name="
|
142
|
+
<div id="method-M000050" class="method-detail">
|
143
|
+
<a name="M000050"></a>
|
144
144
|
|
145
145
|
<div class="method-heading">
|
146
|
-
<a href="#
|
146
|
+
<a href="#M000050" class="method-signature">
|
147
147
|
<span class="method-name">count</span><span class="method-args">(obj, *args)</span>
|
148
148
|
</a>
|
149
149
|
</div>
|
150
150
|
|
151
151
|
<div class="method-description">
|
152
152
|
<p><a class="source-toggle" href="#"
|
153
|
-
onclick="toggleCode('
|
154
|
-
<div class="method-source-code" id="
|
153
|
+
onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
|
154
|
+
<div class="method-source-code" id="M000050-source">
|
155
155
|
<pre>
|
156
156
|
<span class="ruby-comment cmt"># File lib/mack-data_factory/orm_api_bridge/bridge.rb, line 26</span>
|
157
157
|
26: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">count</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
@@ -162,19 +162,19 @@
|
|
162
162
|
</div>
|
163
163
|
</div>
|
164
164
|
|
165
|
-
<div id="method-
|
166
|
-
<a name="
|
165
|
+
<div id="method-M000047" class="method-detail">
|
166
|
+
<a name="M000047"></a>
|
167
167
|
|
168
168
|
<div class="method-heading">
|
169
|
-
<a href="#
|
169
|
+
<a href="#M000047" class="method-signature">
|
170
170
|
<span class="method-name">get</span><span class="method-args">(obj, *args)</span>
|
171
171
|
</a>
|
172
172
|
</div>
|
173
173
|
|
174
174
|
<div class="method-description">
|
175
175
|
<p><a class="source-toggle" href="#"
|
176
|
-
onclick="toggleCode('
|
177
|
-
<div class="method-source-code" id="
|
176
|
+
onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
|
177
|
+
<div class="method-source-code" id="M000047-source">
|
178
178
|
<pre>
|
179
179
|
<span class="ruby-comment cmt"># File lib/mack-data_factory/orm_api_bridge/bridge.rb, line 14</span>
|
180
180
|
14: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
@@ -185,19 +185,19 @@
|
|
185
185
|
</div>
|
186
186
|
</div>
|
187
187
|
|
188
|
-
<div id="method-
|
189
|
-
<a name="
|
188
|
+
<div id="method-M000048" class="method-detail">
|
189
|
+
<a name="M000048"></a>
|
190
190
|
|
191
191
|
<div class="method-heading">
|
192
|
-
<a href="#
|
192
|
+
<a href="#M000048" class="method-signature">
|
193
193
|
<span class="method-name">get_all</span><span class="method-args">(obj, *args)</span>
|
194
194
|
</a>
|
195
195
|
</div>
|
196
196
|
|
197
197
|
<div class="method-description">
|
198
198
|
<p><a class="source-toggle" href="#"
|
199
|
-
onclick="toggleCode('
|
200
|
-
<div class="method-source-code" id="
|
199
|
+
onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
|
200
|
+
<div class="method-source-code" id="M000048-source">
|
201
201
|
<pre>
|
202
202
|
<span class="ruby-comment cmt"># File lib/mack-data_factory/orm_api_bridge/bridge.rb, line 18</span>
|
203
203
|
18: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_all</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
@@ -208,19 +208,19 @@
|
|
208
208
|
</div>
|
209
209
|
</div>
|
210
210
|
|
211
|
-
<div id="method-
|
212
|
-
<a name="
|
211
|
+
<div id="method-M000049" class="method-detail">
|
212
|
+
<a name="M000049"></a>
|
213
213
|
|
214
214
|
<div class="method-heading">
|
215
|
-
<a href="#
|
215
|
+
<a href="#M000049" class="method-signature">
|
216
216
|
<span class="method-name">get_first</span><span class="method-args">(obj, *args)</span>
|
217
217
|
</a>
|
218
218
|
</div>
|
219
219
|
|
220
220
|
<div class="method-description">
|
221
221
|
<p><a class="source-toggle" href="#"
|
222
|
-
onclick="toggleCode('
|
223
|
-
<div class="method-source-code" id="
|
222
|
+
onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
|
223
|
+
<div class="method-source-code" id="M000049-source">
|
224
224
|
<pre>
|
225
225
|
<span class="ruby-comment cmt"># File lib/mack-data_factory/orm_api_bridge/bridge.rb, line 22</span>
|
226
226
|
22: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_first</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
@@ -231,19 +231,19 @@
|
|
231
231
|
</div>
|
232
232
|
</div>
|
233
233
|
|
234
|
-
<div id="method-
|
235
|
-
<a name="
|
234
|
+
<div id="method-M000051" class="method-detail">
|
235
|
+
<a name="M000051"></a>
|
236
236
|
|
237
237
|
<div class="method-heading">
|
238
|
-
<a href="#
|
238
|
+
<a href="#M000051" class="method-signature">
|
239
239
|
<span class="method-name">save</span><span class="method-args">(obj, *args)</span>
|
240
240
|
</a>
|
241
241
|
</div>
|
242
242
|
|
243
243
|
<div class="method-description">
|
244
244
|
<p><a class="source-toggle" href="#"
|
245
|
-
onclick="toggleCode('
|
246
|
-
<div class="method-source-code" id="
|
245
|
+
onclick="toggleCode('M000051-source');return false;">[Source]</a></p>
|
246
|
+
<div class="method-source-code" id="M000051-source">
|
247
247
|
<pre>
|
248
248
|
<span class="ruby-comment cmt"># File lib/mack-data_factory/orm_api_bridge/bridge.rb, line 30</span>
|
249
249
|
30: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
@@ -80,9 +80,10 @@
|
|
80
80
|
<h3 class="section-bar">Methods</h3>
|
81
81
|
|
82
82
|
<div class="name-list">
|
83
|
+
<a href="#M000004">association</a>
|
83
84
|
<a href="#M000002">create</a>
|
84
85
|
<a href="#M000003">field</a>
|
85
|
-
<a href="#
|
86
|
+
<a href="#M000005">scope_for</a>
|
86
87
|
</div>
|
87
88
|
</div>
|
88
89
|
|
@@ -104,6 +105,33 @@
|
|
104
105
|
<div id="methods">
|
105
106
|
<h3 class="section-bar">Public Instance methods</h3>
|
106
107
|
|
108
|
+
<div id="method-M000004" class="method-detail">
|
109
|
+
<a name="M000004"></a>
|
110
|
+
|
111
|
+
<div class="method-heading">
|
112
|
+
<a href="#M000004" class="method-signature">
|
113
|
+
<span class="method-name">association</span><span class="method-args">(model_attrib_sym, assoc_map, assoc_rule = :spread)</span>
|
114
|
+
</a>
|
115
|
+
</div>
|
116
|
+
|
117
|
+
<div class="method-description">
|
118
|
+
<p>
|
119
|
+
Define an <a href="ClassMethods.html#M000004">association</a> rule for this
|
120
|
+
<a href="ClassMethods.html#M000003">field</a>
|
121
|
+
</p>
|
122
|
+
<p><a class="source-toggle" href="#"
|
123
|
+
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
124
|
+
<div class="method-source-code" id="M000004-source">
|
125
|
+
<pre>
|
126
|
+
<span class="ruby-comment cmt"># File lib/mack-data_factory/data_factory.rb, line 88</span>
|
127
|
+
88: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">association</span>(<span class="ruby-identifier">model_attrib_sym</span>, <span class="ruby-identifier">assoc_map</span>, <span class="ruby-identifier">assoc_rule</span> = <span class="ruby-identifier">:spread</span>)
|
128
|
+
89: <span class="ruby-identifier">field</span>(<span class="ruby-identifier">model_attrib_sym</span>, {<span class="ruby-identifier">:default</span> =<span class="ruby-operator">></span> {<span class="ruby-identifier">:df_assoc_map</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">assoc_map</span>}, <span class="ruby-identifier">:assoc</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">assoc_rule</span>})
|
129
|
+
90: <span class="ruby-keyword kw">end</span>
|
130
|
+
</pre>
|
131
|
+
</div>
|
132
|
+
</div>
|
133
|
+
</div>
|
134
|
+
|
107
135
|
<div id="method-M000002" class="method-detail">
|
108
136
|
<a name="M000002"></a>
|
109
137
|
|
@@ -122,7 +150,7 @@ Example: class CarFactory
|
|
122
150
|
</p>
|
123
151
|
<pre>
|
124
152
|
include Mack::Data::Factory
|
125
|
-
field :name, "honda" { |def_value, rules, index| "#{def_value} #{['civic', 'accord', 'pilot'].randomize[0]}"}
|
153
|
+
field :name, :default => "honda" { |def_value, rules, index| "#{def_value} #{['civic', 'accord', 'pilot'].randomize[0]}"}
|
126
154
|
</pre>
|
127
155
|
<p>
|
128
156
|
end
|
@@ -195,7 +223,7 @@ params:
|
|
195
223
|
|
196
224
|
<div class="method-heading">
|
197
225
|
<a href="#M000003" class="method-signature">
|
198
|
-
<span class="method-name">field</span><span class="method-args">(model_attrib_sym,
|
226
|
+
<span class="method-name">field</span><span class="method-args">(model_attrib_sym, options = {}, &block)</span>
|
199
227
|
</a>
|
200
228
|
</div>
|
201
229
|
|
@@ -209,19 +237,19 @@ value and rules and an optional content generator for this factory
|
|
209
237
|
<div class="method-source-code" id="M000003-source">
|
210
238
|
<pre>
|
211
239
|
<span class="ruby-comment cmt"># File lib/mack-data_factory/data_factory.rb, line 81</span>
|
212
|
-
81: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">field</span>(<span class="ruby-identifier">model_attrib_sym</span>, <span class="ruby-identifier">
|
213
|
-
82: <span class="ruby-identifier">field_manager</span>.<span class="ruby-identifier">add</span>(<span class="ruby-identifier">scope</span>, <span class="ruby-identifier">model_attrib_sym</span>, <span class="ruby-identifier">
|
240
|
+
81: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">field</span>(<span class="ruby-identifier">model_attrib_sym</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
241
|
+
82: <span class="ruby-identifier">field_manager</span>.<span class="ruby-identifier">add</span>(<span class="ruby-identifier">scope</span>, <span class="ruby-identifier">model_attrib_sym</span>, <span class="ruby-identifier">options</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
214
242
|
83: <span class="ruby-keyword kw">end</span>
|
215
243
|
</pre>
|
216
244
|
</div>
|
217
245
|
</div>
|
218
246
|
</div>
|
219
247
|
|
220
|
-
<div id="method-
|
221
|
-
<a name="
|
248
|
+
<div id="method-M000005" class="method-detail">
|
249
|
+
<a name="M000005"></a>
|
222
250
|
|
223
251
|
<div class="method-heading">
|
224
|
-
<a href="#
|
252
|
+
<a href="#M000005" class="method-signature">
|
225
253
|
<span class="method-name">scope_for</span><span class="method-args">(tag) {|| ...}</span>
|
226
254
|
</a>
|
227
255
|
</div>
|
@@ -233,15 +261,15 @@ href="ClassMethods.html#M000003">field</a> defined in a scope will
|
|
233
261
|
overwrite its cousin in the default scope.
|
234
262
|
</p>
|
235
263
|
<p><a class="source-toggle" href="#"
|
236
|
-
onclick="toggleCode('
|
237
|
-
<div class="method-source-code" id="
|
264
|
+
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
265
|
+
<div class="method-source-code" id="M000005-source">
|
238
266
|
<pre>
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
267
|
+
<span class="ruby-comment cmt"># File lib/mack-data_factory/data_factory.rb, line 96</span>
|
268
|
+
96: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">scope_for</span>(<span class="ruby-identifier">tag</span>)
|
269
|
+
97: <span class="ruby-identifier">set_scope</span>(<span class="ruby-identifier">tag</span>)
|
270
|
+
98: <span class="ruby-keyword kw">yield</span>
|
271
|
+
99: <span class="ruby-identifier">set_scope</span>(<span class="ruby-identifier">:default</span>)
|
272
|
+
100: <span class="ruby-keyword kw">end</span>
|
245
273
|
</pre>
|
246
274
|
</div>
|
247
275
|
</div>
|