blueprinter 0.25.3 → 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/blueprinter.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'blueprinter/base'
2
4
 
3
5
  module Blueprinter
@@ -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 "Generates blueprint for ActiveRecord model with the given NAME."
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("../templates", __FILE__)
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 :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"
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 :associations, type: :array, default: [], desc: "Manually add specified associations", aliases: "-a"
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 :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"
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 :wrap_at, type: :numeric, default: 80, desc: "Maximum length of generated fields line", aliases: "-w"
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 "blueprint.rb", File.join(path, "#{file_path}_blueprint.rb")
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["blueprints_dir"]
45
+ options['blueprints_dir']
54
46
  end
55
47
 
56
48
  def identifier_symbol
57
- if options['identifier']
58
- options['identifier'] == "identifier" ? :id : options['identifier']
59
- end
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["detect_fields"]
64
- Array.new(options["fields"]).concat(introspected_fields)
55
+ fs = if options['detect_fields']
56
+ Array.new(options['fields']).concat(introspected_fields)
65
57
  else
66
- options["fields"]
58
+ options['fields']
67
59
  end
68
- fs.reject {|f| f.blank? }.uniq
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.reduce([]) do |memo, f|
79
- if !memo.last.nil?
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["wrap_at"].to_i
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["detect_associations"]
97
- Array.new(options["associations"]).concat(introspected_associations.keys)
87
+ as = if options['detect_associations']
88
+ Array.new(options['associations']).concat(introspected_associations.keys)
98
89
  else
99
- options["associations"]
90
+ options['associations']
100
91
  end
101
- as.reject {|f| f.blank? }.uniq
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: " ", four: " ", tab:"\t"}[options["indentation"].intern]
123
- user_intended.nil? ? " " : user_intended
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class <%= class_name %>Blueprint < Blueprinter::Base
2
4
  <% if identifier_symbol -%>
3
5
  <%= indent -%>identifier :<%= identifier_symbol %>
metadata CHANGED
@@ -1,190 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blueprinter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.3
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
- - Adam Hess
8
- - Derek Carter
7
+ - Procore Technologies, Inc.
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2021-03-03 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: factory_bot
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
- - !ruby/object:Gem::Dependency
29
- name: nokogiri
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: 1.8.2
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: 1.8.2
42
- - !ruby/object:Gem::Dependency
43
- name: oj
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: '3.0'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: '3.0'
56
- - !ruby/object:Gem::Dependency
57
- name: yajl-ruby
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: 1.4.1
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: 1.4.1
70
- - !ruby/object:Gem::Dependency
71
- name: pry
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: '0'
84
- - !ruby/object:Gem::Dependency
85
- name: rake
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: '0'
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: '0'
98
- - !ruby/object:Gem::Dependency
99
- name: activerecord
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - "~>"
103
- - !ruby/object:Gem::Version
104
- version: 5.1.2
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: 5.1.2
112
- - !ruby/object:Gem::Dependency
113
- name: rspec
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - "~>"
117
- - !ruby/object:Gem::Version
118
- version: '3.7'
119
- type: :development
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - "~>"
124
- - !ruby/object:Gem::Version
125
- version: '3.7'
126
- - !ruby/object:Gem::Dependency
127
- name: rspec-rails
128
- requirement: !ruby/object:Gem::Requirement
129
- requirements:
130
- - - "<"
131
- - !ruby/object:Gem::Version
132
- version: 4.0.0
133
- type: :development
134
- prerelease: false
135
- version_requirements: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - "<"
138
- - !ruby/object:Gem::Version
139
- version: 4.0.0
140
- - !ruby/object:Gem::Dependency
141
- name: sqlite3
142
- requirement: !ruby/object:Gem::Requirement
143
- requirements:
144
- - - "~>"
145
- - !ruby/object:Gem::Version
146
- version: 1.3.6
147
- type: :development
148
- prerelease: false
149
- version_requirements: !ruby/object:Gem::Requirement
150
- requirements:
151
- - - "~>"
152
- - !ruby/object:Gem::Version
153
- version: 1.3.6
154
- - !ruby/object:Gem::Dependency
155
- name: yard
156
- requirement: !ruby/object:Gem::Requirement
157
- requirements:
158
- - - "~>"
159
- - !ruby/object:Gem::Version
160
- version: 0.9.11
161
- type: :development
162
- prerelease: false
163
- version_requirements: !ruby/object:Gem::Requirement
164
- requirements:
165
- - - "~>"
166
- - !ruby/object:Gem::Version
167
- version: 0.9.11
168
- - !ruby/object:Gem::Dependency
169
- name: ammeter
170
- requirement: !ruby/object:Gem::Requirement
171
- requirements:
172
- - - "~>"
173
- - !ruby/object:Gem::Version
174
- version: 1.1.4
175
- type: :development
176
- prerelease: false
177
- version_requirements: !ruby/object:Gem::Requirement
178
- requirements:
179
- - - "~>"
180
- - !ruby/object:Gem::Version
181
- version: 1.1.4
11
+ date: 2023-09-20 00:00:00.000000000 Z
12
+ dependencies: []
182
13
  description: Blueprinter is a JSON Object Presenter for Ruby that takes business objects
183
14
  and breaks them down into simple hashes and serializes them to JSON. It can be used
184
15
  in Rails in place of other serializers (like JBuilder or ActiveModelSerializers).
185
16
  It is designed to be simple, direct, and performant.
186
17
  email:
187
- - adamhess1991@gmail.com
18
+ - blueprinter@googlegroups.com
188
19
  executables: []
189
20
  extensions: []
190
21
  extra_rdoc_files: []
@@ -215,11 +46,12 @@ files:
215
46
  - lib/blueprinter/view_collection.rb
216
47
  - lib/generators/blueprinter/blueprint_generator.rb
217
48
  - lib/generators/blueprinter/templates/blueprint.rb
218
- - lib/tasks/blueprinter_tasks.rake
219
- homepage: https://github.com/procore/blueprinter
49
+ homepage: https://github.com/procore-oss/blueprinter
220
50
  licenses:
221
51
  - MIT
222
- metadata: {}
52
+ metadata:
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:
@@ -228,14 +60,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
60
  requirements:
229
61
  - - ">="
230
62
  - !ruby/object:Gem::Version
231
- version: 2.2.2
63
+ version: '2.7'
232
64
  required_rubygems_version: !ruby/object:Gem::Requirement
233
65
  requirements:
234
66
  - - ">="
235
67
  - !ruby/object:Gem::Version
236
68
  version: '0'
237
69
  requirements: []
238
- rubygems_version: 3.0.3
70
+ rubygems_version: 3.4.10
239
71
  signing_key:
240
72
  specification_version: 4
241
73
  summary: Simple Fast Declarative Serialization Library
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :blueprinter do
3
- # # Task goes here
4
- # end