hot-glue 0.4.9.2 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -68,19 +68,18 @@ module HotGlue
68
68
  def self.derrive_reference_name(thing_as_string)
69
69
  assoc_class = eval(thing_as_string)
70
70
 
71
- if assoc_class.respond_to?("name")
71
+ if assoc_class.new.respond_to?("name")
72
72
  display_column = "name"
73
- elsif assoc_class.respond_to?("to_label")
73
+ elsif assoc_class.new.respond_to?("to_label")
74
74
  display_column = "to_label"
75
- elsif assoc_class.respond_to?("full_name")
75
+ elsif assoc_class.new.respond_to?("full_name")
76
76
  display_column = "full_name"
77
- elsif assoc_class.respond_to?("display_name")
77
+ elsif assoc_class.new.respond_to?("display_name")
78
78
  display_column = "display_name"
79
- elsif assoc_class.respond_to?("email")
79
+ elsif assoc_class.new.respond_to?("email")
80
80
  display_column = "email"
81
- else
82
- raise("this should have been caught by the checker in the initializer")
83
- # 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)"
81
+ # else # SHOULD BE UNREACHABLE
82
+ # raise("this should have been caught by the checker in the initializer")
84
83
  end
85
84
  display_column
86
85
  end
@@ -97,7 +96,6 @@ module HotGlue
97
96
  class_option :nest, type: :string, default: nil # DEPRECATED —— DO NOT USE
98
97
  class_option :nested, type: :string, default: ""
99
98
 
100
-
101
99
  class_option :namespace, type: :string, default: nil
102
100
  class_option :auth, type: :string, default: nil
103
101
  class_option :auth_identifier, type: :string, default: nil
@@ -105,6 +103,7 @@ module HotGlue
105
103
  class_option :include, type: :string, default: ""
106
104
  class_option :god, type: :boolean, default: false
107
105
  class_option :gd, type: :boolean, default: false # alias for god
106
+
108
107
  class_option :specs_only, type: :boolean, default: false
109
108
  class_option :no_specs, type: :boolean, default: false
110
109
  class_option :no_delete, type: :boolean, default: false
@@ -116,24 +115,32 @@ module HotGlue
116
115
  class_option :show_only, type: :string, default: ""
117
116
 
118
117
  class_option :ujs_syntax, type: :boolean, default: nil
119
-
120
118
  class_option :downnest, type: :string, default: nil
121
119
  class_option :magic_buttons, type: :string, default: nil
122
120
  class_option :small_buttons, type: :boolean, default: nil
123
-
124
121
  class_option :display_list_after_update, type: :boolean, default: false
125
122
  class_option :smart_layout, type: :boolean, default: false
126
123
  class_option :markup, type: :string, default: nil # deprecated -- use in app config instead
127
124
  class_option :layout, type: :string, default: nil # if used here it will override what is in the config
125
+ class_option :hawk, type: :string, default: nil #
126
+
128
127
  class_option :no_list_label, type: :boolean, default: false
128
+
129
129
  class_option :no_list_heading, type: :boolean, default: false
130
130
 
131
- class_option :before_list_labels, type: :boolean, default: false
131
+
132
+ # determines if the labels show up BEFORE or AFTER on the NEW/EDIT (form)
133
+ class_option :form_labels_position, default: 'after' # choices are before, after, omit
134
+ class_option :form_placeholder_labels, default: false # puts the field names into the placeholder labels
135
+
136
+
137
+ # NOT YET IMPLEMENTED
138
+ # determines if labels appear within the rows of the VIEWABLE list (does NOT affect the list heading)
139
+ class_option :inline_list_labels, default: 'omit' # choices are before, after, omit
132
140
 
133
141
  def initialize(*meta_args)
134
142
  super
135
143
 
136
-
137
144
  begin
138
145
  @the_object = eval(class_name)
139
146
  rescue StandardError => e
@@ -142,8 +149,9 @@ module HotGlue
142
149
  raise(HotGlue::Error, message)
143
150
  end
144
151
 
145
- if !options['spec_only'].nil? && !options['no_spec'].nil?
146
- 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."
152
+
153
+ if options['specs_only'] && options['no_specs']
154
+ 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. Aborting.")
147
155
  end
148
156
 
149
157
  if !options['exclude'].empty? && !options['include'].empty?
@@ -155,21 +163,16 @@ module HotGlue
155
163
 
156
164
 
157
165
  if @stimulus_syntax.nil?
158
- if Rails.version.split(".")[0].to_i >= 7
159
- @stimulus_syntax = true
160
- else
161
- @stimulus_syntax = false
162
- end
163
- end
164
-
165
- if !options['markup'].nil?
166
- message = "Using --markup flag in the generator is deprecated; instead, use a file at config/hot_glue.yml with a key markup set to `erb` or `haml`"
167
- raise(HotGlue::Error, message)
166
+ @stimulus_syntax = true
168
167
 
168
+ # if Rails.version.split(".")[0].to_i >= 7
169
+ # @stimulus_syntax = true
170
+ # else
171
+ # end
169
172
  end
170
173
 
171
174
  if !options['markup'].nil?
172
- message = "Using --layout flag in the generator is deprecated; instead, use a file at config/hot_glue.yml with a key markup set to `erb` or `haml`"
175
+ message = "Using --markup flag in the generator is deprecated; instead, use a file at config/hot_glue.yml with a key markup set to `erb` or `haml`"
173
176
  raise(HotGlue::Error, message)
174
177
  end
175
178
 
@@ -179,12 +182,10 @@ module HotGlue
179
182
  if @markup == "erb"
180
183
  @template_builder = HotGlue::ErbTemplate.new
181
184
  elsif @markup == "slim"
182
- message = "SLIM IS NOT IMPLEMENTED; please see https://github.com/jasonfb/hot-glue/issues/3"
183
- raise(HotGlue::Error, message)
184
- @template_builder = HotGlue::SlimTemplate.new
185
-
185
+ raise(HotGlue::Error, "SLIM IS NOT IMPLEMENTED")
186
186
  elsif @markup == "haml"
187
- @template_builder = HotGlue::HamlTemplate.new
187
+ raise(HotGlue::Error, "HAML IS NOT IMPLEMENTED")
188
+
188
189
  end
189
190
 
190
191
 
@@ -219,7 +220,7 @@ module HotGlue
219
220
  @controller_build_folder_singular = singular
220
221
 
221
222
  if ! @controller_build_folder.ends_with?("s")
222
- raise "can't build with controller name #{@controller_build_folder} because it doesn't end with an 's'"
223
+ raise HotGlue::Error, "can't build with controller name #{@controller_build_folder} because it doesn't end with an 's'"
223
224
  end
224
225
 
225
226
  @auth = options['auth'] || "current_user"
@@ -228,7 +229,7 @@ module HotGlue
228
229
 
229
230
 
230
231
  if options['nest']
231
- raise "STOP: the flag --nest has been replaced with --nested; please re-run using the --nested flag"
232
+ raise HotGlue::Error, "STOP: the flag --nest has been replaced with --nested; please re-run using the --nested flag"
232
233
 
233
234
  end
234
235
 
@@ -267,11 +268,27 @@ module HotGlue
267
268
  @no_list_label = options['no_list_label'] || false
268
269
  @no_list_heading = options['no_list_heading'] || false
269
270
 
271
+ @form_labels_position = options['form_labels_position']
272
+ if !['before','after','omit'].include?(@form_labels_position)
273
+
274
+ raise HotGlue::Error, "You passed '#{@form_labels_position}' as the setting for --form-labels-position but the only allowed options are before, after (default), and omit"
275
+ end
276
+
277
+ @form_placeholder_labels = options['form_placeholder_labels'] # true or false
278
+ @inline_list_labels = options['inline_list_labels'] || 'omit' # 'before','after','omit'
279
+
280
+
281
+ if !['before','after','omit'].include?(@inline_list_labels)
282
+ raise HotGlue::Error, "You passed '#{@inline_list_labels}' as the setting for --inline-list-labels but the only allowed options are before, after, and omit (default)"
283
+ end
284
+
285
+
286
+
270
287
  @display_list_after_update = options['display_list_after_update'] || false
271
288
  @smart_layout = options['smart_layout']
272
289
 
273
290
  if options['include'].include?(":") && @smart_layout
274
- raise "You specified both --smart-layout and also specified grouping mode (there is a : character in your field include list); you must remove the colon(s) from your --include tag or remove the --smart-layout option"
291
+ raise HotGlue::Error, "You specified both --smart-layout and also specified grouping mode (there is a : character in your field include list); you must remove the colon(s) from your --include tag or remove the --smart-layout option"
275
292
  end
276
293
 
277
294
 
@@ -299,9 +316,24 @@ module HotGlue
299
316
  raise "This controller appears to be the same as the authentication object but in this context you cannot build a new/create action; please re-run with --no-create flag"
300
317
  end
301
318
 
302
- # old syntax
303
- @nested_args = []
319
+ @magic_buttons = []
320
+ if options['magic_buttons']
321
+ @magic_buttons = options['magic_buttons'].split(',')
322
+ end
323
+
324
+
325
+ @small_buttons = options['small_buttons'] || false
326
+
327
+ @build_update_action = !@no_edit || !@magic_buttons.empty?
328
+ # if the magic buttons are present, build the update action anyway
329
+
330
+ @ujs_syntax = options['ujs_syntax']
331
+ if !@ujs_syntax
332
+ @ujs_syntax = !defined?(Turbo::Engine)
333
+ end
334
+
304
335
 
336
+ # NEST CHAIN
305
337
  # new syntax
306
338
  # @nested_set = [
307
339
  # {
@@ -312,10 +344,6 @@ module HotGlue
312
344
  @nested_set = []
313
345
 
314
346
  if ! @nested.nil?
315
-
316
-
317
- @nested_args = @nested.split("/").collect{|x| x.gsub("~","")}
318
-
319
347
  @nested_set = @nested.split("/").collect { |arg|
320
348
  is_optional = arg.start_with?("~")
321
349
  arg.gsub!("~","")
@@ -326,57 +354,51 @@ module HotGlue
326
354
  }
327
355
 
328
356
  }
329
-
330
- puts "@nested_set is #{@nested_set}"
331
- @nested_args_plural = {}
332
-
333
-
334
- @nested_args.each do |a|
335
- @nested_args_plural[a] = a + "s"
336
- end
337
- end
338
-
339
- @magic_buttons = []
340
- if options['magic_buttons']
341
- @magic_buttons = options['magic_buttons'].split(',')
357
+ puts "NESTING: #{@nested_set}"
342
358
  end
343
359
 
344
-
345
- @small_buttons = options['small_buttons'] || false
346
-
347
- @build_update_action = !@no_edit || !@magic_buttons.empty?
348
- # if the magic buttons are present, build the update action anyway
360
+ # OBJECT OWNERSHIP & NESTING
361
+ @reference_name = HotGlue.derrive_reference_name(singular_class)
362
+ if @auth && @self_auth
363
+ # byebug
364
+ @object_owner_sym = @auth.gsub("current_", "").to_sym
365
+ @object_owner_eval = @auth
366
+ @object_owner_optional = false
367
+ @object_owner_name = @auth.gsub("current_", "").to_s
349
368
 
350
369
 
351
- if @auth && ! @self_auth && @nested_args.none?
370
+ elsif @auth && ! @self_auth && @nested_set.none? && !@auth.include?(".")
371
+ # byebug
352
372
  @object_owner_sym = @auth.gsub("current_", "").to_sym
353
373
  @object_owner_eval = @auth
354
374
  @object_owner_optional = false
355
- else
375
+ @object_owner_name = @auth.gsub("current_", "").to_s
356
376
 
357
- if @nested_args.any?
377
+ elsif @auth && @auth.include?(".")
378
+ # byebug
379
+ @object_owner_sym = nil
380
+ @object_owner_eval = @auth
381
+ else
382
+ # byebug
383
+ if @nested_set.any?
358
384
  @object_owner_sym = @nested_set.last[:singular].to_sym
359
385
  @object_owner_eval = "@#{@nested_set.last[:singular]}"
360
386
  @object_owner_name = @nested_set.last[:singular]
361
387
  @object_owner_optional = @nested_set.last[:optional]
362
388
  else
363
- @object_owner_sym = ""
389
+ @object_owner_sym = nil
364
390
  @object_owner_eval = ""
365
391
  end
366
392
  end
367
393
 
394
+ identify_object_owner
395
+ setup_hawk_keys
368
396
 
369
- @ujs_syntax = options['ujs_syntax']
370
397
 
371
- if !@ujs_syntax
372
- @ujs_syntax = !defined?(Turbo::Engine)
373
- end
374
- @reference_name = HotGlue.derrive_reference_name(singular_class)
375
398
 
376
- identify_object_owner
399
+ # SETUP FIELDS & LAYOUT
377
400
  setup_fields
378
-
379
- if (@columns - @show_only - (@object_owner_sym.empty? ? [] : [@ownership_field.to_sym])).empty?
401
+ if (@columns - @show_only - (@ownership_field ? [@ownership_field.to_sym] : [])).empty?
380
402
  @no_field_form = true
381
403
  end
382
404
 
@@ -391,41 +413,61 @@ module HotGlue
391
413
  })
392
414
  @layout_object = builder.construct
393
415
 
394
- @menu_file_exists = true if @nested_args.none? && File.exists?("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_menu.#{@markup}")
416
+ @menu_file_exists = true if @nested_set.none? && File.exists?("#{Rails.root}/app/views/#{namespace_with_trailing_dash}_menu.#{@markup}")
417
+
418
+
419
+ end
395
420
 
421
+ def setup_hawk_keys
422
+ @hawk_keys = {}
423
+
424
+ if options['hawk']
425
+ options['hawk'].split(",").each do |hawk_entry|
426
+ # format is: abc_id[thing]
427
+
428
+ if hawk_entry.include?("{")
429
+ hawk_entry =~ /(.*){(.*)}/
430
+ key, hawk_to = $1, $2
431
+ else
432
+ key = hawk_entry
433
+ hawk_to = @auth
434
+ end
435
+ hawk_scope = key.gsub("_id", "").pluralize
436
+ @hawk_keys[key.to_sym] = [hawk_to, hawk_scope]
437
+ end
438
+
439
+ puts "HAWKING: #{@hawk_keys}"
440
+ end
396
441
  end
397
442
 
398
443
  def identify_object_owner
399
444
  auth_assoc = @auth && @auth.gsub("current_","")
400
445
 
401
- if !@object_owner_sym.empty?
446
+ if @object_owner_sym && ! @self_auth
402
447
  auth_assoc_field = auth_assoc + "_id" unless @god
403
-
404
448
  assoc = eval("#{singular_class}.reflect_on_association(:#{@object_owner_sym})")
405
-
449
+ # byebug
406
450
  if assoc
407
451
  @ownership_field = assoc.name.to_s + "_id"
408
- elsif ! @nested_args.any?
409
-
410
- exit_message = "*** Oops: It looks like is no association from class called #{@singular_class} to the current_#{@object_owner_sym}. 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."
452
+ elsif ! @nested_set.any?
453
+ exit_message = "*** Oops: It looks like is no association `#{@object_owner_sym}` from the object #{@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."
411
454
  raise(HotGlue::Error, exit_message)
412
455
 
413
456
  else
414
-
415
457
  if eval(singular_class + ".reflect_on_association(:#{@object_owner_sym.to_s})").nil? && !eval(singular_class + ".reflect_on_association(:#{@object_owner_sym.to_s.singularize})").nil?
416
458
  exit_message = "*** Oops: you tried to nest #{singular_class} within a route for `#{@object_owner_sym}` but I can't find an association for this relationship. Did you mean `#{@object_owner_sym.to_s.singularize}` (singular) instead?"
417
- else
418
- exit_message = "*** Oops: Missing relationship from class #{singular_class} to :#{@object_owner_sym} maybe add `belongs_to :#{@object_owner_sym}` to #{singular_class}\n (If your user is called something else, pass with flag auth=current_X where X is the model for your auth object 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 flag). To make a controller that can read all records, specify with --god."
459
+ # else # NOTE: not reachable
460
+ # exit_message = "*** Oops: Missing relationship from class #{singular_class} to :#{@object_owner_sym} maybe add `belongs_to :#{@object_owner_sym}` to #{singular_class}\n (If your user is called something else, pass with flag auth=current_X where X is the model for your auth object 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 flag). To make a controller that can read all records, specify with --god."
419
461
  end
420
462
 
421
463
  raise(HotGlue::Error, exit_message)
422
464
  end
465
+ elsif @object_owner_sym && ! @object_owner_eval.include?(".")
466
+ @ownership_field = @object_owner_name + "_id"
423
467
  end
424
468
  end
425
469
 
426
-
427
470
  def setup_fields
428
- auth_assoc = @auth && @auth.gsub("current_","")
429
471
 
430
472
  if !@include_fields
431
473
  @exclude_fields.push :id, :created_at, :updated_at, :encrypted_password,
@@ -434,7 +476,6 @@ module HotGlue
434
476
  :confirmation_token, :confirmed_at,
435
477
  :confirmation_sent_at, :unconfirmed_email
436
478
 
437
- @exclude_fields.push( (auth_assoc + "_id").to_sym) if ! auth_assoc.nil?
438
479
  @exclude_fields.push( @ownership_field.to_sym ) if ! @ownership_field.nil?
439
480
 
440
481
 
@@ -456,30 +497,34 @@ module HotGlue
456
497
  assoc_name = col.to_s.gsub("_id","")
457
498
 
458
499
 
459
- begin
460
- assoc_model = eval("#{singular_class}.reflect_on_association(:#{assoc_name}).active_record")
461
- rescue NameError => e
462
- exit_message = "*** Oops: The model #{singular_class} is missing an association for :#{assoc_name} or the model #{assoc_name.titlecase} doesn't exist. TODO: Please implement a model for #{assoc_name.titlecase}; your model #{singular_class.titlecase} should belong_to :#{assoc_name}. To make a controller that can read all records, specify with --god."
500
+ assoc_model = eval("#{singular_class}.reflect_on_association(:#{assoc_name})")
501
+
502
+ if assoc_model.nil?
503
+ exit_message = "*** Oops: The model #{singular_class} is missing an association for :#{assoc_name} or the model #{assoc_name.titlecase} doesn't exist. TODO: Please implement a model for #{assoc_name.titlecase}; or add to #{singular_class} `belongs_to :#{assoc_name}`. To make a controller that can read all records, specify with --god."
463
504
  puts exit_message
464
505
  raise(HotGlue::Error, exit_message)
465
506
  end
466
507
 
467
-
468
- if assoc_model.nil?
469
- exit_message = "*** Oops. on the #{singular_class} object, there doesn't seem to be an association called '#{assoc_name}'"
470
- puts exit_message
471
- raise(HotGlue::Error,exit_message)
508
+ begin
509
+ assoc_class = eval(assoc_model.try(:class_name))
510
+ @associations << assoc_name.to_sym
511
+ name_list = [:name, :to_label, :full_name, :display_name, :email]
512
+
513
+ rescue
514
+ # unreachable(?)
515
+ # if eval("#{singular_class}.reflect_on_association(:#{assoc_name.singularize})")
516
+ # raise(HotGlue::Error,"*** Oops: #{singular_class} has no association for #{assoc_name.singularize}")
517
+ # else
518
+ # raise(HotGlue::Error,"*** Oops: Missing relationship from class #{singular_class} to :#{@object_owner_sym} maybe add `belongs_to :#{@object_owner_sym}` to #{singular_class}\n (If your user is called something else, pass with flag auth=current_X where X is the model for your auth object 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 flag). To make a controller that can read all records, specify with --god.")
519
+ # end
472
520
  end
473
521
 
474
- @associations << assoc_name.to_sym
475
- assoc_class = eval(assoc_model.name)
476
- name_list = [:name, :to_label, :full_name, :display_name, :email]
477
- if name_list.collect{ |field|
522
+ if assoc_class && name_list.collect{ |field|
478
523
  assoc_class.column_names.include?(field.to_s) || assoc_class.instance_methods.include?(field)
479
524
  }.any?
480
525
  # do nothing here
481
526
  else
482
- exit_message = "\n*** Oops: Missing a label for `#{assoc_class}`. Can't find any column to use as the display label for the #{assoc_name} association on the #{singular_class} model. TODO: Please implement just one of: \n1) name, \n2) to_label, \n3) full_name, \n4) display_name \n5) email \nYou can implement any of these directly on your`#{assoc_class}` model (can be database fields or model methods) or alias them to field you want to use as your display label. Then RERUN THIS GENERATOR. (Field used will be chosen based on rank here.)"
527
+ exit_message = "Oops: Missing a label for `#{assoc_class}`. Can't find any column to use as the display label for the #{assoc_name} association on the #{singular_class} model. TODO: Please implement just one of: 1) name, 2) to_label, 3) full_name, 4) display_name 5) email. You can implement any of these directly on your`#{assoc_class}` model (can be database fields or model methods) or alias them to field you want to use as your display label. Then RERUN THIS GENERATOR. (Field used will be chosen based on rank here.)"
483
528
  raise(HotGlue::Error,exit_message)
484
529
  end
485
530
  end
@@ -487,6 +532,11 @@ module HotGlue
487
532
  end
488
533
  end
489
534
 
535
+
536
+ def auth_root
537
+ "authenticate_" + @auth_identifier.split(".")[0] + "!"
538
+ end
539
+
490
540
  def formats
491
541
  [format]
492
542
  end
@@ -502,7 +552,7 @@ module HotGlue
502
552
  if @namespace
503
553
  begin
504
554
  eval(controller_descends_from)
505
- puts " skipping base controller #{controller_descends_from}"
555
+ # puts " skipping base controller #{controller_descends_from}"
506
556
  rescue NameError => e
507
557
  template "base_controller.rb.erb", File.join("#{'spec/dummy/' if Rails.env.test?}app/controllers#{namespace_with_dash}", "base_controller.rb")
508
558
  end
@@ -569,8 +619,8 @@ module HotGlue
569
619
  end
570
620
 
571
621
  def object_parent_mapping_as_argument_for_specs
572
- if @nested_args.any?
573
- ", " + @nested_args.last + ": " + @nested_args.last
622
+ if @nested_set.any?
623
+ ", " + @nested_set.last[:singular] + ": " + @nested_set.last[:singular]
574
624
  elsif @auth
575
625
  ", #{@auth_identifier}: #{@auth}"
576
626
  end
@@ -582,21 +632,19 @@ module HotGlue
582
632
  last_parent = ", #{@auth_identifier}: #{@auth}"
583
633
  end
584
634
 
585
- @nested_args.each do |arg|
586
- res << " let(:#{arg}) {create(:#{arg} #{last_parent} )}\n"
587
- last_parent = ", #{arg}: #{arg}"
635
+ @nested_set.each do |arg|
636
+ res << " let(:#{arg[:singular]}) {create(:#{arg[:singular]} #{last_parent} )}\n"
637
+ last_parent = ", #{arg[:singular]}: #{arg[:singular]}"
588
638
  end
589
639
  res
590
640
  end
591
641
 
592
-
593
642
  def objest_nest_params_by_id_for_specs
594
- @nested_args.map{|arg|
595
- "#{arg}_id: #{arg}.id"
643
+ @nested_set.map{|arg|
644
+ "#{arg[:singular]}_id: #{arg[:singular]}.id"
596
645
  }.join(",\n ")
597
646
  end
598
647
 
599
-
600
648
  def controller_class_name
601
649
  @controller_build_name
602
650
  end
@@ -618,8 +666,8 @@ module HotGlue
618
666
  end
619
667
 
620
668
  def path_helper_args
621
- if @nested_args.any? && @nested
622
- [(@nested_args).collect{|a| "#{a}"} , singular].join(",")
669
+ if @nested_set.any? && @nested
670
+ [(@nested_set).collect{|a| "#{a[:singular]}"} , singular].join(",")
623
671
  else
624
672
  singular
625
673
  end
@@ -627,7 +675,7 @@ module HotGlue
627
675
 
628
676
  def path_helper_singular
629
677
  if @nested
630
- "#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_" if @nested_args.any?)}#{@controller_build_folder_singular}_path"
678
+ "#{@namespace+"_" if @namespace}#{(@nested_set.collect{|x| x[:singular]}.join("_") + "_" if @nested_set.any?)}#{@controller_build_folder_singular}_path"
631
679
  else
632
680
  "#{@namespace+"_" if @namespace}#{@controller_build_folder_singular}_path"
633
681
  end
@@ -676,7 +724,7 @@ module HotGlue
676
724
 
677
725
  def path_arity
678
726
  res = ""
679
- if @nested_args.any? && @nested
727
+ if @nested_set.any? && @nested
680
728
  res << nested_objects_arity + ", "
681
729
  end
682
730
  res << "@" + singular
@@ -695,33 +743,24 @@ module HotGlue
695
743
  end
696
744
 
697
745
  def new_path_name
698
-
699
746
  HotGlue.optionalized_ternary(namespace: @namespace,
700
747
  target: singular,
701
748
  nested_set: @nested_set,
702
749
  modifier: "new_",
703
750
  with_params: true)
704
- # base = "new_#{@namespace+"_" if @namespace}#{(@nested_args.join("_") + "_") if @nested_args.any?}#{@controller_build_folder_singular}_path"
705
- # if @nested_args.any?
706
- # base += "(" + @nested_args.collect { |arg|
707
- # "#{arg}.id"
708
- # }.join(", ") + ")"
709
- # end
710
- # base
711
751
  end
712
752
 
713
753
  def nested_assignments
714
- return "" if @nested_args.none?
715
- @nested_args.map{|a| "#{a}: #{a}"}.join(", ") #metaprgramming into Ruby hash
754
+ return "" if @nested_set.none?
755
+ @nested_set.map{|a| "#{a}: #{a}"}.join(", ") #metaprgramming into Ruby hash
716
756
  end
717
757
 
718
758
  def nested_assignments_top_level # this is by accessing the instance variable-- only use at top level
719
- @nested_args.map{|a| "#{a}: @#{a}"}.join(", ") #metaprgramming into Ruby hash
759
+ @nested_set.map{|a| "#{a[:singular]}"}.join(", ") #metaprgramming into Ruby hash
720
760
  end
721
761
 
722
-
723
762
  def nest_assignments_operator(top_level = false, leading_comma = false)
724
- if @nested_args.any?
763
+ if @nested_set.any?
725
764
  "#{", " if leading_comma}#{top_level ? nested_assignments_top_level : nested_assignments }"
726
765
  else
727
766
  ""
@@ -733,25 +772,25 @@ module HotGlue
733
772
  end
734
773
 
735
774
  def nested_objects_arity
736
- @nested_args.map{|a| "@#{a}"}.join(", ")
775
+ @nested_set.map{|a| "@#{a[:singular]}"}.join(", ")
737
776
  end
738
777
 
739
778
  def nested_arity_for_path
740
- [@nested_args[0..-1].collect{|a| "@#{a}"}].join(", ") #metaprgramming into arity for the Rails path helper
779
+ [@nested_set[0..-1].collect{|a| "@#{a[:singular]}"}].join(", ") #metaprgramming into arity for the Rails path helper
741
780
  end
742
781
 
743
782
  def object_scope
744
783
  if @auth
745
- if @nested_args.none?
784
+ if @nested_set.none?
746
785
  @auth + ".#{plural}"
747
786
  else
748
- "@" + @nested_args.last + ".#{plural}"
787
+ "@" + @nested_set.last[:singular] + ".#{plural}"
749
788
  end
750
789
  else
751
- if @nested_args.none?
790
+ if @nested_set.none?
752
791
  @singular_class
753
792
  else
754
- "@" + @nested_args.last + ".#{plural}"
793
+ "@" + @nested_set.last[:singular] + ".#{plural}"
755
794
  end
756
795
 
757
796
  end
@@ -762,10 +801,10 @@ module HotGlue
762
801
  if @auth
763
802
  if @self_auth
764
803
  @singular_class + ".where(id: #{@auth}.id)"
765
- elsif @nested_args.none?
804
+ elsif @nested_set.none?
766
805
  @auth + ".#{plural}"
767
806
  else
768
- "@" + @nested_args.last + ".#{plural}"
807
+ "@" + @nested_set.last[:singular] + ".#{plural}"
769
808
  end
770
809
  else
771
810
  @singular_class + ".all"
@@ -773,7 +812,7 @@ module HotGlue
773
812
  end
774
813
 
775
814
  def any_nested?
776
- @nested_args.any?
815
+ @nested_set.any?
777
816
  end
778
817
 
779
818
  def all_objects_variable
@@ -838,7 +877,7 @@ module HotGlue
838
877
  #
839
878
  # if File.exists?(menu_file)
840
879
  # # TODO: can I insert the new menu item into the menu programatically here?
841
- # # not sure how i would acheive this without nokogiri
880
+ # # not sure how i would achieve this without nokogiri
842
881
  #
843
882
  # end
844
883
 
@@ -914,8 +953,11 @@ module HotGlue
914
953
  show_only: @show_only,
915
954
  singular_class: singular_class,
916
955
  singular: singular,
956
+ hawk_keys: @hawk_keys,
917
957
  col_identifier: col_identifier,
918
- ownership_field: @ownership_field
958
+ ownership_field: @ownership_field,
959
+ form_labels_position: @form_labels_position,
960
+ form_placeholder_labels: @form_placeholder_labels
919
961
  )
920
962
  end
921
963
 
@@ -969,7 +1011,9 @@ module HotGlue
969
1011
  singular_class: singular_class,
970
1012
  singular: singular,
971
1013
  layout: @layout,
972
- col_identifier: col_identifier
1014
+ col_identifier: col_identifier,
1015
+ inline_list_labels: @inline_list_labels
1016
+
973
1017
  )
974
1018
  end
975
1019
 
@@ -999,9 +1043,8 @@ module HotGlue
999
1043
  "display_name"
1000
1044
  elsif me.column_names.include?("email") || me.instance_methods(false).include?(:email)
1001
1045
  "email"
1002
- elsif me.column_names.include?("number") || me.instance_methods(false).include?(:number)
1003
- "number"
1004
1046
  else
1047
+ # NOT UNREACHABLE BUT UNTESTED
1005
1048
  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)"
1006
1049
  raise(HotGlue::Error, exit_message)
1007
1050
  end
@@ -1081,7 +1124,7 @@ module HotGlue
1081
1124
  def nested_for_turbo_nested_constructor(top_level = true)
1082
1125
  instance_symbol = "@" if top_level
1083
1126
  instance_symbol = "" if !top_level
1084
- if @nested_args.none?
1127
+ if @nested_set.none?
1085
1128
  "\"\""
1086
1129
  else
1087
1130
  @nested_set.collect{|arg|
@@ -1093,10 +1136,10 @@ module HotGlue
1093
1136
  def nested_for_assignments_constructor(top_level = true)
1094
1137
  instance_symbol = "@" if top_level
1095
1138
  instance_symbol = "" if !top_level
1096
- if @nested_args.none?
1139
+ if @nested_set.none?
1097
1140
  ""
1098
1141
  else
1099
- ", \n nested_for: \"" + @nested_args.collect{|a| "#{a}-" + '#{' + instance_symbol + a + ".id}"}.join("__") + "\""
1142
+ ", \n nested_for: \"" + @nested_set.collect{|a| "#{a[:singular]}-" + '#{' + instance_symbol + a[:singular] + ".id}"}.join("__") + "\""
1100
1143
  end
1101
1144
  end
1102
1145
 
@@ -1105,6 +1148,12 @@ module HotGlue
1105
1148
  def cc_filename_with_extensions(name, file_format = format)
1106
1149
  [name, file_format].compact.join(".")
1107
1150
  end
1151
+
1152
+ def hawk_to_ruby
1153
+ @hawk_keys.collect{ |k,v|
1154
+ "#{k}: [#{v[0]}, \"#{v[1]}\"] "
1155
+ }.join(", ")
1156
+ end
1108
1157
  end
1109
1158
  end
1110
1159