hot-glue 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ddd0fff6e983cefb9f4705ecfa218553412a78d6b02e70f246427562b0991e4
4
- data.tar.gz: 12971b62efd73dc85db9a48b7d9874f8ba9e81615f1f981af6d00cd2d58a57d7
3
+ metadata.gz: 59ec85e7253282cf8d83bc7d8137a787ff33cb617aad95f5752efbb6df68acf4
4
+ data.tar.gz: bdbab52ce54a5c1ed52f03753c01c203cce7109dc58fa73e6b9357deee8c83bc
5
5
  SHA512:
6
- metadata.gz: 3f436af0a80f4228e2f17f290d9be67aa1ffc7e48379d92a6739889906bf1a148df922db4af8f5989567bc6306336541de7685dbf41a89de4d7c6caa26235d55
7
- data.tar.gz: 566393c43f57c2ec3e5e09b2ddd1e3684f643f10fa76468e7343cac20ccd0a015bc6c71f417181cecc60c2e97d10dfecbf36b735c7e2db8dd25556dee5669db0
6
+ metadata.gz: 995f7a97e1b6f1105b9190a19cc0bfa93ed9490c2080c97332ae745326f1cc86da3e9e0abf401510d926a574686728dc848e155aa7a0f12ac53417147c625185
7
+ data.tar.gz: b5bda3332c15706e124f577aa77bfaa068d7ad8d45ebe31aacea7cbcf9cb193a20719ff87d8c1b467bfd0162fcbe5ab0e536295849a3f86e30002babe0ad1212
data/.gitignore CHANGED
@@ -1,16 +1,21 @@
1
1
  .bundle/
2
2
  log/*.log
3
3
  pkg/
4
- test/dummy/db/*.sqlite3
5
- test/dummy/db/*.sqlite3-journal
6
- test/dummy/db/*.sqlite3-*
7
- test/dummy/log/*.log
8
- test/dummy/storage/
9
- test/dummy/tmp/
4
+
10
5
  .byebug_history
11
6
 
12
7
  .idea/
13
8
  *.gem
14
9
  .DS_Store
15
10
 
16
- dump.rdb
11
+ dump.rdb
12
+ tmp/
13
+
14
+
15
+ db/*.sqlite3
16
+
17
+ spec/dummy/app/views/
18
+ spec/dummy/app/controllers/
19
+ spec/dummy/specs/
20
+
21
+ spec/strawman/
data/Gemfile CHANGED
@@ -1,15 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
3
 
4
- # Declare your gem's dependencies in common_core_js.gemspec.
5
- # Bundler will treat runtime dependencies like base dependencies, and
6
- # development dependencies will be added by default to the :development group.
7
4
  gemspec
8
5
 
9
- # Declare any dependencies that are still in development here instead of in
10
- # your gemspec. These might include edge Rails or gems from your path or
11
- # Git. Remember to move these dependencies to your gemspec before releasing
12
- # your gem to rubygems.org.
6
+ gem 'sqlite3'
7
+ gem 'byebug'
13
8
 
14
- # To use a debugger
15
- # gem 'byebug', group: [:development, :test]
9
+ gem 'rails', '6.1'
10
+ gem 'devise', require: true
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hot-glue (0.0.4)
4
+ hot-glue (0.0.5)
5
5
  ffaker (~> 2.16)
6
6
  haml-rails (~> 2.0)
7
7
  kaminari (~> 1.2)
@@ -12,68 +12,76 @@ PATH
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- actioncable (6.1.3)
16
- actionpack (= 6.1.3)
17
- activesupport (= 6.1.3)
15
+ actioncable (6.1.0)
16
+ actionpack (= 6.1.0)
17
+ activesupport (= 6.1.0)
18
18
  nio4r (~> 2.0)
19
19
  websocket-driver (>= 0.6.1)
20
- actionmailbox (6.1.3)
21
- actionpack (= 6.1.3)
22
- activejob (= 6.1.3)
23
- activerecord (= 6.1.3)
24
- activestorage (= 6.1.3)
25
- activesupport (= 6.1.3)
20
+ actionmailbox (6.1.0)
21
+ actionpack (= 6.1.0)
22
+ activejob (= 6.1.0)
23
+ activerecord (= 6.1.0)
24
+ activestorage (= 6.1.0)
25
+ activesupport (= 6.1.0)
26
26
  mail (>= 2.7.1)
27
- actionmailer (6.1.3)
28
- actionpack (= 6.1.3)
29
- actionview (= 6.1.3)
30
- activejob (= 6.1.3)
31
- activesupport (= 6.1.3)
27
+ actionmailer (6.1.0)
28
+ actionpack (= 6.1.0)
29
+ actionview (= 6.1.0)
30
+ activejob (= 6.1.0)
31
+ activesupport (= 6.1.0)
32
32
  mail (~> 2.5, >= 2.5.4)
33
33
  rails-dom-testing (~> 2.0)
34
- actionpack (6.1.3)
35
- actionview (= 6.1.3)
36
- activesupport (= 6.1.3)
34
+ actionpack (6.1.0)
35
+ actionview (= 6.1.0)
36
+ activesupport (= 6.1.0)
37
37
  rack (~> 2.0, >= 2.0.9)
38
38
  rack-test (>= 0.6.3)
39
39
  rails-dom-testing (~> 2.0)
40
40
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
41
- actiontext (6.1.3)
42
- actionpack (= 6.1.3)
43
- activerecord (= 6.1.3)
44
- activestorage (= 6.1.3)
45
- activesupport (= 6.1.3)
41
+ actiontext (6.1.0)
42
+ actionpack (= 6.1.0)
43
+ activerecord (= 6.1.0)
44
+ activestorage (= 6.1.0)
45
+ activesupport (= 6.1.0)
46
46
  nokogiri (>= 1.8.5)
47
- actionview (6.1.3)
48
- activesupport (= 6.1.3)
47
+ actionview (6.1.0)
48
+ activesupport (= 6.1.0)
49
49
  builder (~> 3.1)
50
50
  erubi (~> 1.4)
51
51
  rails-dom-testing (~> 2.0)
52
52
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
53
- activejob (6.1.3)
54
- activesupport (= 6.1.3)
53
+ activejob (6.1.0)
54
+ activesupport (= 6.1.0)
55
55
  globalid (>= 0.3.6)
56
- activemodel (6.1.3)
57
- activesupport (= 6.1.3)
58
- activerecord (6.1.3)
59
- activemodel (= 6.1.3)
60
- activesupport (= 6.1.3)
61
- activestorage (6.1.3)
62
- actionpack (= 6.1.3)
63
- activejob (= 6.1.3)
64
- activerecord (= 6.1.3)
65
- activesupport (= 6.1.3)
56
+ activemodel (6.1.0)
57
+ activesupport (= 6.1.0)
58
+ activerecord (6.1.0)
59
+ activemodel (= 6.1.0)
60
+ activesupport (= 6.1.0)
61
+ activestorage (6.1.0)
62
+ actionpack (= 6.1.0)
63
+ activejob (= 6.1.0)
64
+ activerecord (= 6.1.0)
65
+ activesupport (= 6.1.0)
66
66
  marcel (~> 0.3.1)
67
67
  mimemagic (~> 0.3.2)
68
- activesupport (6.1.3)
68
+ activesupport (6.1.0)
69
69
  concurrent-ruby (~> 1.0, >= 1.0.2)
70
70
  i18n (>= 1.6, < 2)
71
71
  minitest (>= 5.1)
72
72
  tzinfo (~> 2.0)
73
73
  zeitwerk (~> 2.3)
74
+ bcrypt (3.1.16)
74
75
  builder (3.2.4)
76
+ byebug (11.1.3)
75
77
  concurrent-ruby (1.1.8)
76
78
  crass (1.0.6)
79
+ devise (4.7.3)
80
+ bcrypt (~> 3.0)
81
+ orm_adapter (~> 0.1)
82
+ railties (>= 4.1.0)
83
+ responders
84
+ warden (~> 1.2.3)
77
85
  erubi (1.10.0)
78
86
  erubis (2.7.0)
79
87
  ffaker (2.18.0)
@@ -118,41 +126,47 @@ GEM
118
126
  method_source (1.0.0)
119
127
  mimemagic (0.3.5)
120
128
  mini_mime (1.0.2)
129
+ mini_portile2 (2.5.0)
121
130
  minitest (5.14.4)
122
- nio4r (2.5.5)
123
- nokogiri (1.11.1-x86_64-darwin)
131
+ nio4r (2.5.7)
132
+ nokogiri (1.11.1)
133
+ mini_portile2 (~> 2.5.0)
124
134
  racc (~> 1.4)
135
+ orm_adapter (0.5.0)
125
136
  racc (1.5.2)
126
137
  rack (2.2.3)
127
138
  rack-test (1.1.0)
128
139
  rack (>= 1.0, < 3)
129
- rails (6.1.3)
130
- actioncable (= 6.1.3)
131
- actionmailbox (= 6.1.3)
132
- actionmailer (= 6.1.3)
133
- actionpack (= 6.1.3)
134
- actiontext (= 6.1.3)
135
- actionview (= 6.1.3)
136
- activejob (= 6.1.3)
137
- activemodel (= 6.1.3)
138
- activerecord (= 6.1.3)
139
- activestorage (= 6.1.3)
140
- activesupport (= 6.1.3)
140
+ rails (6.1.0)
141
+ actioncable (= 6.1.0)
142
+ actionmailbox (= 6.1.0)
143
+ actionmailer (= 6.1.0)
144
+ actionpack (= 6.1.0)
145
+ actiontext (= 6.1.0)
146
+ actionview (= 6.1.0)
147
+ activejob (= 6.1.0)
148
+ activemodel (= 6.1.0)
149
+ activerecord (= 6.1.0)
150
+ activestorage (= 6.1.0)
151
+ activesupport (= 6.1.0)
141
152
  bundler (>= 1.15.0)
142
- railties (= 6.1.3)
153
+ railties (= 6.1.0)
143
154
  sprockets-rails (>= 2.0.0)
144
155
  rails-dom-testing (2.0.3)
145
156
  activesupport (>= 4.2.0)
146
157
  nokogiri (>= 1.6)
147
158
  rails-html-sanitizer (1.3.0)
148
159
  loofah (~> 2.3)
149
- railties (6.1.3)
150
- actionpack (= 6.1.3)
151
- activesupport (= 6.1.3)
160
+ railties (6.1.0)
161
+ actionpack (= 6.1.0)
162
+ activesupport (= 6.1.0)
152
163
  method_source
153
164
  rake (>= 0.8.7)
154
165
  thor (~> 1.0)
155
166
  rake (13.0.3)
167
+ responders (3.0.1)
168
+ actionpack (>= 5.0)
169
+ railties (>= 5.0)
156
170
  ruby_parser (3.15.1)
157
171
  sexp_processor (~> 4.9)
158
172
  sass-rails (6.0.0)
@@ -173,6 +187,7 @@ GEM
173
187
  actionpack (>= 4.0)
174
188
  activesupport (>= 4.0)
175
189
  sprockets (>= 3.0.0)
190
+ sqlite3 (1.4.2)
176
191
  temple (0.8.2)
177
192
  thor (1.1.0)
178
193
  tilt (2.0.10)
@@ -180,6 +195,8 @@ GEM
180
195
  rails (>= 6.0.0)
181
196
  tzinfo (2.0.4)
182
197
  concurrent-ruby (~> 1.0)
198
+ warden (1.2.9)
199
+ rack (>= 2.0.9)
183
200
  websocket-driver (0.7.3)
184
201
  websocket-extensions (>= 0.1.0)
185
202
  websocket-extensions (0.1.5)
@@ -189,7 +206,11 @@ PLATFORMS
189
206
  ruby
190
207
 
191
208
  DEPENDENCIES
209
+ byebug
210
+ devise
192
211
  hot-glue!
212
+ rails (= 6.1)
213
+ sqlite3
193
214
 
194
215
  BUNDLED WITH
195
216
  2.1.4
data/README.md CHANGED
@@ -282,7 +282,11 @@ Omits delete action.
282
282
 
283
283
  # VERSION HISTORY
284
284
 
285
- #### 2021-03-01 - v0.0.4 - Validation magic; refactors the options to the correct Rails::Generators syntax
285
+ #### 2021-03-08 - v0.1 - testing, testing, testing
286
+
287
+ #### 2021-03-01 - v0.0.5 - Validation magic; refactors the options to the correct Rails::Generators syntax
288
+
289
+ #### (yanked) - v0.0.4
286
290
 
287
291
  #### 2021-02-27 - v0.0.3 - several fixes for namespaces; adds pagination; adds exclude list to fields
288
292
 
@@ -300,3 +304,34 @@ Omits delete action.
300
304
  I hope one day I will leave this Earth a poor man (like my code) owning only the most simple structure for the simple form of my existence. Thanks for having educated me in this wisdom goes to my former mentor [@trak3r](https://github.com/trak3r)!
301
305
 
302
306
 
307
+
308
+
309
+ # HOW THIS GEM IS TESTED
310
+
311
+ The testing of functionality-within-functionality is a little tricky and requires thinking outside the box.
312
+
313
+ We have two kinds of "sandboxes": a DUMMY sandbox, and also a STRAWMAN sandbox
314
+
315
+ The dummy sandbox is found at `spec/dummy`
316
+
317
+ The dummy lives as mostly checked- into the repository, except the folders where the generated code goes (`spec/dummy/app/views/`, `spec/dummy/app/controllers/`, `spec/dummy/specs/` are excluded from Git)
318
+
319
+ When you run the **internal specs**, which you can do **at the root of this repo** using the command `rspec`, a set of specs will run to assert the generators are erroring when they are supposed to and producing code when they are supposed to.
320
+
321
+
322
+ The DUMMY testing DOES NOT test the actual functionality of the output code (it just tests the functionality of the generation process).
323
+
324
+ For this reason, I've also added something I call STRAWMAN testing, which is a set of steps that does these things:
325
+
326
+ The Strawman isn't in the repository, but if you build it locally, it will create itself into
327
+
328
+ `spec/strawman/`
329
+
330
+ 1) Builds you a strawman sandbox app from scratch, using the native `rails new`
331
+ 2) Makes a few small modifications to the new app to support this gem
332
+ 3) Create two nonsense tables called OmnitableA and OmnitableB. Each omnitable has one of each kind of field (integer, text, string, date, time, etc)
333
+ 4) In this way, it is a "Noah's Arc" testing strategy: It will build you a fully functional app using all of the feature sets of the gem.
334
+ 5) The built app itself will contain its own specs
335
+ 6) You will then cd into `spec/strawman` and run `rspec`. This second test suite now runs to full test all of the *generated* code.
336
+
337
+
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
- APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
17
+ APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
18
18
  load 'rails/tasks/engine.rake'
19
19
 
20
20
  load 'rails/tasks/statistics.rake'
File without changes
data/bin/rails CHANGED
@@ -3,8 +3,8 @@
3
3
  # installed from the root of your application.
4
4
 
5
5
  ENGINE_ROOT = File.expand_path('..', __dir__)
6
- ENGINE_PATH = File.expand_path('../lib/common_core_js/engine', __dir__)
7
- APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)
6
+ ENGINE_PATH = File.expand_path('../lib/hotglue/engine', __dir__)
7
+ APP_PATH = File.expand_path('../spec/dummy/application', __dir__)
8
8
 
9
9
  # Set up gems listed in the Gemfile.
10
10
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
@@ -0,0 +1,11 @@
1
+ development:
2
+ adapter: sqlite3
3
+ database: ../spec/dummy/db/development.sqlite3
4
+ pool: 5
5
+ timeout: 5000
6
+
7
+ test:
8
+ adapter: sqlite3
9
+ database: ../spec/dummy/db/test.sqlite3
10
+ pool: 5
11
+ timeout: 5000
@@ -0,0 +1,11 @@
1
+ class CreateAbcs < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :abcs do |t|
4
+ t.integer :xxx
5
+ t.string :yyy
6
+ t.integer :def_id
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ class CreateDefs < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :defs do |t|
4
+ t.integer :user_id
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateHgis < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :hgis do |t|
4
+ t.integer :def_id
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateJkls < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :jkls do |t|
4
+ t.integer :hgi_id
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DeviseCreateUsers < ActiveRecord::Migration[6.1]
4
+ def change
5
+ create_table :users do |t|
6
+ ## Database authenticatable
7
+ t.string :email, null: false, default: ""
8
+ t.string :encrypted_password, null: false, default: ""
9
+
10
+ ## Recoverable
11
+ t.string :reset_password_token
12
+ t.datetime :reset_password_sent_at
13
+
14
+ ## Rememberable
15
+ t.datetime :remember_created_at
16
+
17
+ ## Trackable
18
+ # t.integer :sign_in_count, default: 0, null: false
19
+ # t.datetime :current_sign_in_at
20
+ # t.datetime :last_sign_in_at
21
+ # t.string :current_sign_in_ip
22
+ # t.string :last_sign_in_ip
23
+
24
+ ## Confirmable
25
+ # t.string :confirmation_token
26
+ # t.datetime :confirmed_at
27
+ # t.datetime :confirmation_sent_at
28
+ # t.string :unconfirmed_email # Only if using reconfirmable
29
+
30
+ ## Lockable
31
+ # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
32
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
33
+ # t.datetime :locked_at
34
+
35
+
36
+ t.timestamps null: false
37
+ end
38
+
39
+ add_index :users, :email, unique: true
40
+ add_index :users, :reset_password_token, unique: true
41
+ # add_index :users, :confirmation_token, unique: true
42
+ # add_index :users, :unlock_token, unique: true
43
+ end
44
+ end
@@ -0,0 +1,9 @@
1
+ class CreateXyzs < ActiveRecord::Migration[6.1]
2
+ def change
3
+ create_table :xyzs do |t|
4
+ t.integer :nothing_id
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
data/db/schema.rb ADDED
@@ -0,0 +1,59 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 2021_03_06_225506) do
14
+
15
+ create_table "abcs", force: :cascade do |t|
16
+ t.integer "xxx"
17
+ t.string "yyy"
18
+ t.integer "def_id"
19
+ t.datetime "created_at", precision: 6, null: false
20
+ t.datetime "updated_at", precision: 6, null: false
21
+ end
22
+
23
+ create_table "defs", force: :cascade do |t|
24
+ t.integer "user_id"
25
+ t.datetime "created_at", precision: 6, null: false
26
+ t.datetime "updated_at", precision: 6, null: false
27
+ end
28
+
29
+ create_table "hgis", force: :cascade do |t|
30
+ t.integer "def_id"
31
+ t.datetime "created_at", precision: 6, null: false
32
+ t.datetime "updated_at", precision: 6, null: false
33
+ end
34
+
35
+ create_table "jkls", force: :cascade do |t|
36
+ t.integer "hgi_id"
37
+ t.datetime "created_at", precision: 6, null: false
38
+ t.datetime "updated_at", precision: 6, null: false
39
+ end
40
+
41
+ create_table "users", force: :cascade do |t|
42
+ t.string "email", default: "", null: false
43
+ t.string "encrypted_password", default: "", null: false
44
+ t.string "reset_password_token"
45
+ t.datetime "reset_password_sent_at"
46
+ t.datetime "remember_created_at"
47
+ t.datetime "created_at", precision: 6, null: false
48
+ t.datetime "updated_at", precision: 6, null: false
49
+ t.index ["email"], name: "index_users_on_email", unique: true
50
+ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
51
+ end
52
+
53
+ create_table "xyzs", force: :cascade do |t|
54
+ t.integer "nothing_id"
55
+ t.datetime "created_at", precision: 6, null: false
56
+ t.datetime "updated_at", precision: 6, null: false
57
+ end
58
+
59
+ end
@@ -10,9 +10,9 @@ module HotGlue
10
10
 
11
11
  def initialize(*args) #:nodoc:
12
12
  super
13
- # copy_file "common_core.js", "app/javascript/common_core.js"
14
- # copy_file "common_core.scss", "app/assets/stylesheets/common_core.scss"
15
- copy_file "_flash_notices.haml", "app/views/layouts/_flash_notices.haml"
13
+ # copy_file "hot_glue.js", "#{'spec/dummy/' if Rails.env.test?}app/javascript/hot_glue.js"
14
+ # copy_file "hot_glue.scss", "#{'spec/dummy/' if Rails.env.test?}app/assets/stylesheets/hot_glue.scss"
15
+ copy_file "_flash_notices.haml", "#{'spec/dummy/' if Rails.env.test?}app/views/layouts/_flash_notices.haml"
16
16
  end
17
17
  end
18
18
  end
@@ -3,6 +3,12 @@ require 'ffaker'
3
3
 
4
4
 
5
5
  module HotGlue
6
+
7
+
8
+ class Error < StandardError
9
+ end
10
+
11
+
6
12
  module GeneratorHelper
7
13
  def text_area_output(col, field_length, col_identifier )
8
14
  lines = field_length % 40
@@ -59,32 +65,26 @@ module HotGlue
59
65
  begin
60
66
  object = eval(class_name)
61
67
  rescue StandardError => e
62
- puts "*** Oops: It looks like there is no object for #{class_name}. Please define the object + database table first."
63
- exit
68
+ message = "*** Oops: It looks like there is no object for #{class_name}. Please define the object + database table first."
69
+ raise(HotGlue::Error, message)
70
+ end
71
+
72
+ if @specs_only && @no_specs
73
+ raise(HotGlue::Error, "*** Oops: You seem to have specified both the --specs-only flag and --no-specs flags. this doesn't make any sense, so I am aborting. sorry.")
64
74
  end
65
- args = meta_args[0]
66
- @singular = args.first.tableize.singularize # should be in form hello_world
67
75
 
68
76
 
77
+ args = meta_args[0]
78
+ @singular = args.first.tableize.singularize # should be in form hello_world
69
79
  @plural = options['plural'] || @singular + "s" # supply to override; leave blank to use default
70
80
  @auth = options['auth'] || "current_user"
71
81
  @auth_identifier = options['auth'] || (!@auth.nil? && @auth.gsub("current_", "")) || nil
72
-
73
-
74
82
  @nest = options['auth'] || nil
75
83
  @namespace = options['namespace'] || nil
76
-
77
84
  @singular_class = @singular.titleize.gsub(" ", "")
78
-
79
85
  @exclude_fields = []
80
-
81
-
82
-
83
86
  @exclude_fields += options['exclude'].split(",").collect(&:to_sym)
84
-
85
87
  auth_assoc = @auth.gsub("current_","")
86
-
87
-
88
88
  @god = options['god'] || options['gd'] || false
89
89
  @specs_only = options['specs-only'] || false
90
90
  @no_specs = options['no-specs'] || false
@@ -92,22 +92,15 @@ module HotGlue
92
92
  @no_create = options['no-create'] || false
93
93
  @no_paginate = options['no-paginate'] || false
94
94
 
95
- if @specs_only && @no_specs
96
- puts "*** Oops: You seem to have specified both the --specs-only flag and --no-specs flags. this doesn't make any sense, so I am aborting. sorry."
97
- exit
98
- end
99
-
100
95
  if @god
101
96
  @auth = nil
102
97
  end
103
98
 
104
-
105
99
  # when in self auth, the object is the same as the authenticated object
106
100
  if @auth && auth_identifier == @singular
107
101
  @self_auth = true
108
102
  end
109
103
 
110
-
111
104
  @nested_args = []
112
105
  if !@nest.nil?
113
106
  @nested_args = @nest.split("/")
@@ -134,19 +127,20 @@ module HotGlue
134
127
  end
135
128
  end
136
129
 
137
- # create the columns
130
+
138
131
  if !@object_owner_sym.empty?
139
132
  auth_assoc_field = auth_assoc + "_id"
140
133
  assoc = eval("#{singular_class}.reflect_on_association(:#{@object_owner_sym})")
134
+
141
135
  if assoc
142
136
  ownership_field = assoc.name.to_s + "_id"
143
137
  else
144
- if @auth
145
- puts "*** Oops: It looks like is no association from current_#{@object_owner_sym} to a class called #{singular_class}. If your user is called something else, pass with flag auth=current_X where X is the model for your users as lowercase. Also, be sure to implement current_X as a method on your controller. (If you really don't want to implement a current_X on your controller and want me to check some other method for your current user, see the section in the docs for auth_identifier.) To make a controller that can read all records, specify with --god."
146
- else
147
- puts "*** Oops: god mode could not find the association(?). something is wrong."
148
- end
149
- exit
138
+ # if @auth
139
+ exit_message= "*** Oops: It looks like is no association from current_#{@object_owner_sym} to a class called #{singular_class}. If your user is called something else, pass with flag auth=current_X where X is the model for your users as lowercase. Also, be sure to implement current_X as a method on your controller. (If you really don't want to implement a current_X on your controller and want me to check some other method for your current user, see the section in the docs for auth_identifier.) To make a controller that can read all records, specify with --god."
140
+ # else
141
+ # exit_message= "*** Oops: god mode could not find the association(?). something is wrong."
142
+ # end
143
+ raise(HotGlue::Error, exit_message)
150
144
  end
151
145
  end
152
146
 
@@ -158,18 +152,52 @@ module HotGlue
158
152
 
159
153
  @exclude_fields.push(auth_assoc_field.to_sym) if !auth_assoc_field.nil?
160
154
  @exclude_fields.push(ownership_field.to_sym) if !ownership_field.nil?
155
+ @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| @exclude_fields.include?(field) }
161
156
 
162
- begin
163
- @columns = object.columns.map(&:name).map(&:to_sym).reject{|field| @exclude_fields.include?(field) }
164
- rescue StandardError => e
165
- puts "Ooops... #{e} it looks like is no object for #{class_name}. Please create the database table with fields first. "
166
- exit
167
- end
157
+ @columns.each do |col|
158
+ if object.columns_hash[col.to_s].type == :integer
159
+ if col.to_s.ends_with?("_id")
160
+ # guess the association name label
161
+ assoc_name = col.to_s.gsub("_id","")
162
+ assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
163
+
164
+
165
+ begin
166
+ eval(assoc.class_name)
167
+ rescue NameError => e
168
+ exit_message = "*** Oops: The table #{singular_class} has an association for '#{assoc.name.to_s}', but I can't find an assoicated model for that association. TODO: Please implement a model for #{assoc.name.to_s} that belongs to #{singular_class} "
169
+ raise(HotGlue::Error, exit_message)
168
170
 
171
+ end
169
172
 
170
173
 
174
+ if assoc.nil?
175
+ exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
176
+ raise(HotGlue::Error,exit_message)
177
+ end
178
+ assoc_class = eval(assoc.class_name)
179
+ if assoc_class.column_names.include?("name")
180
+ # display_column = "name"
181
+ elsif assoc_class.column_names.include?("to_label")
182
+ # display_column = "to_label"
183
+ elsif assoc_class.column_names.include?("full_name")
184
+ # display_column = "full_name"
185
+ elsif assoc_class.column_names.include?("display_name")
186
+ # display_column = "display_name"
187
+ elsif assoc_class.column_names.include?("email")
188
+ # display_column = "email"
189
+ else
190
+ exit_message= "*** Oops: Can't find any column to use as the display label for the #{assoc.name.to_s} association on the #{singular_class} model . TODO: Please implement just one of: 1) name, 2) to_label, 3) full_name, 4) display_name, or 5) email directly on your #{assoc.class_name} model (either as database field or model methods), then RERUN THIS GENERATOR. (If more than one is implemented, the field to use will be chosen based on the rank here, e.g., if name is present it will be used; if not, I will look for a to_label, etc)"
191
+ raise(HotGlue::Error,exit_message)
192
+ end
193
+ end
194
+ end
195
+ end
171
196
  end
172
197
 
198
+
199
+
200
+ #
173
201
  def formats
174
202
  [format]
175
203
  end
@@ -182,17 +210,17 @@ module HotGlue
182
210
  @default_colspan = @columns.size
183
211
 
184
212
  unless @specs_only
185
- template "controller.rb", File.join("app/controllers#{namespace_with_dash}", "#{plural}_controller.rb")
213
+ template "controller.rb", File.join("#{'spec/dummy/' if Rails.env.test?}app/controllers#{namespace_with_dash}", "#{plural}_controller.rb")
186
214
  if @namespace && defined?(controller_descends_from) == nil
187
- template "base_controller.rb", File.join("app/controllers#{namespace_with_dash}", "base_controller.rb")
215
+ template "base_controller.rb", File.join("#{'spec/dummy/' if Rails.env.test?}app/controllers#{namespace_with_dash}", "base_controller.rb")
188
216
  end
189
217
  end
190
218
 
191
219
  unless @no_specs
192
- template "controller_spec.rb", File.join("spec/controllers#{namespace_with_dash}", "#{plural}_controller_spec.rb")
220
+ template "controller_spec.rb", File.join("#{'spec/dummy/' if Rails.env.test?}spec/controllers#{namespace_with_dash}", "#{plural}_controller_spec.rb")
193
221
  end
194
222
 
195
- template "_errors.haml", File.join("app/views#{namespace_with_dash}", "_errors.haml")
223
+ template "_errors.haml", File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}", "_errors.haml")
196
224
  end
197
225
 
198
226
  def list_column_headings
@@ -387,14 +415,14 @@ module HotGlue
387
415
  haml_views.each do |view|
388
416
  formats.each do |format|
389
417
  filename = cc_filename_with_extensions(view, "haml")
390
- template filename, File.join("app/views#{namespace_with_dash}", controller_file_path, filename)
418
+ template filename, File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}", controller_file_path, filename)
391
419
  end
392
420
  end
393
421
 
394
422
  turbo_stream_views.each do |view|
395
423
  formats.each do |format|
396
424
  filename = cc_filename_with_extensions(view, 'turbo_stream.haml')
397
- template filename, File.join("app/views#{namespace_with_dash}", controller_file_path, filename)
425
+ template filename, File.join("#{'spec/dummy/' if Rails.env.test?}app/views#{namespace_with_dash}", controller_file_path, filename)
398
426
  end
399
427
  end
400
428
  end
@@ -451,15 +479,15 @@ module HotGlue
451
479
  when :integer
452
480
  # look for a belongs_to on this object
453
481
  if col.to_s.ends_with?("_id")
454
- # guess the association name label
455
-
456
-
457
- assoc_name = col.to_s.gsub("_id","")
458
- assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
459
- if assoc.nil?
460
- puts "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
461
- exit
462
- end
482
+ # # guess the association name label
483
+ #
484
+ #
485
+ # assoc_name = col.to_s.gsub("_id","")
486
+ # assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
487
+ # if assoc.nil?
488
+ # exit_message= "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
489
+ # exit
490
+ # end
463
491
 
464
492
 
465
493
  assoc_class = eval(assoc.class_name)
@@ -475,7 +503,8 @@ module HotGlue
475
503
  elsif assoc_class.column_names.include?("email")
476
504
  display_column = "email"
477
505
  else
478
- puts "*** Oops: Can't find any column to use as the display label for the #{assoc.name.to_s} association on the #{singular_class} model . TODO: Please implement just one of: 1) name, 2) to_label, 3) full_name, 4) display_name, or 5) email directly on your #{assoc.class_name} model (either as database field or model methods), then RERUN THIS GENERATOR. (If more than one is implemented, the field to use will be chosen based on the rank here, e.g., if name is present it will be used; if not, I will look for a to_label, etc)"
506
+ raise("this should have been caught by the checker in the initializer")
507
+ # puts "*** Oops: Can't find any column to use as the display label for the #{assoc.name.to_s} association on the #{singular_class} model . TODO: Please implement just one of: 1) name, 2) to_label, 3) full_name, 4) display_name, or 5) email directly on your #{assoc.class_name} model (either as database field or model methods), then RERUN THIS GENERATOR. (If more than one is implemented, the field to use will be chosen based on the rank here, e.g., if name is present it will be used; if not, I will look for a to_label, etc)"
479
508
  end
480
509
 
481
510
  "#{col_identifier}{class: \"form-group \#{'alert-danger' if #{singular}.errors.details.keys.include?(:#{assoc_name.to_s})}\"}
@@ -556,8 +585,8 @@ module HotGlue
556
585
  assoc = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
557
586
 
558
587
  if assoc.nil?
559
- puts "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
560
- exit
588
+ exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
589
+ raise(HotGlue::Error,exit_message)
561
590
  end
562
591
 
563
592
  assoc_class = eval(assoc.class_name)
@@ -664,7 +693,8 @@ module HotGlue
664
693
  display_column = "number"
665
694
 
666
695
  else
667
- raise "*** Oops: Can't find any column to use as the display label on #{singular_class} model . TODO: Please implement just one of: 1) name, 2) to_label, 3) full_name, 4) display_name, 5) email, or 6) number directly on your #{singular_class} model (either as database field or model methods), then RERUN THIS GENERATOR. (If more than one is implemented, the field to use will be chosen based on the rank here, e.g., if name is present it will be used; if not, I will look for a to_label, etc)"
696
+ exit_message = "*** Oops: Can't find any column to use as the display label on #{singular_class} model . TODO: Please implement just one of: 1) name, 2) to_label, 3) full_name, 4) display_name, 5) email, or 6) number directly on your #{singular_class} model (either as database field or model methods), then RERUN THIS GENERATOR. (If more than one is implemented, the field to use will be chosen based on the rank here, e.g., if name is present it will be used; if not, I will look for a to_label, etc)"
697
+ raise(HotGlue::Error, exit_message)
668
698
  end
669
699
  end
670
700
 
@@ -1,3 +1,3 @@
1
1
  module HotGlue
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
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.5
4
+ version: 0.0.6
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-01 00:00:00.000000000 Z
11
+ date: 2021-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,9 +108,18 @@ files:
108
108
  - LICENCE
109
109
  - README.md
110
110
  - Rakefile
111
+ - app/assets/config/manifest.js
111
112
  - app/helpers/hot_glue/controller_helper.rb
112
113
  - app/helpers/hot_glue_helper.rb
113
114
  - bin/rails
115
+ - config/database.yml
116
+ - db/migrate/20210306212711_create_abcs.rb
117
+ - db/migrate/20210306223300_create_defs.rb
118
+ - db/migrate/20210306223305_create_hgis.rb
119
+ - db/migrate/20210306223309_create_jkls.rb
120
+ - db/migrate/20210306223701_devise_create_users.rb
121
+ - db/migrate/20210306225506_create_xyzs.rb
122
+ - db/schema.rb
114
123
  - lib/generators/hot_glue/install_generator.rb
115
124
  - lib/generators/hot_glue/scaffold_generator.rb
116
125
  - lib/generators/hot_glue/templates/_errors.haml
@@ -121,9 +130,9 @@ files:
121
130
  - lib/generators/hot_glue/templates/_new_button.haml
122
131
  - lib/generators/hot_glue/templates/_new_form.haml
123
132
  - lib/generators/hot_glue/templates/_show.haml
124
- - lib/generators/hot_glue/templates/base_controller.rb
125
- - lib/generators/hot_glue/templates/controller.rb
126
- - lib/generators/hot_glue/templates/controller_spec.rb
133
+ - lib/generators/hot_glue/templates/base_controller.rb.erb
134
+ - lib/generators/hot_glue/templates/controller.rb.erb
135
+ - lib/generators/hot_glue/templates/controller_spec.rb.erb
127
136
  - lib/generators/hot_glue/templates/create.turbo_stream.haml
128
137
  - lib/generators/hot_glue/templates/destroy.turbo_stream.haml
129
138
  - lib/generators/hot_glue/templates/edit.haml
@@ -172,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
181
  - !ruby/object:Gem::Version
173
182
  version: '0'
174
183
  requirements: []
175
- rubygems_version: 3.2.11
184
+ rubygems_version: 3.0.8
176
185
  signing_key:
177
186
  specification_version: 4
178
187
  summary: A gem build scaffolding.