blueprinter 0.26.0 → 0.30.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +55 -50
- data/README.md +17 -50
- data/Rakefile +13 -1
- data/lib/blueprinter/base.rb +10 -15
- data/lib/blueprinter/blueprinter_error.rb +2 -0
- data/lib/blueprinter/configuration.rb +14 -2
- data/lib/blueprinter/deprecation.rb +5 -3
- data/lib/blueprinter/empty_types.rb +7 -9
- data/lib/blueprinter/extractor.rb +6 -4
- data/lib/blueprinter/extractors/association_extractor.rb +8 -3
- data/lib/blueprinter/extractors/auto_extractor.rb +2 -0
- data/lib/blueprinter/extractors/block_extractor.rb +3 -1
- data/lib/blueprinter/extractors/hash_extractor.rb +2 -0
- data/lib/blueprinter/extractors/public_send_extractor.rb +3 -1
- data/lib/blueprinter/field.rb +44 -47
- data/lib/blueprinter/formatters/date_time_formatter.rb +3 -1
- data/lib/blueprinter/helpers/base_helpers.rb +17 -13
- data/lib/blueprinter/helpers/type_helpers.rb +5 -5
- data/lib/blueprinter/transformer.rb +4 -2
- data/lib/blueprinter/version.rb +3 -1
- data/lib/blueprinter/view.rb +8 -6
- data/lib/blueprinter/view_collection.rb +17 -12
- data/lib/blueprinter.rb +2 -0
- data/lib/generators/blueprinter/blueprint_generator.rb +37 -48
- data/lib/generators/blueprinter/templates/blueprint.rb +2 -0
- metadata +5 -173
- data/lib/tasks/blueprinter_tasks.rake +0 -4
@@ -1,39 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Blueprinter
|
2
4
|
module Generators
|
3
5
|
class BlueprintGenerator < ::Rails::Generators::NamedBase
|
4
|
-
desc
|
6
|
+
desc 'Generates blueprint for ActiveRecord model with the given NAME.'
|
5
7
|
|
6
8
|
attr_accessor :options
|
7
9
|
|
8
|
-
source_root File.expand_path(
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
class_option :blueprints_dir, default: "app/blueprints", desc: "path to new blueprint", aliases: "-d"
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
class_option :identifier, default: nil, desc: "Add an identifer to the generated blueprint, either uses :id or your specified value", aliases: "-i", banner: "id"
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
class_option :fields, type: :array, default: [], desc: "Manually add specified fields"
|
10
|
+
source_root File.expand_path('templates', __dir__)
|
21
11
|
|
22
|
-
class_option :
|
12
|
+
class_option :blueprints_dir, default: 'app/blueprints', desc: 'path to new blueprint', aliases: '-d'
|
23
13
|
|
14
|
+
class_option :identifier, default: nil,
|
15
|
+
desc: 'Add an identifer to the generated blueprint, either uses :id or your specified value', aliases: '-i', banner: 'id'
|
24
16
|
|
17
|
+
class_option :fields, type: :array, default: [], desc: 'Manually add specified fields'
|
25
18
|
|
26
|
-
class_option :
|
19
|
+
class_option :detect_fields, type: :boolean, default: false,
|
20
|
+
desc: 'Introspect on the model to set fields in the generated blueprint. Will be merged with any manually specified'
|
27
21
|
|
28
|
-
class_option :
|
22
|
+
class_option :associations, type: :array, default: [], desc: 'Manually add specified associations', aliases: '-a'
|
29
23
|
|
24
|
+
class_option :detect_associations, type: :boolean, default: false,
|
25
|
+
desc: 'Introspect on the model to set associations in the generated blueprint. Will be merged with any manually specified'
|
30
26
|
|
27
|
+
class_option :wrap_at, type: :numeric, default: 80, desc: 'Maximum length of generated fields line', aliases: '-w'
|
31
28
|
|
32
|
-
class_option :
|
33
|
-
|
34
|
-
class_option :indentation, type: :string, default: "two", desc: "Indentation of generated file", banner: "two|four|tab"
|
35
|
-
|
36
|
-
|
29
|
+
class_option :indentation, type: :string, default: 'two', desc: 'Indentation of generated file',
|
30
|
+
banner: 'two|four|tab'
|
37
31
|
|
38
32
|
remove_class_option :skip_namespace
|
39
33
|
|
@@ -42,30 +36,28 @@ module Blueprinter
|
|
42
36
|
end
|
43
37
|
|
44
38
|
def create_blueprint
|
45
|
-
template
|
39
|
+
template 'blueprint.rb', File.join(path, "#{file_path}_blueprint.rb")
|
46
40
|
end
|
47
41
|
|
48
|
-
|
49
|
-
|
50
42
|
private
|
51
43
|
|
52
44
|
def path
|
53
|
-
options[
|
45
|
+
options['blueprints_dir']
|
54
46
|
end
|
55
47
|
|
56
48
|
def identifier_symbol
|
57
|
-
|
58
|
-
|
59
|
-
|
49
|
+
return unless options['identifier']
|
50
|
+
|
51
|
+
options['identifier'] == 'identifier' ? :id : options['identifier']
|
60
52
|
end
|
61
53
|
|
62
54
|
def fields
|
63
|
-
fs = if options[
|
64
|
-
Array.new(options[
|
55
|
+
fs = if options['detect_fields']
|
56
|
+
Array.new(options['fields']).concat(introspected_fields)
|
65
57
|
else
|
66
|
-
options[
|
58
|
+
options['fields']
|
67
59
|
end
|
68
|
-
fs.reject
|
60
|
+
fs.reject(&:blank?).uniq
|
69
61
|
end
|
70
62
|
|
71
63
|
def introspected_fields
|
@@ -75,30 +67,29 @@ module Blueprinter
|
|
75
67
|
# split at wrap_at chars, two indentations
|
76
68
|
def formatted_fields
|
77
69
|
two_indents = indent * 2
|
78
|
-
fields_string = fields.
|
79
|
-
if
|
70
|
+
fields_string = fields.each_with_object([]) do |f, memo|
|
71
|
+
if memo.last.nil?
|
72
|
+
memo << " :#{f},"
|
73
|
+
else
|
80
74
|
now = "#{memo.last} :#{f},"
|
81
|
-
if now.length > options[
|
75
|
+
if now.length > options['wrap_at'].to_i
|
82
76
|
memo << ":#{f},"
|
83
77
|
else
|
84
78
|
memo[memo.length - 1] = now
|
85
79
|
end
|
86
|
-
else
|
87
|
-
memo << " :#{f},"
|
88
80
|
end
|
89
|
-
memo
|
90
81
|
end.join("\n#{two_indents}")
|
91
82
|
|
92
|
-
fields_string[0,fields_string.length - 1]
|
83
|
+
fields_string[0, fields_string.length - 1]
|
93
84
|
end
|
94
85
|
|
95
86
|
def associations
|
96
|
-
as = if options[
|
97
|
-
Array.new(options[
|
87
|
+
as = if options['detect_associations']
|
88
|
+
Array.new(options['associations']).concat(introspected_associations.keys)
|
98
89
|
else
|
99
|
-
options[
|
90
|
+
options['associations']
|
100
91
|
end
|
101
|
-
as.reject
|
92
|
+
as.reject(&:blank?).uniq
|
102
93
|
end
|
103
94
|
|
104
95
|
def introspected_associations
|
@@ -112,15 +103,13 @@ module Blueprinter
|
|
112
103
|
def association_class(association_name)
|
113
104
|
introspected_name = if introspected_associations[association_name].respond_to?(:klass)
|
114
105
|
introspected_associations[association_name].klass.to_s
|
115
|
-
else
|
116
|
-
nil
|
117
106
|
end
|
118
107
|
"#{introspected_name || association_name.camelcase}Blueprint"
|
119
108
|
end
|
120
109
|
|
121
110
|
def indent
|
122
|
-
user_intended = {two:
|
123
|
-
user_intended.nil? ?
|
111
|
+
user_intended = { two: ' ', four: ' ', tab: "\t" }[options['indentation'].intern]
|
112
|
+
user_intended.nil? ? ' ' : user_intended
|
124
113
|
end
|
125
114
|
end
|
126
115
|
end
|
metadata
CHANGED
@@ -1,183 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blueprinter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.30.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Procore Technologies, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
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
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: factory_bot
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: nokogiri
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 1.8.2
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 1.8.2
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: oj
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '3.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '3.0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: pry
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rake
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rspec
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '3.7'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '3.7'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rspec-rails
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '6.0'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '6.0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: sqlite3
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - "~>"
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: 1.4.2
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - "~>"
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: 1.4.2
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: yajl-ruby
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - "~>"
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: 1.4.1
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - "~>"
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: 1.4.1
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: yard
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - "~>"
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: 0.9.11
|
174
|
-
type: :development
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - "~>"
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: 0.9.11
|
11
|
+
date: 2023-09-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
181
13
|
description: Blueprinter is a JSON Object Presenter for Ruby that takes business objects
|
182
14
|
and breaks them down into simple hashes and serializes them to JSON. It can be used
|
183
15
|
in Rails in place of other serializers (like JBuilder or ActiveModelSerializers).
|
@@ -214,12 +46,12 @@ files:
|
|
214
46
|
- lib/blueprinter/view_collection.rb
|
215
47
|
- lib/generators/blueprinter/blueprint_generator.rb
|
216
48
|
- lib/generators/blueprinter/templates/blueprint.rb
|
217
|
-
- lib/tasks/blueprinter_tasks.rake
|
218
49
|
homepage: https://github.com/procore-oss/blueprinter
|
219
50
|
licenses:
|
220
51
|
- MIT
|
221
52
|
metadata:
|
222
53
|
allowed_push_host: https://rubygems.org
|
54
|
+
rubygems_mfa_required: 'true'
|
223
55
|
post_install_message:
|
224
56
|
rdoc_options: []
|
225
57
|
require_paths:
|