blueprinter_schema 0.4.2 → 0.5.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/README.md +2 -1
- data/lib/blueprinter_schema/generator.rb +5 -4
- data/lib/blueprinter_schema/version.rb +1 -1
- data/lib/blueprinter_schema.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03c37dc53060c99e65e98088279e4e635bcedd8b495c9c9d4b31c624c7b56488
|
4
|
+
data.tar.gz: 5c82b98494016b536ed9e9f360353834c5daaf28e692a4a16fa8c5e466924733
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a118085debb64d40d46aae65e8c88ddc69c0e55e49949e580966618ea14b7573a05c02a0df47aa8cac4c09bb2872b50c002e7828b275954a045728fa56115d6e
|
7
|
+
data.tar.gz: b05ee47b64997f7dbc0d16b0f8bf440e76e61d810d82b79ff3295d46f07c051b8048076db67983fd8df940e78f69b30e5504a2e646590f429993dc97ef1be5dd
|
data/README.md
CHANGED
@@ -91,7 +91,8 @@ BlueprinterSchema.generate(
|
|
91
91
|
model,
|
92
92
|
{
|
93
93
|
include_conditional_fields: true, # Whether or not to include conditional fields from the serializer
|
94
|
-
fallback_type: {} # Type when no DB column is found or type is unknown. E.g. { 'type' => 'object' }
|
94
|
+
fallback_type: {}, # Type when no DB column is found or type is unknown. E.g. { 'type' => 'object' }
|
95
|
+
view: :default # The Blueprint view to use
|
95
96
|
}
|
96
97
|
)
|
97
98
|
```
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module BlueprinterSchema
|
4
4
|
class Generator
|
5
|
-
def initialize(serializer, model, options
|
5
|
+
def initialize(serializer, model, options)
|
6
6
|
@serializer = serializer
|
7
7
|
@model = model
|
8
8
|
@options = options
|
@@ -21,11 +21,11 @@ module BlueprinterSchema
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def fields
|
24
|
-
@fields ||= @serializer.reflections[:
|
24
|
+
@fields ||= @serializer.reflections[@options[:view]].fields
|
25
25
|
end
|
26
26
|
|
27
27
|
def associations
|
28
|
-
@associations ||= @serializer.reflections[:
|
28
|
+
@associations ||= @serializer.reflections[@options[:view]].associations
|
29
29
|
end
|
30
30
|
|
31
31
|
def build_properties
|
@@ -45,7 +45,8 @@ module BlueprinterSchema
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def skip_field?(field)
|
48
|
-
!@options[:include_conditional_fields] &&
|
48
|
+
!@options[:include_conditional_fields] &&
|
49
|
+
(field.options[:if] || field.options[:unless] || field.options[:exclude_if_nil])
|
49
50
|
end
|
50
51
|
|
51
52
|
def build_required_fields
|
data/lib/blueprinter_schema.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative 'blueprinter_schema/version'
|
|
4
4
|
require_relative 'blueprinter_schema/generator'
|
5
5
|
|
6
6
|
module BlueprinterSchema
|
7
|
-
def self.generate(serializer, model, options = { include_conditional_fields: true, fallback_type: {} })
|
7
|
+
def self.generate(serializer, model, options = { include_conditional_fields: true, fallback_type: {}, view: :default })
|
8
8
|
Generator.new(serializer, model, options).generate
|
9
9
|
end
|
10
10
|
end
|