blueprinter 1.1.2 → 1.3.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 +25 -5
- data/README.md +83 -5
- data/lib/blueprinter/association.rb +2 -2
- data/lib/blueprinter/base.rb +363 -419
- data/lib/blueprinter/blueprint_validator.rb +4 -8
- data/lib/blueprinter/configuration.rb +34 -7
- data/lib/blueprinter/errors/invalid_blueprint.rb +1 -1
- data/lib/blueprinter/errors/invalid_root.rb +13 -0
- data/lib/blueprinter/errors/meta_requires_root.rb +13 -0
- data/lib/blueprinter/extractors/association_extractor.rb +23 -5
- data/lib/blueprinter/extractors/block_extractor.rb +25 -1
- data/lib/blueprinter/field.rb +2 -6
- data/lib/blueprinter/formatters/date_time_formatter.rb +1 -1
- data/lib/blueprinter/reflection.rb +3 -3
- data/lib/blueprinter/rendering.rb +202 -0
- data/lib/blueprinter/version.rb +1 -1
- data/lib/blueprinter/view_collection.rb +87 -11
- data/lib/blueprinter.rb +3 -2
- data/lib/generators/blueprinter/blueprint_generator.rb +1 -1
- metadata +10 -8
- data/lib/blueprinter/helpers/base_helpers.rb +0 -104
- /data/lib/generators/blueprinter/templates/{blueprint.rb → blueprint.erb} +0 -0
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: blueprinter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Procore Technologies, Inc.
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-04-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Blueprinter is a JSON Object Presenter for Ruby that takes business objects
|
|
14
14
|
and breaks them down into simple hashes and serializes them to JSON. It can be used
|
|
@@ -34,6 +34,8 @@ files:
|
|
|
34
34
|
- lib/blueprinter/empty_types.rb
|
|
35
35
|
- lib/blueprinter/errors.rb
|
|
36
36
|
- lib/blueprinter/errors/invalid_blueprint.rb
|
|
37
|
+
- lib/blueprinter/errors/invalid_root.rb
|
|
38
|
+
- lib/blueprinter/errors/meta_requires_root.rb
|
|
37
39
|
- lib/blueprinter/extension.rb
|
|
38
40
|
- lib/blueprinter/extensions.rb
|
|
39
41
|
- lib/blueprinter/extractor.rb
|
|
@@ -44,22 +46,22 @@ files:
|
|
|
44
46
|
- lib/blueprinter/extractors/public_send_extractor.rb
|
|
45
47
|
- lib/blueprinter/field.rb
|
|
46
48
|
- lib/blueprinter/formatters/date_time_formatter.rb
|
|
47
|
-
- lib/blueprinter/helpers/base_helpers.rb
|
|
48
49
|
- lib/blueprinter/helpers/type_helpers.rb
|
|
49
50
|
- lib/blueprinter/reflection.rb
|
|
51
|
+
- lib/blueprinter/rendering.rb
|
|
50
52
|
- lib/blueprinter/transformer.rb
|
|
51
53
|
- lib/blueprinter/version.rb
|
|
52
54
|
- lib/blueprinter/view.rb
|
|
53
55
|
- lib/blueprinter/view_collection.rb
|
|
54
56
|
- lib/generators/blueprinter/blueprint_generator.rb
|
|
55
|
-
- lib/generators/blueprinter/templates/blueprint.
|
|
57
|
+
- lib/generators/blueprinter/templates/blueprint.erb
|
|
56
58
|
homepage: https://github.com/procore-oss/blueprinter
|
|
57
59
|
licenses:
|
|
58
60
|
- MIT
|
|
59
61
|
metadata:
|
|
60
62
|
allowed_push_host: https://rubygems.org
|
|
61
63
|
rubygems_mfa_required: 'true'
|
|
62
|
-
post_install_message:
|
|
64
|
+
post_install_message:
|
|
63
65
|
rdoc_options: []
|
|
64
66
|
require_paths:
|
|
65
67
|
- lib
|
|
@@ -67,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
67
69
|
requirements:
|
|
68
70
|
- - ">="
|
|
69
71
|
- !ruby/object:Gem::Version
|
|
70
|
-
version: '3.
|
|
72
|
+
version: '3.1'
|
|
71
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
74
|
requirements:
|
|
73
75
|
- - ">="
|
|
@@ -75,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
75
77
|
version: '0'
|
|
76
78
|
requirements: []
|
|
77
79
|
rubygems_version: 3.4.19
|
|
78
|
-
signing_key:
|
|
80
|
+
signing_key:
|
|
79
81
|
specification_version: 4
|
|
80
82
|
summary: Simple Fast Declarative Serialization Library
|
|
81
83
|
test_files: []
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'blueprinter/helpers/type_helpers'
|
|
4
|
-
require 'blueprinter/view_collection'
|
|
5
|
-
|
|
6
|
-
module Blueprinter
|
|
7
|
-
module BaseHelpers
|
|
8
|
-
def self.included(base)
|
|
9
|
-
base.extend(SingletonMethods)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
module SingletonMethods
|
|
13
|
-
include TypeHelpers
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
def prepare_for_render(object, options)
|
|
18
|
-
view_name = options.fetch(:view, :default) || :default
|
|
19
|
-
root = options[:root]
|
|
20
|
-
meta = options[:meta]
|
|
21
|
-
validate_root_and_meta!(root, meta)
|
|
22
|
-
prepare(
|
|
23
|
-
object,
|
|
24
|
-
view_name: view_name,
|
|
25
|
-
local_options: options.except(
|
|
26
|
-
:view,
|
|
27
|
-
:root,
|
|
28
|
-
:meta
|
|
29
|
-
),
|
|
30
|
-
root: root,
|
|
31
|
-
meta: meta
|
|
32
|
-
)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def prepare_data(object, view_name, local_options)
|
|
36
|
-
if array_like?(object)
|
|
37
|
-
object.map do |obj|
|
|
38
|
-
object_to_hash(obj,
|
|
39
|
-
view_name: view_name,
|
|
40
|
-
local_options: local_options)
|
|
41
|
-
end
|
|
42
|
-
else
|
|
43
|
-
object_to_hash(object,
|
|
44
|
-
view_name: view_name,
|
|
45
|
-
local_options: local_options)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def prepend_root_and_meta(data, root, meta)
|
|
50
|
-
return data unless root
|
|
51
|
-
|
|
52
|
-
ret = { root => data }
|
|
53
|
-
meta ? ret.merge!(meta: meta) : ret
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def inherited(subclass)
|
|
57
|
-
subclass.send(:view_collection).inherit(view_collection)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def object_to_hash(object, view_name:, local_options:)
|
|
61
|
-
result_hash = view_collection.fields_for(view_name).each_with_object({}) do |field, hash|
|
|
62
|
-
next if field.skip?(field.name, object, local_options)
|
|
63
|
-
|
|
64
|
-
value = field.extract(object, local_options)
|
|
65
|
-
|
|
66
|
-
next if value.nil? && field.options[:exclude_if_nil]
|
|
67
|
-
|
|
68
|
-
hash[field.name] = value
|
|
69
|
-
end
|
|
70
|
-
view_collection.transformers(view_name).each do |transformer|
|
|
71
|
-
transformer.transform(result_hash, object, local_options)
|
|
72
|
-
end
|
|
73
|
-
result_hash
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def validate_root_and_meta!(root, meta)
|
|
77
|
-
case root
|
|
78
|
-
when String, Symbol
|
|
79
|
-
# no-op
|
|
80
|
-
when NilClass
|
|
81
|
-
raise BlueprinterError, 'meta requires a root to be passed' if meta
|
|
82
|
-
else
|
|
83
|
-
raise BlueprinterError, 'root should be one of String, Symbol, NilClass'
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def jsonify(blob)
|
|
88
|
-
Blueprinter.configuration.jsonify(blob)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def current_view
|
|
92
|
-
@current_view ||= view_collection[:default]
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def view_collection
|
|
96
|
-
@view_collection ||= ViewCollection.new
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def associations(view_name = :default)
|
|
100
|
-
view_collection.fields_for(view_name).select { |f| f.options[:association] }
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
File without changes
|