blueprinter 0.26.0 → 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,183 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blueprinter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.0
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
- - Derek Carter
7
+ - Procore Technologies, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-19 00:00:00.000000000 Z
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:
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :blueprinter do
3
- # # Task goes here
4
- # end