blueprinter 0.24.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +19 -0
- data/lib/blueprinter/configuration.rb +2 -1
- data/lib/blueprinter/version.rb +1 -1
- data/lib/blueprinter/view.rb +10 -6
- 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: c47449bb382533a5c9dab64108c3eec2078f4f1ceba16a9cde3c46b23cb1dcc9
|
4
|
+
data.tar.gz: ea6d7fb604c37ad0bceb6db63a300da7c7946bb49ef0696ed416a674fe95f01a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48c8207d8f6a721feb45df8c15c128a73166478d708725a561861704eec7d041d92c08b8a5032bda2bba67cab138c0988976026732340086320b723e0ecab465
|
7
|
+
data.tar.gz: 1c818d65fb75800ff01ebdb15470626a2e83af578e16ef0537d67005dbb014366da34d504970fc7501e4d2fc9031601710ee4943f79fd4145ce965da06cd6e1d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 0.25.0 - 2020/7/06
|
2
|
+
* 🚀 [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).
|
3
|
+
|
1
4
|
## 0.24.0 - 2020/6/22
|
2
5
|
* 🚀 [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).
|
3
6
|
|
data/README.md
CHANGED
@@ -759,6 +759,25 @@ class UserBlueprint < Blueprinter::Base
|
|
759
759
|
end
|
760
760
|
```
|
761
761
|
|
762
|
+
#### Global Transforms
|
763
|
+
|
764
|
+
You can also specify global default transformers. Create one or more transformer classes extending from `Blueprinter::Transformer` and set the `default_transformers` configuration
|
765
|
+
```ruby
|
766
|
+
class LowerCamelTransformer < Blueprinter::Transformer
|
767
|
+
def transform(hash, _object, _options)
|
768
|
+
hash.transform_keys! { |key| key.to_s.camelize(:lower).to_sym }
|
769
|
+
end
|
770
|
+
end
|
771
|
+
```
|
772
|
+
|
773
|
+
```ruby
|
774
|
+
Blueprinter.configure do |config|
|
775
|
+
config.default_transformers = [LowerCamelTransformer]
|
776
|
+
end
|
777
|
+
```
|
778
|
+
|
779
|
+
**Note: Any transforms specified on a per-blueprint or per-view level will override the `default_transformers` in the configuration.**
|
780
|
+
|
762
781
|
---
|
763
782
|
</details>
|
764
783
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Blueprinter
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :association_default, :datetime_format, :field_default, :generator, :if, :method, :sort_fields_by, :unless, :extractor_default
|
3
|
+
attr_accessor :association_default, :datetime_format, :field_default, :generator, :if, :method, :sort_fields_by, :unless, :extractor_default, :default_transformers
|
4
4
|
|
5
5
|
VALID_CALLABLES = %i(if unless).freeze
|
6
6
|
|
@@ -14,6 +14,7 @@ module Blueprinter
|
|
14
14
|
@sort_fields_by = :name_asc
|
15
15
|
@unless = nil
|
16
16
|
@extractor_default = AutoExtractor
|
17
|
+
@default_transformers = []
|
17
18
|
end
|
18
19
|
|
19
20
|
def jsonify(blob)
|
data/lib/blueprinter/version.rb
CHANGED
data/lib/blueprinter/view.rb
CHANGED
@@ -2,18 +2,22 @@ module Blueprinter
|
|
2
2
|
# @api private
|
3
3
|
DefinitionPlaceholder = Struct.new :name, :view?
|
4
4
|
class View
|
5
|
-
attr_reader :excluded_field_names, :fields, :included_view_names, :name, :
|
5
|
+
attr_reader :excluded_field_names, :fields, :included_view_names, :name, :view_transformers, :definition_order
|
6
6
|
|
7
|
-
def initialize(name, fields: {}, included_view_names: [], excluded_view_names: [],transformers: [])
|
7
|
+
def initialize(name, fields: {}, included_view_names: [], excluded_view_names: [], transformers: [])
|
8
8
|
@name = name
|
9
9
|
@fields = fields
|
10
10
|
@included_view_names = included_view_names
|
11
11
|
@excluded_field_names = excluded_view_names
|
12
|
-
@
|
12
|
+
@view_transformers = transformers
|
13
13
|
@definition_order = []
|
14
14
|
@sort_by_definition = Blueprinter.configuration.sort_fields_by.eql?(:definition)
|
15
15
|
end
|
16
16
|
|
17
|
+
def transformers
|
18
|
+
view_transformers.empty? ? Blueprinter.configuration.default_transformers : view_transformers
|
19
|
+
end
|
20
|
+
|
17
21
|
def track_definition_order(method, is_view = true)
|
18
22
|
if @sort_by_definition
|
19
23
|
@definition_order << DefinitionPlaceholder.new(method, is_view)
|
@@ -33,8 +37,8 @@ module Blueprinter
|
|
33
37
|
exclude_field(field_name)
|
34
38
|
end
|
35
39
|
|
36
|
-
view.
|
37
|
-
|
40
|
+
view.view_transformers.each do |transformer|
|
41
|
+
add_transformer(transformer)
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
@@ -61,7 +65,7 @@ module Blueprinter
|
|
61
65
|
end
|
62
66
|
|
63
67
|
def add_transformer(custom_transformer)
|
64
|
-
|
68
|
+
view_transformers << custom_transformer
|
65
69
|
end
|
66
70
|
|
67
71
|
def <<(field)
|
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.25.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: 2020-06
|
12
|
+
date: 2020-07-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: factory_bot
|