faker_maker 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +8 -22
- data/lib/faker_maker/factory.rb +2 -2
- data/lib/faker_maker/version.rb +1 -1
- metadata +2 -3
- data/lib/.DS_Store +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f977406ece1d14881538014e4b76cb2d6d93d2753163414211170223dea9c83
|
4
|
+
data.tar.gz: 315e1e877b305628ffdd659b0afa7003554cf778d3b32eadb950b40c7b300f2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8d80e848a217be01b2425e2538a9923b101fbd1eaf51e8fbb51878516f4078dbe6a96540ae8ae306fecc65dc099362b6af85e7c83553f256d3fc4243f20719e
|
7
|
+
data.tar.gz: 9717105b014298cada262689873234a136c131c51433441e91184a3ea7cfabbd9912320539bfb8a3c17485c266bde3c2bb969665bdc197ca40f5fa2987ad6221
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -123,28 +123,6 @@ FakerMaker.factory :basket do
|
|
123
123
|
end
|
124
124
|
```
|
125
125
|
|
126
|
-
JSON keys are often have a different stylistic convention than Ruby's snake-case so you can override the attribute's name when is come to generating JSON:
|
127
|
-
|
128
|
-
```ruby
|
129
|
-
FakerMaker.factory :item do
|
130
|
-
name( json: 'productName' ) { Faker::Commerce.product_name }
|
131
|
-
price( json: 'ticketPrice' ) { Faker::Commerce.price }
|
132
|
-
end
|
133
|
-
```
|
134
|
-
|
135
|
-
so in Ruby you would access the attribute using the attribute name as in:
|
136
|
-
|
137
|
-
```ruby
|
138
|
-
item = FM[:item].build
|
139
|
-
puts item
|
140
|
-
```
|
141
|
-
|
142
|
-
but `item.to_json` would produce:
|
143
|
-
|
144
|
-
```javascript
|
145
|
-
{"productName":"Enormous Silk Pants","ticketPrice":55.35}
|
146
|
-
```
|
147
|
-
|
148
126
|
### Building instances
|
149
127
|
|
150
128
|
Instances are Plain Ol' Ruby Objects and the attributes are attached with getters and setters with their values assigned to the value return from their block at build time.
|
@@ -157,6 +135,14 @@ result = FakerMaker[:basket].build
|
|
157
135
|
|
158
136
|
will generate a new instance using the Basket factory. Because an actual class is defined, you can instantiate an object directly through `Basket.new` but that will not populate any of the attributes.
|
159
137
|
|
138
|
+
It's possible to override attributes at build-time:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
result = FakerMaker[:item].build{ |i| i.name = 'Electric Sheep' }
|
142
|
+
```
|
143
|
+
|
144
|
+
Calling `result.to_json` will give a stringified JSON representation. Because ActiveSupport is used under the covers, `as_json` will give you a `Hash` rather than the stringified version.
|
145
|
+
|
160
146
|
As a convenience, you can request a JSON representation directly:
|
161
147
|
|
162
148
|
```ruby
|
data/lib/faker_maker/factory.rb
CHANGED
@@ -17,13 +17,13 @@ module FakerMaker
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def attach_attribute attribute
|
20
|
-
@attributes << attribute
|
20
|
+
@attributes << attribute
|
21
21
|
end
|
22
22
|
|
23
23
|
def build
|
24
24
|
instance = instantiate
|
25
25
|
populate_instance instance
|
26
|
-
yield
|
26
|
+
yield instance if block_given?
|
27
27
|
instance
|
28
28
|
end
|
29
29
|
|
data/lib/faker_maker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faker_maker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nigel Brookes-Thomas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -126,7 +126,6 @@ files:
|
|
126
126
|
- bin/console
|
127
127
|
- bin/setup
|
128
128
|
- faker_maker.gemspec
|
129
|
-
- lib/.DS_Store
|
130
129
|
- lib/faker_maker.rb
|
131
130
|
- lib/faker_maker/attribute.rb
|
132
131
|
- lib/faker_maker/base.rb
|
data/lib/.DS_Store
DELETED
Binary file
|