blueprinter 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +14 -0
- data/lib/blueprinter/extractors/association_extractor.rb +1 -1
- data/lib/blueprinter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72efd8dd2ec9f959aa0a4ab79db6aca9a8654ea7a66474524fdfb49277fbd315
|
4
|
+
data.tar.gz: b04bc7182d997999f0bf30babe1abb5ad9bd8f35206cc0648f00cae4026d6900
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af5cd971e59e741c3edf95a5778f2462c679769bf4e95ba37f725fd8508f765bc296d5fd0412c8cbb1cbee41b213bd5f7a0c2b46f3c3b9ec63fb02c82acfac7b
|
7
|
+
data.tar.gz: 418d5b106f804d9e11dede74cc89cf03c9734a0b15ef31a5cf8554b2ba0fd9e7e3515db3e3b15f2fee2e21c484c962cae03967bcd55990e9a5690fc04f50bdc2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 0.5.0 - 2018/05/15
|
2
|
+
|
3
|
+
* [FEATURE] Add `default` option to `association` which will be used as the serialized value instead of `null` when the association evaluates to null.
|
4
|
+
See PR #78 by @vinaya-procore.
|
5
|
+
|
1
6
|
## 0.4.0 - 2018/05/02
|
2
7
|
|
3
8
|
* [FEATURE] Add `render_as_hash` which will output a hash instead of
|
data/README.md
CHANGED
@@ -120,6 +120,20 @@ Output:
|
|
120
120
|
}
|
121
121
|
```
|
122
122
|
|
123
|
+
#### Default option
|
124
|
+
By default, an association that evaluates to `nil` is serialized as `nil`. A default serialized value can be
|
125
|
+
specified as option on the association for cases when the association could potentially evaluate to `nil`.
|
126
|
+
```ruby
|
127
|
+
class UserBlueprint < Blueprinter::Base
|
128
|
+
identifier :uuid
|
129
|
+
|
130
|
+
view :normal do
|
131
|
+
fields :first_name, :last_name
|
132
|
+
association :company, blueprint: CompanyBlueprint, default: {}
|
133
|
+
end
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
123
137
|
### Defining a field directly in the Blueprint
|
124
138
|
|
125
139
|
You can define a field directly in the Blueprint by passing it a block. This is especially useful if the object does not already have such an attribute or method defined, and you want to define it specifically for use with the Blueprint. For example:
|
@@ -2,7 +2,7 @@ module Blueprinter
|
|
2
2
|
class AssociationExtractor < Extractor
|
3
3
|
def extract(association_name, object, local_options, options={})
|
4
4
|
value = object.public_send(association_name)
|
5
|
-
return value if value.nil?
|
5
|
+
return (value || options[:default]) if value.nil?
|
6
6
|
view = options[:view] || :default
|
7
7
|
options[:blueprint].prepare(value, view_name: view, local_options: local_options)
|
8
8
|
end
|
data/lib/blueprinter/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blueprinter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hess
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-05-
|
12
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|