hot-glue 0.6.23 → 0.6.24

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.
@@ -1,6 +1,6 @@
1
1
  class RelatedSetField < Field
2
2
 
3
- attr_accessor :assoc_name, :assoc_class, :assoc
3
+ attr_accessor :assoc_name, :assoc_class, :assoc, :label_field, :hawk
4
4
 
5
5
  def initialize( scaffold: , name: )
6
6
  super
@@ -17,15 +17,23 @@ class RelatedSetField < Field
17
17
 
18
18
  @assoc_class = eval(@related_set_model.try(:class_name))
19
19
 
20
- name_list = [:name, :to_label, :full_name, :display_name, :email]
21
20
 
22
- if assoc_class && name_list.collect{ |field|
23
- assoc_class.respond_to?(field.to_s) || assoc_class.instance_methods.include?(field)
24
- }.none?
25
- 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 #{class_name} 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.)"
26
- raise(HotGlue::Error, exit_message)
27
- end
21
+ @deets = scaffold.related_sets[name.to_sym]
22
+
23
+ if @deets[:label_field].nil?
24
+ @label_field = "label"
28
25
 
26
+ # name_list = [:name, :to_label, :full_name, :display_name, :email]
27
+ #
28
+ # if assoc_class && name_list.collect{ |field|
29
+ # assoc_class.respond_to?(field.to_s) || assoc_class.instance_methods.include?(field)
30
+ # }.none?
31
+ # 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 #{class_name} 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.)"
32
+ # raise(HotGlue::Error, exit_message)
33
+ # end
34
+ else
35
+ @label_field = @deets[:label_field]
36
+ end
29
37
  end
30
38
 
31
39
 
@@ -35,11 +43,23 @@ class RelatedSetField < Field
35
43
  if pundit
36
44
  disabled_syntax << ", {disabled: ! #{class_name}Policy.new(#{auth}, @#{singular}).role_ids_able?}"
37
45
  end
38
- " <%= f.collection_check_boxes :#{association_ids_method}, #{association_class_name}.all, :id, :label, {}#{disabled_syntax} do |m| %>
46
+ " <%= f.collection_check_boxes :#{association_ids_method}, #{record_scope}, :id, :#{label_field}, {}#{disabled_syntax} do |m| %>
39
47
  <%= m.check_box %> <%= m.label %><br />
40
48
  <% end %>"
41
49
  end
42
50
 
51
+ def record_scope
52
+ if hawk.nil?
53
+ "#{association_class_name}.all"
54
+ else
55
+ hawk
56
+ end
57
+ end
58
+
59
+ def label_field
60
+ @label_field
61
+ end
62
+
43
63
  def association_ids_method
44
64
  eval("#{class_name}.reflect_on_association(:#{name})").class_name.underscore + "_ids"
45
65
  end
@@ -49,7 +69,7 @@ class RelatedSetField < Field
49
69
  end
50
70
 
51
71
  def viewable_output
52
- "<%= #{singular}.#{name}.collect(&:label).join(\", \") %>"
72
+ "<%= #{singular}.#{name}.collect(&:#{label_field}).join(\", \") %>"
53
73
  end
54
74
  end
55
75
 
@@ -517,13 +517,30 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
517
517
  related_set_input = options['related_sets'].split(",")
518
518
  @related_sets = {}
519
519
  related_set_input.each do |setting|
520
- name = setting.to_sym
521
- association_ids_method = eval("#{singular_class}.reflect_on_association(:#{setting.to_sym})").class_name.underscore + "_ids"
522
- class_name = eval("#{singular_class}.reflect_on_association(:#{setting.to_sym})").class_name
523
520
 
524
- @related_sets[setting.to_sym] = { name: setting.to_sym,
521
+ if setting.include?("{") && setting.include?("[")
522
+ setting =~ /(.*){(.*)}\[(.*)\]/
523
+ key, label, hawk = $1, $2 , $3
524
+ elsif setting.include?("{") && !setting.include?("[")
525
+ setting =~ /(.*){(.*)}/
526
+ key, label = $1, $2 , $3
527
+ elsif setting.include?("[") && !setting.include?("{")
528
+ setting =~ /(.*)\[(.*)\]/
529
+ key, hawk = $1, $2
530
+ else
531
+
532
+ key = setting
533
+ label = "label"
534
+ end
535
+
536
+ association_ids_method = eval("#{singular_class}.reflect_on_association(:#{key.to_sym})").class_name.underscore + "_ids"
537
+ class_name = eval("#{singular_class}.reflect_on_association(:#{key.to_sym})").class_name
538
+
539
+ @related_sets[key.to_sym] = { name: key.to_sym,
525
540
  association_ids_method: association_ids_method,
526
- class_name: class_name }
541
+ class_name: class_name,
542
+ label_field: label,
543
+ hawk: hawk }
527
544
  end
528
545
 
529
546
  if @related_sets.any?
@@ -281,20 +281,19 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
281
281
  # <%= rs[:association_ids_method] %>: modified_params[:<%= rs[:association_ids_method] %>>]} syntax for Pundit
282
282
  modified_relations = { <%= rs[:association_ids_method] %>: modified_params[:<%= rs[:association_ids_method] %>] }
283
283
  return unless modified_params[:<%= rs[:association_ids_method] %>].present?
284
- policy_check = <%= singular_class %>Policy.new(current_user, @<%= singular %>,
285
- modified_relations:).method("#{action}?".to_sym).call
284
+ policy_check = <%= singular_class %>Policy.new(current_user, @<%= singular %>).method("#{action}?".to_sym).call
286
285
  return if policy_check
287
286
  raise Pundit::NotAuthorizedError, message: @<%= singular %>.errors.collect{|k| "#{k.attribute} #{k.message}"}.join(" ")
288
287
  end<% end %><% end %>
289
288
 
290
289
  def <%=singular_name%>_params
291
- fields = <%= ((fields_filtered_for_strong_params - @show_only) + @magic_buttons.collect{|x| "__#{x}"} + @phantom_create_params.split(",")).collect{|sym| ":#{sym}"}.join(", ") %><%= ", " + @related_sets.collect{|key, rs| "#{rs[:association_ids_method]}: []"}.join(", ") if @related_sets.any? %><%= ", " + @alt_lookups.collect{|k,v| ":__lookup_#{v[:assoc].downcase}_#{v[:lookup_as]}" }.join(", ") if @alt_lookups.any? %>
290
+ fields = <%= ((fields_filtered_for_strong_params - @show_only) + @magic_buttons.collect{|x| "__#{x}"} + @phantom_create_params.split(",")).collect{|sym| ":#{sym}"}.join(", ") %><%= ", " + @related_sets.collect{|key, rs| "{#{rs[:association_ids_method]}: []}"}.join(", ") if @related_sets.any? %><%= ", " + @alt_lookups.collect{|k,v| ":__lookup_#{v[:assoc].downcase}_#{v[:lookup_as]}" }.join(", ") if @alt_lookups.any? %>
292
291
  params.require(:<%= testing_name %>).permit(fields)
293
292
  end<% if @update_show_only %>
294
293
 
295
294
  <% unless @no_edit %>
296
295
  def update_<%=singular_name%>_params
297
- fields = <%= ((fields_filtered_for_strong_params - @update_show_only) + @magic_buttons.collect{|x| "__#{x}"} + @phantom_update_params.split(",")).collect{|sym| ":#{sym}"}.join(", ") %><%= ", " + @related_sets.collect{|key, rs| "#{rs[:association_ids_method]}: []"}.join(", ") if @related_sets.any? %><%= ", " + @alt_lookups.collect{|k,v| ":__lookup_#{v[:assoc].downcase}_#{v[:lookup_as]}" }.join(", ") if @alt_lookups.any? %>
296
+ fields = <%= ((fields_filtered_for_strong_params - @update_show_only) + @magic_buttons.collect{|x| "__#{x}"} + @phantom_update_params.split(",")).collect{|sym| ":#{sym}"}.join(", ") %><%= ", " + @related_sets.collect{|key, rs| "{#{rs[:association_ids_method]}: []}"}.join(", ") if @related_sets.any? %><%= ", " + @alt_lookups.collect{|k,v| ":__lookup_#{v[:assoc].downcase}_#{v[:lookup_as]}" }.join(", ") if @alt_lookups.any? %>
298
297
  <%= (fields_filtered_for_strong_params - @update_show_only).collect{|col|
299
298
  # TODO : fields not on show only also not invisible should be checked here
300
299
  # for _able? methods and added only when able
@@ -1,5 +1,5 @@
1
1
  module HotGlue
2
2
  class Version
3
- CURRENT = '0.6.23'
3
+ CURRENT = '0.6.24'
4
4
  end
5
5
  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.6.23
4
+ version: 0.6.24
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: 2025-08-15 00:00:00.000000000 Z
11
+ date: 2025-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails