hot-glue 0.0.6 → 0.0.7
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/Gemfile.lock +1 -1
- data/README.md +19 -2
- data/db/migrate/20210306223300_create_defs.rb +1 -1
- data/db/schema.rb +1 -0
- data/lib/generators/hot_glue/scaffold_generator.rb +58 -24
- data/lib/generators/hot_glue/templates/_show.haml +1 -1
- data/lib/generators/hot_glue/templates/controller.rb.erb +1 -0
- data/lib/generators/hot_glue/templates/edit.haml +2 -0
- data/lib/generators/hot_glue/templates/{controller_spec.rb.erb → request_spec.rb.erb} +0 -0
- data/lib/generators/hot_glue/templates/system_spec.rb.erb +109 -0
- data/lib/hotglue/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d747beed420f47b73a42783e6ae92edd8f4508b13c471a7ae7747a1a7eddfe58
|
4
|
+
data.tar.gz: 9feb6afe2493e46d7e4eef0db0c836f3d140e33c20555c5f07e7fbc896fef366
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf3dcb49cf4a37919269ff3812d00668e2739830c6f01b1f3cc86a01abc78c3278214bb27e3c3935cf60e640460482c8b79bc1127263790e349bf82f3ea4b443
|
7
|
+
data.tar.gz: 7b9576bb6ee658ffb2c05cc7a5f0c77383e70964c174e361d993c5f6f4162b94be69452fceed1fdd1988d8876b43c14c7f16b95d564136b9167604e75ee3a287
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -233,9 +233,21 @@ You don't need this if the pluralized version is just + "s" of the singular vers
|
|
233
233
|
|
234
234
|
By default, all fields are included unless they are on the exclude list. (The default for the exclude list is `id`, `created_at`, and `updated_at` so you don't need to exclude those-- they are added.)
|
235
235
|
|
236
|
-
If you specify an exclude list, those
|
236
|
+
If you specify an exclude list, those and the default excluded list will be excluded.
|
237
237
|
|
238
238
|
|
239
|
+
`rails generate hot_glue:scaffold Account --exclude=password`
|
240
|
+
|
241
|
+
(The default excluded list is: :id, :created_at, :updated_at, :encrypted_password, :reset_password_token, :reset_password_sent_at, :remember_created_at, :confirmation_token, :confirmed_at, :confirmation_sent_at, :unconfirmed_email. If you want to edit any fields with the same name, you must use the include flag instead.)
|
242
|
+
|
243
|
+
|
244
|
+
### `--include=`
|
245
|
+
(separate field names by COMMA)
|
246
|
+
|
247
|
+
You may not specify both include and exclude. If you specify an include list, it will be treated as a whitelist: no fields will be included unless specified on the include list.
|
248
|
+
|
249
|
+
`rails generate hot_glue:scaffold Account --include=first_name,last_name,company_name,created_at,kyc_verified_at`
|
250
|
+
|
239
251
|
|
240
252
|
### `--god` or `--gd`
|
241
253
|
|
@@ -277,12 +289,17 @@ Omits create action.
|
|
277
289
|
|
278
290
|
Omits delete action.
|
279
291
|
|
292
|
+
### `--big-edit`
|
293
|
+
|
294
|
+
If you do not want inline editing of your list items but instead to fall back to old fashioned new page behavior for your edit views, use `--big-edit`.
|
280
295
|
|
281
296
|
|
282
297
|
|
283
298
|
# VERSION HISTORY
|
284
299
|
|
285
|
-
#### 2021-03-
|
300
|
+
#### 2021-03-20 - v0.0.7 - adds lots of spec coverage; cleans up generated cruft code on each run; adds no-delete, no-create; a working --big-edit with basic data-turbo false to disable inline editing
|
301
|
+
|
302
|
+
#### 2021-03-06 - v0.0.6 - internal specs test the error catches and cover basic code generation (dummy testing only)
|
286
303
|
|
287
304
|
#### 2021-03-01 - v0.0.5 - Validation magic; refactors the options to the correct Rails::Generators syntax
|
288
305
|
|
data/db/schema.rb
CHANGED
@@ -22,6 +22,7 @@ ActiveRecord::Schema.define(version: 2021_03_06_225506) do
|
|
22
22
|
|
23
23
|
create_table "defs", force: :cascade do |t|
|
24
24
|
t.integer "user_id"
|
25
|
+
t.string "name"
|
25
26
|
t.datetime "created_at", precision: 6, null: false
|
26
27
|
t.datetime "updated_at", precision: 6, null: false
|
27
28
|
end
|
@@ -52,12 +52,15 @@ module HotGlue
|
|
52
52
|
class_option :auth, type: :string, default: nil
|
53
53
|
class_option :auth_identifier, type: :string, default: nil
|
54
54
|
class_option :exclude, type: :string, default: ""
|
55
|
+
class_option :include, type: :string, default: ""
|
55
56
|
class_option :god, type: :boolean, default: false
|
57
|
+
class_option :gd, type: :boolean, default: false # alias for god
|
56
58
|
class_option :spacs_only, type: :boolean, default: false
|
57
59
|
class_option :no_specs, type: :boolean, default: false
|
58
60
|
class_option :no_delete, type: :boolean, default: false
|
59
61
|
class_option :no_create, type: :boolean, default: false
|
60
62
|
class_option :no_paginate, type: :boolean, default: false
|
63
|
+
class_option :big_edit, type: :boolean, default: false
|
61
64
|
|
62
65
|
def initialize(*meta_args) #:nodoc:
|
63
66
|
super
|
@@ -84,13 +87,21 @@ module HotGlue
|
|
84
87
|
@singular_class = @singular.titleize.gsub(" ", "")
|
85
88
|
@exclude_fields = []
|
86
89
|
@exclude_fields += options['exclude'].split(",").collect(&:to_sym)
|
90
|
+
|
91
|
+
if options['include']
|
92
|
+
@include_fields = []
|
93
|
+
@include_fields += options['include'].split(",").collect(&:to_sym)
|
94
|
+
end
|
87
95
|
auth_assoc = @auth.gsub("current_","")
|
96
|
+
|
88
97
|
@god = options['god'] || options['gd'] || false
|
89
|
-
@specs_only = options['
|
90
|
-
@no_specs = options['
|
91
|
-
@no_delete = options['
|
92
|
-
|
93
|
-
@
|
98
|
+
@specs_only = options['specs_only'] || false
|
99
|
+
@no_specs = options['no_specs'] || false
|
100
|
+
@no_delete = options['no_delete'] || false
|
101
|
+
|
102
|
+
@no_create = options['no_create'] || false
|
103
|
+
@no_paginate = options['no_paginate'] || false
|
104
|
+
@big_edit = options['big_edit']
|
94
105
|
|
95
106
|
if @god
|
96
107
|
@auth = nil
|
@@ -144,15 +155,26 @@ module HotGlue
|
|
144
155
|
end
|
145
156
|
end
|
146
157
|
|
147
|
-
@exclude_fields.push :id, :created_at, :updated_at, :encrypted_password,
|
148
|
-
:reset_password_token,
|
149
|
-
:reset_password_sent_at, :remember_created_at,
|
150
|
-
:confirmation_token, :confirmed_at,
|
151
|
-
:confirmation_sent_at, :unconfirmed_email
|
152
158
|
|
153
|
-
|
154
|
-
|
155
|
-
|
159
|
+
if !@include_fields
|
160
|
+
@exclude_fields.push :id, :created_at, :updated_at, :encrypted_password,
|
161
|
+
:reset_password_token,
|
162
|
+
:reset_password_sent_at, :remember_created_at,
|
163
|
+
:confirmation_token, :confirmed_at,
|
164
|
+
:confirmation_sent_at, :unconfirmed_email
|
165
|
+
|
166
|
+
@exclude_fields.push(auth_assoc_field.to_sym) if !auth_assoc_field.nil?
|
167
|
+
@exclude_fields.push(ownership_field.to_sym) if !ownership_field.nil?
|
168
|
+
|
169
|
+
|
170
|
+
@columns = object.columns.map(&:name).map(&:to_sym).reject{|field| @exclude_fields.include?(field) }
|
171
|
+
|
172
|
+
else
|
173
|
+
@columns = object.columns.map(&:name).map(&:to_sym).reject{|field| !@include_fields.include?(field) }
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
|
156
178
|
|
157
179
|
@columns.each do |col|
|
158
180
|
if object.columns_hash[col.to_s].type == :integer
|
@@ -175,6 +197,7 @@ module HotGlue
|
|
175
197
|
exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
|
176
198
|
raise(HotGlue::Error,exit_message)
|
177
199
|
end
|
200
|
+
|
178
201
|
assoc_class = eval(assoc.class_name)
|
179
202
|
if assoc_class.column_names.include?("name")
|
180
203
|
# display_column = "name"
|
@@ -210,14 +233,16 @@ module HotGlue
|
|
210
233
|
@default_colspan = @columns.size
|
211
234
|
|
212
235
|
unless @specs_only
|
213
|
-
template "controller.rb", File.join("#{'spec/dummy/' if Rails.env.test?}app/controllers#{namespace_with_dash}", "#{plural}_controller.rb")
|
236
|
+
template "controller.rb.erb", File.join("#{'spec/dummy/' if Rails.env.test?}app/controllers#{namespace_with_dash}", "#{plural}_controller.rb")
|
214
237
|
if @namespace && defined?(controller_descends_from) == nil
|
215
|
-
template "base_controller.rb", File.join("#{'spec/dummy/' if Rails.env.test?}app/controllers#{namespace_with_dash}", "base_controller.rb")
|
238
|
+
template "base_controller.rb.erb", File.join("#{'spec/dummy/' if Rails.env.test?}app/controllers#{namespace_with_dash}", "base_controller.rb")
|
216
239
|
end
|
217
240
|
end
|
218
241
|
|
219
242
|
unless @no_specs
|
220
|
-
template "
|
243
|
+
template "request_spec.rb.erb", File.join("#{'spec/dummy/' if Rails.env.test?}spec/request#{namespace_with_dash}", "#{plural}_spec.rb")
|
244
|
+
template "system_spec.rb.erb", File.join("#{'spec/dummy/' if Rails.env.test?}spec/system#{namespace_with_dash}", "#{plural}_spec.rb")
|
245
|
+
|
221
246
|
end
|
222
247
|
|
223
248
|
template "_errors.haml", File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}", "_errors.haml")
|
@@ -444,13 +469,21 @@ module HotGlue
|
|
444
469
|
end
|
445
470
|
|
446
471
|
def haml_views
|
447
|
-
res = %w(index edit
|
472
|
+
res = %w(index edit _form _line _list _show _errors)
|
473
|
+
|
474
|
+
unless @no_create
|
475
|
+
res += %w(new _new_form _new_button)
|
476
|
+
end
|
448
477
|
|
449
478
|
res
|
450
479
|
end
|
451
480
|
|
452
481
|
def turbo_stream_views
|
453
|
-
res = %w(create
|
482
|
+
res = %w(create edit update)
|
483
|
+
unless @no_delete
|
484
|
+
res << 'destroy'
|
485
|
+
end
|
486
|
+
res
|
454
487
|
end
|
455
488
|
|
456
489
|
def handler
|
@@ -678,18 +711,19 @@ module HotGlue
|
|
678
711
|
|
679
712
|
def display_class
|
680
713
|
me = eval(singular_class)
|
714
|
+
|
681
715
|
@display_class ||=
|
682
|
-
if me.
|
716
|
+
if me.respond_to?("name")
|
683
717
|
"name"
|
684
|
-
elsif me.
|
718
|
+
elsif me.respond_to?("to_label")
|
685
719
|
"to_label"
|
686
|
-
elsif me.
|
720
|
+
elsif me.respond_to?("full_name")
|
687
721
|
"full_name"
|
688
|
-
elsif me.
|
722
|
+
elsif me.respond_to?("display_name")
|
689
723
|
"display_name"
|
690
|
-
elsif me.
|
724
|
+
elsif me.respond_to?("email")
|
691
725
|
"email"
|
692
|
-
elsif me.
|
726
|
+
elsif me.respond_to?("number")
|
693
727
|
display_column = "number"
|
694
728
|
|
695
729
|
else
|
@@ -4,4 +4,4 @@
|
|
4
4
|
= link_to "Delete <i class='fa fa-1x fa-remove'></i>".html_safe, <%= path_helper_full %>(<%= path_helper_args %>), method: :delete, data: {confirm: 'Are you sure?'}, disable_with: "Loading...", class: "delete-<%= singular %>-button btn btn-primary "
|
5
5
|
<% end %>
|
6
6
|
|
7
|
-
= link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%= path_helper_full %>(<%= path_helper_args %>),
|
7
|
+
= link_to "Edit <i class='fa fa-1x fa-list-alt'></i>".html_safe, edit_<%= path_helper_full %>(<%= path_helper_args %>), <% if @big_edit %>'data-turbo' => 'false', <% end %>disable_with: "Loading...", class: "edit-<%= singular %>-button btn btn-primary "
|
@@ -46,6 +46,7 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
|
|
46
46
|
format.html
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
49
50
|
def create
|
50
51
|
modified_params = modify_date_inputs_on_params(<%=singular_name %>_params.dup<% if !@object_owner_sym.empty? %>.merge!(<%= @object_owner_sym %>: <%= @object_owner_eval %> )<% end %> <%= @auth ? ', ' + @auth : '' %>)
|
51
52
|
@<%=singular_name %> = <%=class_name %>.create(modified_params)
|
File without changes
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe "interaction for <%= controller_class_name %>", type: :feature do
|
4
|
+
<% unless @auth.nil? %> let(:<%= @auth %>) {create(:<%= @auth.gsub('current_', '') %>)}<%end%>
|
5
|
+
let(:<%= singular %>) {create(:<%= singular %><%= object_parent_mapping_as_argument_for_specs %> )}
|
6
|
+
|
7
|
+
<%= objest_nest_factory_setup %>
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@request.env["devise.mapping"] = Devise.mappings[:account]
|
11
|
+
|
12
|
+
sign_in <%= @auth %>, scope: :<%= @auth %>
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "index" do
|
16
|
+
it "should respond" do
|
17
|
+
get :index, xhr: true, format: 'js', params: {
|
18
|
+
<%= objest_nest_params_by_id_for_specs %>
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "new" do
|
24
|
+
it "should show form" do
|
25
|
+
get :new, xhr: true, format: 'js', params: {
|
26
|
+
<%= objest_nest_params_by_id_for_specs %>
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "create" do
|
32
|
+
it "should create a new <%= singular %>" do
|
33
|
+
expect {
|
34
|
+
post :create, xhr: true, format: 'js', params: {
|
35
|
+
<%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
|
36
|
+
<%= singular %>: {
|
37
|
+
<%= columns_spec_with_sample_data %>
|
38
|
+
}}
|
39
|
+
}.to change { <%= @singular_class %>.all.count }.by(1)
|
40
|
+
assert_response :ok
|
41
|
+
end
|
42
|
+
|
43
|
+
# it "should not create if there are errors" do
|
44
|
+
# post :create, xhr: true, format: 'js', params: {id: <%= singular %>.id,
|
45
|
+
# <%= singular %>: {skin_id: nil}}
|
46
|
+
#
|
47
|
+
# expect(controller).to set_flash.now[:alert].to(/Oops, your <%= singular %> could not be saved/)
|
48
|
+
# end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "edit" do
|
52
|
+
it "should return an editable form" do
|
53
|
+
get :edit, xhr: true, format: 'js', params: {
|
54
|
+
<%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
|
55
|
+
id: <%= singular %>.id
|
56
|
+
}
|
57
|
+
assert_response :ok
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "show" do
|
62
|
+
it "should return a view form" do
|
63
|
+
get :show, xhr: true, format: 'js', params: {
|
64
|
+
<%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
|
65
|
+
id: <%= singular %>.id
|
66
|
+
}
|
67
|
+
assert_response :ok
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "update" do
|
72
|
+
it "should update" do
|
73
|
+
put :update, xhr: true, format: 'js',
|
74
|
+
params: {
|
75
|
+
<%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
|
76
|
+
id: <%= singular %>.id,
|
77
|
+
<%= singular %>: {
|
78
|
+
<%= columns_spec_with_sample_data %>
|
79
|
+
}}
|
80
|
+
|
81
|
+
assert_response :ok
|
82
|
+
end
|
83
|
+
|
84
|
+
# it "should not update if invalid" do
|
85
|
+
# put :update, xhr: true, format: 'js',
|
86
|
+
# params: {
|
87
|
+
# id: <%= singular %>.id,
|
88
|
+
# <%= singular %>: {
|
89
|
+
# <%= columns_spec_with_sample_data %>
|
90
|
+
# }}
|
91
|
+
#
|
92
|
+
# assert_response :ok
|
93
|
+
#
|
94
|
+
# expect(controller).to set_flash.now[:alert].to(/Oops, your <%= singular %> could not be saved/)
|
95
|
+
# end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#destroy" do
|
99
|
+
it "should destroy" do
|
100
|
+
post :destroy, format: 'js', params: {
|
101
|
+
<%= (@nested_args.empty? ? "" : objest_nest_params_by_id_for_specs + ",") %>
|
102
|
+
id: <%= singular %>.id
|
103
|
+
}
|
104
|
+
assert_response :ok
|
105
|
+
expect(<%= @singular_class %>.count).to be(0)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
data/lib/hotglue/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hot-glue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Fleetwood-Boldt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -132,13 +132,14 @@ files:
|
|
132
132
|
- lib/generators/hot_glue/templates/_show.haml
|
133
133
|
- lib/generators/hot_glue/templates/base_controller.rb.erb
|
134
134
|
- lib/generators/hot_glue/templates/controller.rb.erb
|
135
|
-
- lib/generators/hot_glue/templates/controller_spec.rb.erb
|
136
135
|
- lib/generators/hot_glue/templates/create.turbo_stream.haml
|
137
136
|
- lib/generators/hot_glue/templates/destroy.turbo_stream.haml
|
138
137
|
- lib/generators/hot_glue/templates/edit.haml
|
139
138
|
- lib/generators/hot_glue/templates/edit.turbo_stream.haml
|
140
139
|
- lib/generators/hot_glue/templates/index.haml
|
141
140
|
- lib/generators/hot_glue/templates/new.haml
|
141
|
+
- lib/generators/hot_glue/templates/request_spec.rb.erb
|
142
|
+
- lib/generators/hot_glue/templates/system_spec.rb.erb
|
142
143
|
- lib/generators/hot_glue/templates/update.turbo_stream.haml
|
143
144
|
- lib/hot-glue.rb
|
144
145
|
- lib/hotglue/engine.rb
|
@@ -181,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
182
|
- !ruby/object:Gem::Version
|
182
183
|
version: '0'
|
183
184
|
requirements: []
|
184
|
-
rubygems_version: 3.
|
185
|
+
rubygems_version: 3.2.11
|
185
186
|
signing_key:
|
186
187
|
specification_version: 4
|
187
188
|
summary: A gem build scaffolding.
|