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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08abb9ba41c2c44993545fc879b4b94ab77394356f8cc82bc2fd8f11d37ad482'
4
- data.tar.gz: d40666d3ed13b2bfca020a0ee37bde00876300ab856591b1e33d4cc6067f23c7
3
+ metadata.gz: 72efd8dd2ec9f959aa0a4ab79db6aca9a8654ea7a66474524fdfb49277fbd315
4
+ data.tar.gz: b04bc7182d997999f0bf30babe1abb5ad9bd8f35206cc0648f00cae4026d6900
5
5
  SHA512:
6
- metadata.gz: 4353599cf5f1b1320ad8bd930c23bbf046258c7767f4e27ff2d07faedc28fd031d29166959e2303588ac96140e06881bf761e2918e9cf40db0abe941cc2cb5a7
7
- data.tar.gz: da2c78ad5210456490af49493a2b9043fde2aa73bd1a0642e6f2264c4ac004200e8d3a3a4058ec66cd1014252c4fd3f901ae6a771411c9720f8c1490ab7199f8
6
+ metadata.gz: af5cd971e59e741c3edf95a5778f2462c679769bf4e95ba37f725fd8508f765bc296d5fd0412c8cbb1cbee41b213bd5f7a0c2b46f3c3b9ec63fb02c82acfac7b
7
+ data.tar.gz: 418d5b106f804d9e11dede74cc89cf03c9734a0b15ef31a5cf8554b2ba0fd9e7e3515db3e3b15f2fee2e21c484c962cae03967bcd55990e9a5690fc04f50bdc2
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Blueprinter
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
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.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-02 00:00:00.000000000 Z
12
+ date: 2018-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri