blueprinter 0.23.0 → 0.23.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/blueprinter/base.rb +1 -0
- data/lib/blueprinter/version.rb +1 -1
- data/lib/blueprinter/view.rb +13 -1
- data/lib/blueprinter/view_collection.rb +21 -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: 1a290d1ace21669c5f28a726e25b634570cf8da35654f51b0901a46fcd36de94
|
4
|
+
data.tar.gz: c065c391df542d56b63e1668096d0e83f14e67819e9e69360667290ec4d4b16a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91c21f6610e95ff9221a7a546d215f5fcef23de42e6429fe72af7ebee134bb2a5550b4a283cecf178d837f19ec12b8df782cc5bd42c5088ab8da4af09ff9d8a6
|
7
|
+
data.tar.gz: d5832253816c04b5309c7e589730f5d28ca9ef2e0dffe7cd0879bf860a360ee95b6e953062571ca83656c273612a07bd53ef70986db431b3ecf69740b3ebba6f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 0.23.1 - 2019/3/13
|
2
|
+
* 🚀 [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).
|
3
|
+
|
1
4
|
## 0.23.0 - 2019/1/31
|
2
5
|
* 🚀 [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:
|
3
6
|
```
|
data/lib/blueprinter/base.rb
CHANGED
@@ -427,6 +427,7 @@ module Blueprinter
|
|
427
427
|
# @return [View] a Blueprinter::View object
|
428
428
|
def self.view(view_name)
|
429
429
|
@current_view = view_collection[view_name]
|
430
|
+
view_collection[:default].track_definition_order(view_name)
|
430
431
|
yield
|
431
432
|
@current_view = view_collection[:default]
|
432
433
|
end
|
data/lib/blueprinter/version.rb
CHANGED
data/lib/blueprinter/view.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
module Blueprinter
|
2
2
|
# @api private
|
3
|
+
DefinitionPlaceholder = Struct.new :name, :view?
|
3
4
|
class View
|
4
|
-
attr_reader :excluded_field_names, :fields, :included_view_names, :name, :transformers
|
5
|
+
attr_reader :excluded_field_names, :fields, :included_view_names, :name, :transformers, :definition_order
|
5
6
|
|
6
7
|
def initialize(name, fields: {}, included_view_names: [], excluded_view_names: [],transformers: [])
|
7
8
|
@name = name
|
@@ -9,6 +10,14 @@ module Blueprinter
|
|
9
10
|
@included_view_names = included_view_names
|
10
11
|
@excluded_field_names = excluded_view_names
|
11
12
|
@transformers = transformers
|
13
|
+
@definition_order = []
|
14
|
+
@sort_by_definition = Blueprinter.configuration.sort_fields_by.eql?(:definition)
|
15
|
+
end
|
16
|
+
|
17
|
+
def track_definition_order(method, is_view = true)
|
18
|
+
if @sort_by_definition
|
19
|
+
@definition_order << DefinitionPlaceholder.new(method, is_view)
|
20
|
+
end
|
12
21
|
end
|
13
22
|
|
14
23
|
def inherit(view)
|
@@ -30,11 +39,13 @@ module Blueprinter
|
|
30
39
|
end
|
31
40
|
|
32
41
|
def include_view(view_name)
|
42
|
+
track_definition_order(view_name)
|
33
43
|
included_view_names << view_name
|
34
44
|
end
|
35
45
|
|
36
46
|
def include_views(view_names)
|
37
47
|
view_names.each do |view_name|
|
48
|
+
track_definition_order(view_name)
|
38
49
|
included_view_names << view_name
|
39
50
|
end
|
40
51
|
end
|
@@ -54,6 +65,7 @@ module Blueprinter
|
|
54
65
|
end
|
55
66
|
|
56
67
|
def <<(field)
|
68
|
+
track_definition_order(field.name,false)
|
57
69
|
fields[field.name] = field
|
58
70
|
end
|
59
71
|
end
|
@@ -23,8 +23,8 @@ module Blueprinter
|
|
23
23
|
def fields_for(view_name)
|
24
24
|
return identifier_fields if view_name == :identifier
|
25
25
|
|
26
|
-
|
27
|
-
sorted_fields = sort_by_definition ?
|
26
|
+
fields_hash = sortable_fields(view_name)
|
27
|
+
sorted_fields = sort_by_definition ? sort_by_def(view_name, fields_hash) : fields_hash.values.sort_by(&:name)
|
28
28
|
identifier_fields + sorted_fields
|
29
29
|
end
|
30
30
|
|
@@ -58,12 +58,27 @@ module Blueprinter
|
|
58
58
|
fields
|
59
59
|
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
# select and order members of fields according to traversal of the definition_orders
|
62
|
+
def sort_by_def(view_name, fields)
|
63
|
+
ordered_fields = {}
|
64
|
+
views[:default].definition_order.each { |definition| add_to_ordered_fields(ordered_fields, definition, fields, view_name) }
|
65
|
+
ordered_fields.values
|
66
|
+
end
|
67
|
+
|
68
|
+
# view_name_filter allows to follow definition order all the way down starting from the view_name given to sort_by_def()
|
69
|
+
# but include no others at the top-level
|
70
|
+
def add_to_ordered_fields(ordered_fields, definition, fields, view_name_filter = nil)
|
71
|
+
if definition.view?
|
72
|
+
if view_name_filter.nil? || view_name_filter == definition.name
|
73
|
+
views[definition.name].definition_order.each { |_definition| add_to_ordered_fields(ordered_fields, _definition, fields) }
|
74
|
+
end
|
64
75
|
else
|
65
|
-
|
76
|
+
ordered_fields[definition.name] = fields[definition.name]
|
66
77
|
end
|
67
78
|
end
|
79
|
+
|
80
|
+
def merge_fields(source_fields, included_fields)
|
81
|
+
source_fields.merge! included_fields
|
82
|
+
end
|
68
83
|
end
|
69
84
|
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.23.
|
4
|
+
version: 0.23.1
|
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-
|
12
|
+
date: 2020-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: factory_bot
|