blueprinter 0.25.2 → 0.26.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: 9e5e7be1f829035c332a5baa935ef724f52c381bd60f039a20a89368acc7cfde
4
- data.tar.gz: 7307febc9d3a860aa3b3ffe00a83066b808329a32a3d81dde5a7af7439dc4609
3
+ metadata.gz: '084b38103a3fc3c3771e1c4c165ebc0886ffba618706e85550685b4009748b74'
4
+ data.tar.gz: aa06eb341bd07f58fa3a7db984d6904baf368cd3825fdddaca8c95ce28d3c89c
5
5
  SHA512:
6
- metadata.gz: 24411ac6c3068b7c08c167e1f91a6e4e25757fd4a32df56f710b0fbe84d07e7507cbdf05eb54645ba3b9b29b8b90c81cede3e68254b254c0523975c9c9236dc0
7
- data.tar.gz: baef6ae7db2fcc0e6ab9eb4e4c11baf6453ecaf30519462bd6ea5d4dbd5cbd8b1e791f202b2b74e9f15ccc4d265d19828c33b339dc65041916d09351d7729e1f
6
+ metadata.gz: 453f3c4833925ff58aff5db8f5b6593a0d7c4cd60871996440ed832a55d15d9d00493c7b6cf8aeabbbdb66d3b23bd3c0ca83d66d44d7aff93c16478b15176509
7
+ data.tar.gz: 7485797da5950803fec48384f950a8feb69880ed092e20db573b324484a600eb0898c80d0b311ceef5015b4e37a44f052b34f3867165b081258e1b95231acf31
data/CHANGELOG.md CHANGED
@@ -1,28 +1,34 @@
1
+ ## 0.26.0 - 2023/08/17
2
+ * 🐛 [BREAKING] Transition to GitHub Actions from CircleCI and update to handle Ruby versions 2.7, 3.0, 3.1, 3.2. Drop support for any ruby version less than 2.7. See [#307](https://github.com/procore-oss/blueprinter/pull/307)
3
+
4
+ ## 0.25.3 - 2021/03/03
5
+ * 🐛 [BUGFIX] Fixes issue where fields and associations that are redefined by later views were not properly overwritten. See [#201](https://github.com/procore/blueprinter/pull/201) thanks to [@Berardpi](https://github.com/Berardpi).
6
+
1
7
  ## 0.25.2 - 2020/11/19
2
- * 🚀 [FEATURE] Make deprecation behavior configurable (`:silence`, `:stderror`, `:raise`). See [#248](https://github.com/procore/blueprinter/pull/248) thanks to [@mcclayton](https://github.com/mcclayton)
8
+ * 🚀 [FEATURE] Make deprecation behavior configurable (`:silence`, `:stderror`, `:raise`). See [#248](https://github.com/procore/blueprinter/pull/248) thanks to [@mcclayton](https://github.com/mcclayton).
3
9
 
4
- ## 0.25.1 - 2020/8/18
5
- * 🐛 [BUGFIX] Raise Blueprinter::BlueprinterError if Blueprint given is not of class Blueprinter::Base. Before it just raised a generic `undefined method 'prepare'`. See [#233](https://github.com/procore/blueprinter/pull/233) thanks to [@caws](https://github.com/caws)
10
+ ## 0.25.1 - 2020/08/18
11
+ * 🐛 [BUGFIX] Raise Blueprinter::BlueprinterError if Blueprint given is not of class Blueprinter::Base. Before it just raised a generic `undefined method 'prepare'`. See [#233](https://github.com/procore/blueprinter/pull/233) thanks to [@caws](https://github.com/caws).
6
12
 
7
- ## 0.25.0 - 2020/7/06
13
+ ## 0.25.0 - 2020/07/06
8
14
  * 🚀 [FEATURE] Enable default `Blueprinter::Transformer`s to be set in the global configuration. [#222](https://github.com/procore/blueprinter/pull/222). Thanks to [@supremebeing7](https://github.com/supremebeing7).
9
15
 
10
- ## 0.24.0 - 2020/6/22
16
+ ## 0.24.0 - 2020/06/22
11
17
  * 🚀 [FEATURE] Add an `options` option to associations to facilitate passing options from one blueprint to another. [#220](https://github.com/procore/blueprinter/pull/220). Thanks to [@mcclayton](https://github.com/mcclayton).
12
18
 
13
- ## 0.23.4 - 2020/4/28
19
+ ## 0.23.4 - 2020/04/28
14
20
  * 🚀 [FEATURE] Public class method `has_view?` on Blueprinter::Base subclasses introduced in [#213](https://github.com/procore/blueprinter/pull/213). Thanks to [@spencerneste](https://github.com/spencerneste).
15
21
 
16
- ## 0.23.3 - 2020/4/7
22
+ ## 0.23.3 - 2020/04/07
17
23
  * 🐛 [BUGFIX] Fixes issue where `exclude` fields in deeply nested views were not respected. Resolved issue [207](https://github.com/procore/blueprinter/issues/207) in [#208](https://github.com/procore/blueprinter/pull/208) by [@tpltn](https://github.com/tpltn).
18
24
 
19
- ## 0.23.2 - 2020/3/16
25
+ ## 0.23.2 - 2020/03/16
20
26
  * 🐛 [BUGFIX] Fixes issue where fields "bled" into other views due to merge side-effects. Resolved issue [205](https://github.com/procore/blueprinter/issues/205) in [#204](https://github.com/procore/blueprinter/pull/204) by [@trevorrjohn](https://github.com/trevorrjohn).
21
27
 
22
- ## 0.23.1 - 2020/3/13
28
+ ## 0.23.1 - 2020/03/13
23
29
  * 🐛 [BUGFIX] Fixes #172 where views would unintentionally ignore `sort_fields_by: :definition` configuration. Resolved in [#197](https://github.com/procore/blueprinter/pull/197) by [@wlkrw](https://github.com/wlkrw).
24
30
 
25
- ## 0.23.0 - 2020/1/31
31
+ ## 0.23.0 - 2020/01/31
26
32
  * 🚀 [FEATURE] Configurable default extractor introduced in [#198](https://github.com/procore/blueprinter/pull/198) by [@wlkrw](https://github.com/wlkrw). You can now set a default extractor like so:
27
33
  ```
28
34
  Blueprinter.configure do |config|
@@ -78,15 +84,15 @@ end
78
84
  * 🚀 [FEATURE] Added an option to render with a root key. [#135](https://github.com/procore/blueprinter/pull/135). Thanks to [@ritikesh](https://github.com/ritikesh).
79
85
  * 🚀 [FEATURE] Added an option to render with a top-level meta attribute. [#135](https://github.com/procore/blueprinter/pull/135). Thanks to [@ritikesh](https://github.com/ritikesh).
80
86
 
81
- ## 0.12.1 - 2019/1/24
87
+ ## 0.12.1 - 2019/01/24
82
88
 
83
89
  * 🐛 [BUGFIX] Fix boolean `false` values getting serialized as `null`. Please see PR [#132](https://github.com/procore/blueprinter/pull/132). Thanks to [@samsongz](https://github.com/samsongz).
84
90
 
85
- ## 0.12.0 - 2019/1/16
91
+ ## 0.12.0 - 2019/01/16
86
92
 
87
93
  * 🚀 [FEATURE] Enables the setting of global `:field_default` and `:association_default` option value in the Blueprinter Configuration that will be used as default values for fields and associations that evaluate to nil. [#128](https://github.com/procore/blueprinter/pull/128). Thanks to [@mcclayton](https://github.com/mcclayton).
88
94
 
89
- ## 0.11.0 - 2019/1/15
95
+ ## 0.11.0 - 2019/01/15
90
96
 
91
97
  * 🚀 [FEATURE] Enables the setting of a global `:if`/`:unless` proc in the Blueprinter Configuration that will be used to evaluate the conditional render of all fields. [#127](https://github.com/procore/blueprinter/pull/127). Thanks to [@mcclayton](https://github.com/mcclayton).
92
98
 
data/README.md CHANGED
@@ -1,18 +1,35 @@
1
- [![CircleCI](https://circleci.com/gh/procore/blueprinter.svg?style=svg)](https://circleci.com/gh/procore/blueprinter)
1
+ [![Test](https://github.com/procore-oss/blueprinter/actions/workflows/test.yaml/badge.svg?branch=master)](https://github.com/procore-oss/blueprinter/actions/workflows/test.yaml)
2
2
  [![Gem Version](https://badge.fury.io/rb/blueprinter.svg)](https://badge.fury.io/rb/blueprinter)
3
3
  [![Gitter chat](https://badges.gitter.im/procore/blueprinter.svg)](https://gitter.im/blueprinter-gem/community)
4
4
 
5
5
  <img src="blueprinter_logo.svg" width="25%">
6
6
 
7
+ # Recent Organization Move
8
+
9
+ Please change your local remote to pull from this repository:
10
+
11
+ ```bash
12
+ git remote set-url [previous-remote-name] git@github.com:procore-oss/blueprinter.git
13
+ ```
14
+
15
+ to see the previous upstream remote name, run:
16
+
17
+ ```bash
18
+ git remote -v
19
+ ```
20
+
7
21
  # Blueprinter
22
+
8
23
  Blueprinter is a JSON Object Presenter for Ruby that takes business objects and breaks them down into simple hashes and serializes them to JSON. It can be used in Rails in place of other serializers (like JBuilder or ActiveModelSerializers). It is designed to be simple, direct, and performant.
9
24
 
10
25
  It heavily relies on the idea of `views` which, similar to Rails views, are ways of predefining output for data in different contexts.
11
26
 
12
27
  ## Documentation
28
+
13
29
  Docs can be found [here](http://www.rubydoc.info/gems/blueprinter).
14
30
 
15
31
  ## Usage
32
+
16
33
  <details open>
17
34
  <summary>Basic</summary>
18
35
 
@@ -31,6 +48,7 @@ end
31
48
  ```
32
49
 
33
50
  and then, in your code:
51
+
34
52
  ```ruby
35
53
  puts UserBlueprint.render(user) # Output is a JSON string
36
54
  ```
@@ -49,7 +67,6 @@ And the output would look like:
49
67
  ---
50
68
  </details>
51
69
 
52
-
53
70
  <details>
54
71
  <summary>Collections</summary>
55
72
 
@@ -83,7 +100,6 @@ This will result in JSON that looks something like this:
83
100
  ---
84
101
  </details>
85
102
 
86
-
87
103
  <details>
88
104
  <summary>Renaming</summary>
89
105
 
@@ -114,13 +130,13 @@ This will result in JSON that looks something like this:
114
130
  ---
115
131
  </details>
116
132
 
117
-
118
133
  <details>
119
134
  <summary>Views</summary>
120
135
 
121
136
  ---
122
137
 
123
138
  You may define different outputs by utilizing views:
139
+
124
140
  ```ruby
125
141
  class UserBlueprint < Blueprinter::Base
126
142
  identifier :uuid
@@ -137,14 +153,17 @@ class UserBlueprint < Blueprinter::Base
137
153
  end
138
154
  end
139
155
  ```
156
+
140
157
  A view can include fields from another view by utilizing `include_view` and `include_views`.
141
158
 
142
159
  Usage:
160
+
143
161
  ```ruby
144
162
  puts UserBlueprint.render(user, view: :extended)
145
163
  ```
146
164
 
147
165
  Output:
166
+
148
167
  ```json
149
168
  {
150
169
  "uuid": "733f0758-8f21-4719-875f-262c3ec743af",
@@ -158,13 +177,39 @@ Output:
158
177
  ---
159
178
  </details>
160
179
 
180
+ <details>
181
+ <summary>Identifiers</summary>
182
+
183
+ ---
184
+
185
+ `identifier`s are used to specify a field or method name used as an identifier. Usually, this is something like `:id`.
186
+
187
+ Example:
188
+
189
+ ```rb
190
+ class UserBlueprint < Blueprinter::Base
191
+ identifier :uuid
192
+ end
193
+ ```
194
+
195
+ Blueprinter `identifier`s have a few properties that set them apart from `field`s.
196
+
197
+ 1. Identifiers are **always** rendered and considered their own view (the `:identifier` view).
198
+ 2. When rendering, identifier fields are always sorted first, before other fields.
199
+
200
+ If either of the above two developer conveniences are not desired, you can simply create your identifier fields as regular `field`s.
201
+
202
+ ---
203
+
204
+ </details>
161
205
 
162
206
  <details>
163
207
  <summary>Root</summary>
164
-
208
+ <a name="root"></a>
165
209
  ---
166
210
 
167
211
  You can also optionally pass in a root key to wrap your resulting json in:
212
+
168
213
  ```ruby
169
214
  class UserBlueprint < Blueprinter::Base
170
215
  identifier :uuid
@@ -177,11 +222,13 @@ end
177
222
  ```
178
223
 
179
224
  Usage:
225
+
180
226
  ```ruby
181
227
  puts UserBlueprint.render(user, view: :normal, root: :user)
182
228
  ```
183
229
 
184
230
  Output:
231
+
185
232
  ```json
186
233
  {
187
234
  "user": {
@@ -196,13 +243,13 @@ Output:
196
243
  ---
197
244
  </details>
198
245
 
199
-
200
246
  <details>
201
247
  <summary>Meta Attributes</summary>
202
248
 
203
249
  ---
204
250
 
205
251
  You can additionally add meta-data to the json as well:
252
+
206
253
  ```ruby
207
254
  class UserBlueprint < Blueprinter::Base
208
255
  identifier :uuid
@@ -215,6 +262,7 @@ end
215
262
  ```
216
263
 
217
264
  Usage:
265
+
218
266
  ```ruby
219
267
  json = UserBlueprint.render(user, view: :normal, root: :user, meta: {links: [
220
268
  'https://app.mydomain.com',
@@ -224,6 +272,7 @@ puts json
224
272
  ```
225
273
 
226
274
  Output:
275
+
227
276
  ```json
228
277
  {
229
278
  "user": {
@@ -240,18 +289,19 @@ Output:
240
289
  }
241
290
  }
242
291
  ```
292
+
243
293
  _NOTE:_ For meta attributes, a [root](#root) is mandatory.
244
294
 
245
295
  ---
246
296
  </details>
247
297
 
248
-
249
298
  <details>
250
299
  <summary>Exclude Fields</summary>
251
300
 
252
301
  ---
253
302
 
254
303
  You can specifically choose to exclude certain fields for specific views
304
+
255
305
  ```ruby
256
306
  class UserBlueprint < Blueprinter::Base
257
307
  identifier :uuid
@@ -270,11 +320,13 @@ end
270
320
  ```
271
321
 
272
322
  Usage:
323
+
273
324
  ```ruby
274
325
  puts UserBlueprint.render(user, view: :extended)
275
326
  ```
276
327
 
277
328
  Output:
329
+
278
330
  ```json
279
331
  {
280
332
  "uuid": "733f0758-8f21-4719-875f-262c3ec743af",
@@ -306,13 +358,13 @@ end
306
358
  ---
307
359
  </details>
308
360
 
309
-
310
361
  <details>
311
362
  <summary>Associations</summary>
312
363
 
313
364
  ---
314
365
 
315
366
  You may include associated objects. Say for example, a user has projects:
367
+
316
368
  ```ruby
317
369
  class ProjectBlueprint < Blueprinter::Base
318
370
  identifier :uuid
@@ -331,11 +383,13 @@ end
331
383
  ```
332
384
 
333
385
  Usage:
386
+
334
387
  ```ruby
335
388
  puts UserBlueprint.render(user, view: :normal)
336
389
  ```
337
390
 
338
391
  Output:
392
+
339
393
  ```json
340
394
  {
341
395
  "uuid": "733f0758-8f21-4719-875f-262c3ec743af",
@@ -357,6 +411,7 @@ Output:
357
411
 
358
412
  It is also possible to pass options from one Blueprint to another via an association.
359
413
  For example:
414
+
360
415
  ```ruby
361
416
  class VehicleBlueprint < Blueprinter::Base
362
417
  identifier :uuid
@@ -378,7 +433,6 @@ end
378
433
  ---
379
434
  </details>
380
435
 
381
-
382
436
  <details>
383
437
  <summary>Default Association/Field Option</summary>
384
438
 
@@ -386,7 +440,8 @@ end
386
440
 
387
441
  By default, an association or field that evaluates to `nil` is serialized as `nil`. A default serialized value can be specified as an option on the association or field for cases when the association/field could potentially evaluate to `nil`. You can also specify a global `field_default` or `association_default` in the Blueprinter config which will be used for all fields/associations that evaluate to nil.
388
442
 
389
- #### Global Config Setting
443
+ ### Global Config Setting
444
+
390
445
  ```ruby
391
446
  Blueprinter.configure do |config|
392
447
  config.field_default = "N/A"
@@ -394,7 +449,8 @@ Blueprinter.configure do |config|
394
449
  end
395
450
  ```
396
451
 
397
- #### Field-level/Association-level Setting
452
+ ### Field-level/Association-level Setting
453
+
398
454
  ```ruby
399
455
  class UserBlueprint < Blueprinter::Base
400
456
  identifier :uuid
@@ -409,7 +465,6 @@ end
409
465
  ---
410
466
  </details>
411
467
 
412
-
413
468
  <details>
414
469
  <summary>default_if</summary>
415
470
 
@@ -418,25 +473,29 @@ end
418
473
  Sometimes, you may want certain "empty" values to pass through to the default value.
419
474
  Blueprinter provides the ability to treat the following empty types as the default value (or `nil` if no default provided).
420
475
 
421
- #### Blueprinter::EMPTY_COLLECTION
476
+ ### Blueprinter::EMPTY_COLLECTION
477
+
422
478
  An empty array or empty active record collection.
423
479
 
424
- #### Blueprinter::EMPTY_HASH
480
+ ### Blueprinter::EMPTY_HASH
481
+
425
482
  An empty hash.
426
483
 
427
- #### Blueprinter::EMPTY_STRING
484
+ ### Blueprinter::EMPTY_STRING
485
+
428
486
  An empty string or symbol.
429
487
 
430
- #### Field-level/Association-level Setting
488
+ #### Field-level/Association-level Setting - EMPTY_STRING
489
+
431
490
  ```ruby
432
491
  class UserBlueprint < Blueprinter::Base
433
492
  identifier :uuid
434
493
 
435
494
  view :normal do
436
495
  # If first_name is an empty string, it will become "N/A"
437
- field :first_name, default_if: Blueprinter::EmptyString, default: "N/A"
496
+ field :first_name, default_if: Blueprinter::EMPTY_STRING, default: "N/A"
438
497
  # If the projects association collection is empty, it will become nil
439
- association :projects, blueprint: ProjectBlueprint, default_if: Blueprinter::EmptyCollection
498
+ association :projects, blueprint: ProjectBlueprint, default_if: Blueprinter::EMPTY_COLLECTION
440
499
  end
441
500
  end
442
501
  ```
@@ -444,13 +503,13 @@ end
444
503
  ---
445
504
  </details>
446
505
 
447
-
448
506
  <details>
449
507
  <summary>Supporting Dynamic Blueprints For Associations</summary>
450
508
 
451
509
  ---
452
510
 
453
511
  When defining an association, we can dynamically evaluate the blueprint. This comes in handy when adding polymorphic associations, by allowing reuse of existing blueprints.
512
+
454
513
  ```ruby
455
514
  class Task < ActiveRecord::Base
456
515
  belongs_to :taskable, polymorphic: true
@@ -473,12 +532,12 @@ class TaskBlueprint < Blueprinter::Base
473
532
  end
474
533
  end
475
534
  ```
535
+
476
536
  _NOTE:_ `taskable.blueprint` should return a valid Blueprint class. Currently, `has_many` is not supported because of the very nature of polymorphic associations.
477
537
 
478
538
  ---
479
539
  </details>
480
540
 
481
-
482
541
  <details>
483
542
  <summary>Defining A Field Directly In The Blueprint</summary>
484
543
 
@@ -513,7 +572,6 @@ Output:
513
572
  ---
514
573
  </details>
515
574
 
516
-
517
575
  <details>
518
576
  <summary>Defining An Identifier Directly In The Blueprint</summary>
519
577
 
@@ -546,7 +604,6 @@ Output:
546
604
  ---
547
605
  </details>
548
606
 
549
-
550
607
  <details>
551
608
  <summary>Defining An Association Directly In The Blueprint</summary>
552
609
 
@@ -591,7 +648,6 @@ Output:
591
648
  ---
592
649
  </details>
593
650
 
594
-
595
651
  <details>
596
652
  <summary>Passing Additional Properties To #render</summary>
597
653
 
@@ -626,7 +682,6 @@ Output:
626
682
  ---
627
683
  </details>
628
684
 
629
-
630
685
  <details>
631
686
  <summary>Conditional Fields</summary>
632
687
 
@@ -634,7 +689,8 @@ Output:
634
689
 
635
690
  Both the `field` and the global Blueprinter Configuration supports `:if` and `:unless` options that can be used to serialize fields conditionally.
636
691
 
637
- #### Global Config Setting
692
+ ### Global Config Setting - if and unless
693
+
638
694
  ```ruby
639
695
  Blueprinter.configure do |config|
640
696
  config.if = ->(field_name, obj, _options) { !obj[field_name].nil? }
@@ -643,6 +699,7 @@ end
643
699
  ```
644
700
 
645
701
  #### Field-level Setting
702
+
646
703
  ```ruby
647
704
  class UserBlueprint < Blueprinter::Base
648
705
  identifier :uuid
@@ -656,7 +713,6 @@ _NOTE:_ The field-level setting overrides the global config setting (for the fie
656
713
  ---
657
714
  </details>
658
715
 
659
-
660
716
  <details>
661
717
  <summary>Custom Formatting for Dates and Times</summary>
662
718
 
@@ -667,18 +723,21 @@ This global or field-level option can be either a string representing the associ
667
723
  or a Proc which receives the original Date/DateTime object and returns the formatted value.
668
724
  When using a Proc, it is the Proc's responsibility to handle any errors in formatting.
669
725
 
726
+ #### Global Config Setting - datetime
670
727
 
671
- #### Global Config Setting
672
728
  If a global datetime_format is set (either as a string format or a Proc), this option will be
673
729
  invoked and used to format all fields that respond to `strftime`.
730
+
674
731
  ```ruby
675
732
  Blueprinter.configure do |config|
676
733
  config.datetime_format = ->(datetime) { datetime.nil? ? datetime : datetime.strftime("%s").to_i }
677
734
  end
678
735
  ```
679
736
 
680
- #### Field-level Setting
737
+ #### Field-level Setting - datetime_format
738
+
681
739
  Usage (String Option):
740
+
682
741
  ```ruby
683
742
  class UserBlueprint < Blueprinter::Base
684
743
  identifier :name
@@ -687,6 +746,7 @@ end
687
746
  ```
688
747
 
689
748
  Output:
749
+
690
750
  ```json
691
751
  {
692
752
  "name": "John Doe",
@@ -695,6 +755,7 @@ Output:
695
755
  ```
696
756
 
697
757
  Usage (Proc Option):
758
+
698
759
  ```ruby
699
760
  class UserBlueprint < Blueprinter::Base
700
761
  identifier :name
@@ -703,6 +764,7 @@ end
703
764
  ```
704
765
 
705
766
  Output:
767
+
706
768
  ```json
707
769
  {
708
770
  "name": "John Doe",
@@ -715,7 +777,6 @@ _NOTE:_ The field-level setting overrides the global config setting (for the fie
715
777
  ---
716
778
  </details>
717
779
 
718
-
719
780
  <details>
720
781
  <summary>Transform Classes</summary>
721
782
 
@@ -731,6 +792,7 @@ Whatever is returned from this `transform` method will end up being the resultin
731
792
  #### Example
732
793
 
733
794
  Create a Transform class extending from `Blueprinter::Transformer`
795
+
734
796
  ```ruby
735
797
  class DynamicFieldTransformer < Blueprinter::Transformer
736
798
  def transform(hash, object, options)
@@ -752,6 +814,7 @@ end
752
814
  ```
753
815
 
754
816
  Then specify the transform to use for the view.
817
+
755
818
  ```ruby
756
819
  class UserBlueprint < Blueprinter::Base
757
820
  fields :first_name, :last_name
@@ -762,6 +825,7 @@ end
762
825
  #### Global Transforms
763
826
 
764
827
  You can also specify global default transformers. Create one or more transformer classes extending from `Blueprinter::Transformer` and set the `default_transformers` configuration
828
+
765
829
  ```ruby
766
830
  class LowerCamelTransformer < Blueprinter::Transformer
767
831
  def transform(hash, _object, _options)
@@ -791,6 +855,7 @@ Blueprinter gets a given objects' values from the fields definitions using extra
791
855
  #### Examples
792
856
 
793
857
  For a specific kind of field, create an extractor class extending from `Blueprinter::Extractor`
858
+
794
859
  ```ruby
795
860
  class MyFieldExtractor < Blueprinter::Extractor
796
861
  def extract(_field_name, _object, _local_options, _options={})
@@ -807,6 +872,7 @@ end
807
872
  ```
808
873
 
809
874
  For a global default, create an extractor class extending from `Blueprinter::AutoExtractor` and set the `extractor_default` configuration
875
+
810
876
  ```ruby
811
877
  class MyAutoExtractor < Blueprinter::AutoExtractor
812
878
  def initialize
@@ -857,6 +923,7 @@ end
857
923
  ```
858
924
 
859
925
  Output:
926
+
860
927
  ```json
861
928
  {
862
929
  "name": "John Doe",
@@ -868,7 +935,6 @@ Output:
868
935
  ---
869
936
  </details>
870
937
 
871
-
872
938
  <details>
873
939
  <summary>Deprecations</summary>
874
940
 
@@ -885,7 +951,8 @@ However, deprecations can be configured to report at three different levels:
885
951
  | `:raise` | Deprecations will be raised as `Blueprinter::BlueprinterError`s |
886
952
  | `:silence` | Deprecations will be silenced and will not be raised or logged |
887
953
 
888
- ### Example:
954
+ ### Example - deprecations
955
+
889
956
  ```ruby
890
957
  Blueprinter.configure do |config|
891
958
  config.deprecations = :raise
@@ -895,7 +962,6 @@ end
895
962
  ---
896
963
  </details>
897
964
 
898
-
899
965
  <details>
900
966
  <summary>render_as_hash</summary>
901
967
 
@@ -921,7 +987,6 @@ Output:
921
987
  ---
922
988
  </details>
923
989
 
924
-
925
990
  <details>
926
991
  <summary>render_as_json</summary>
927
992
 
@@ -947,8 +1012,8 @@ Output:
947
1012
  ---
948
1013
  </details>
949
1014
 
950
-
951
1015
  ## Installation
1016
+
952
1017
  Add this line to your application's Gemfile:
953
1018
 
954
1019
  ```ruby
@@ -956,13 +1021,15 @@ gem 'blueprinter'
956
1021
  ```
957
1022
 
958
1023
  And then execute:
1024
+
959
1025
  ```bash
960
- $ bundle
1026
+ bundle
961
1027
  ```
962
1028
 
963
1029
  Or install it yourself as:
1030
+
964
1031
  ```bash
965
- $ gem install blueprinter
1032
+ gem install blueprinter
966
1033
  ```
967
1034
 
968
1035
  You should also have `require 'json'` already in your project if you are not using Rails or if you are not using Oj.
@@ -1002,12 +1069,15 @@ end
1002
1069
  _NOTE:_ You should be doing this only if you aren't using `yajl-ruby` through the JSON API by requiring `yajl/json_gem`. More details [here](https://github.com/brianmario/yajl-ruby#json-gem-compatibility-api). In this case, `JSON.generate` is patched to use `Yajl::Encoder.encode` internally.
1003
1070
 
1004
1071
  ## Contributing
1005
- Feel free to browse the issues, converse, and make pull requests. If you need help, first please see if there is already an issue for your problem. Otherwise, go ahead and make a new issue.
1072
+
1073
+ Please read our [Contributing](CONTRIBUTING.md) file
1006
1074
 
1007
1075
  ### Tests
1076
+
1008
1077
  You can run tests with `bundle exec rake`.
1009
1078
 
1010
1079
  ### Maintain The Docs
1080
+
1011
1081
  We use Yard for documentation. Here are the following documentation rules:
1012
1082
 
1013
1083
  - Document all public methods we expect to be utilized by the end developers.
@@ -1022,7 +1092,9 @@ documentation rules:
1022
1092
  - Methods that are not set to private due to ruby visibility rule limitations should be marked with `@api private`.
1023
1093
 
1024
1094
  ### Releasing a New Version
1095
+
1025
1096
  To release a new version, change the version number in `version.rb`, and update the `CHANGELOG.md`. Finally, maintainers need to run `bundle exec rake release`, which will automatically create a git tag for the version, push git commits and tags to Github, and push the `.gem` file to rubygems.org.
1026
1097
 
1027
1098
  ## License
1099
+
1028
1100
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -1,3 +1,3 @@
1
1
  module Blueprinter
2
- VERSION = '0.25.2'.freeze
2
+ VERSION = '0.26.0'.freeze
3
3
  end
@@ -48,7 +48,6 @@ module Blueprinter
48
48
  def sortable_fields(view_name)
49
49
  excluded_fields = {}
50
50
  fields = views[:default].fields
51
- fields = merge_fields(fields, views[view_name].fields)
52
51
  views[view_name].included_view_names.each do |included_view_name|
53
52
  next if view_name == included_view_name
54
53
 
@@ -56,6 +55,7 @@ module Blueprinter
56
55
  fields = merge_fields(fields, view_fields)
57
56
  excluded_fields.merge!(view_excluded_fields)
58
57
  end
58
+ fields = merge_fields(fields, views[view_name].fields)
59
59
 
60
60
  views[view_name].excluded_field_names.each { |name| excluded_fields[name] = nil }
61
61
 
metadata CHANGED
@@ -1,16 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blueprinter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.2
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
- - Adam Hess
8
7
  - Derek Carter
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2020-11-20 00:00:00.000000000 Z
11
+ date: 2023-09-19 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 6.1.7
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 6.1.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: ammeter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.4
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.4
14
41
  - !ruby/object:Gem::Dependency
15
42
  name: factory_bot
16
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,20 +80,6 @@ dependencies:
53
80
  - - "~>"
54
81
  - !ruby/object:Gem::Version
55
82
  version: '3.0'
56
- - !ruby/object:Gem::Dependency
57
- name: yajl-ruby
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: 1.4.1
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: 1.4.1
70
83
  - !ruby/object:Gem::Dependency
71
84
  name: pry
72
85
  requirement: !ruby/object:Gem::Requirement
@@ -95,20 +108,6 @@ dependencies:
95
108
  - - ">="
96
109
  - !ruby/object:Gem::Version
97
110
  version: '0'
98
- - !ruby/object:Gem::Dependency
99
- name: activerecord
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - "~>"
103
- - !ruby/object:Gem::Version
104
- version: 5.1.2
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: 5.1.2
112
111
  - !ruby/object:Gem::Dependency
113
112
  name: rspec
114
113
  requirement: !ruby/object:Gem::Requirement
@@ -127,64 +126,64 @@ dependencies:
127
126
  name: rspec-rails
128
127
  requirement: !ruby/object:Gem::Requirement
129
128
  requirements:
130
- - - "<"
129
+ - - "~>"
131
130
  - !ruby/object:Gem::Version
132
- version: 4.0.0
131
+ version: '6.0'
133
132
  type: :development
134
133
  prerelease: false
135
134
  version_requirements: !ruby/object:Gem::Requirement
136
135
  requirements:
137
- - - "<"
136
+ - - "~>"
138
137
  - !ruby/object:Gem::Version
139
- version: 4.0.0
138
+ version: '6.0'
140
139
  - !ruby/object:Gem::Dependency
141
140
  name: sqlite3
142
141
  requirement: !ruby/object:Gem::Requirement
143
142
  requirements:
144
143
  - - "~>"
145
144
  - !ruby/object:Gem::Version
146
- version: 1.3.6
145
+ version: 1.4.2
147
146
  type: :development
148
147
  prerelease: false
149
148
  version_requirements: !ruby/object:Gem::Requirement
150
149
  requirements:
151
150
  - - "~>"
152
151
  - !ruby/object:Gem::Version
153
- version: 1.3.6
152
+ version: 1.4.2
154
153
  - !ruby/object:Gem::Dependency
155
- name: yard
154
+ name: yajl-ruby
156
155
  requirement: !ruby/object:Gem::Requirement
157
156
  requirements:
158
157
  - - "~>"
159
158
  - !ruby/object:Gem::Version
160
- version: 0.9.11
159
+ version: 1.4.1
161
160
  type: :development
162
161
  prerelease: false
163
162
  version_requirements: !ruby/object:Gem::Requirement
164
163
  requirements:
165
164
  - - "~>"
166
165
  - !ruby/object:Gem::Version
167
- version: 0.9.11
166
+ version: 1.4.1
168
167
  - !ruby/object:Gem::Dependency
169
- name: ammeter
168
+ name: yard
170
169
  requirement: !ruby/object:Gem::Requirement
171
170
  requirements:
172
171
  - - "~>"
173
172
  - !ruby/object:Gem::Version
174
- version: 1.1.4
173
+ version: 0.9.11
175
174
  type: :development
176
175
  prerelease: false
177
176
  version_requirements: !ruby/object:Gem::Requirement
178
177
  requirements:
179
178
  - - "~>"
180
179
  - !ruby/object:Gem::Version
181
- version: 1.1.4
180
+ version: 0.9.11
182
181
  description: Blueprinter is a JSON Object Presenter for Ruby that takes business objects
183
182
  and breaks them down into simple hashes and serializes them to JSON. It can be used
184
183
  in Rails in place of other serializers (like JBuilder or ActiveModelSerializers).
185
184
  It is designed to be simple, direct, and performant.
186
185
  email:
187
- - adamhess1991@gmail.com
186
+ - blueprinter@googlegroups.com
188
187
  executables: []
189
188
  extensions: []
190
189
  extra_rdoc_files: []
@@ -216,10 +215,11 @@ files:
216
215
  - lib/generators/blueprinter/blueprint_generator.rb
217
216
  - lib/generators/blueprinter/templates/blueprint.rb
218
217
  - lib/tasks/blueprinter_tasks.rake
219
- homepage: https://github.com/procore/blueprinter
218
+ homepage: https://github.com/procore-oss/blueprinter
220
219
  licenses:
221
220
  - MIT
222
- metadata: {}
221
+ metadata:
222
+ allowed_push_host: https://rubygems.org
223
223
  post_install_message:
224
224
  rdoc_options: []
225
225
  require_paths:
@@ -228,14 +228,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
228
  requirements:
229
229
  - - ">="
230
230
  - !ruby/object:Gem::Version
231
- version: 2.2.2
231
+ version: '2.7'
232
232
  required_rubygems_version: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
237
  requirements: []
238
- rubygems_version: 3.0.3
238
+ rubygems_version: 3.4.10
239
239
  signing_key:
240
240
  specification_version: 4
241
241
  summary: Simple Fast Declarative Serialization Library