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