hot-glue 0.6.20 → 0.6.21

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bce1267ee3ccc16a7f32068e1f4faa0aafab073d1f1af91744f02c7e63e2b40c
4
- data.tar.gz: f87d7c1cecc3cd30ceff3d2176d82cc6e51ff62245ba54e02ffd8487cb214d75
3
+ metadata.gz: a3b2bb368a4cdb82730ae64b48bea2e06e8183eeca6b262fe26efa2291710f6d
4
+ data.tar.gz: cb9ac4fe4f6175098e940baa602f766bf962367c4b3de9b782c9b5f11a6b1891
5
5
  SHA512:
6
- metadata.gz: b3740aff61a08504a01237aa822ff3e92ed09afc91666d4398e400bf8cede65d74d86dddd950e664ff155de69413707fd5b5460b31c0504428df50c6c18af8d5
7
- data.tar.gz: 503b69ea3a5abe6074fcc0bc987db37c1efb88e38cbbb79ecf1fb5ff8a58fda01609469b4da0554c42ded090ef1c896e9dc00c759f1fa31fc31ed34b4ccbea7d
6
+ metadata.gz: 15dcae458d17b32d08922021b3baafb87a4be7f1d4f2a576aad23b933b532983835458a06c2d71dd2b8eb984c48df50df394a4d9b84e70a3a5ba56590e8e197f
7
+ data.tar.gz: d56153ba5db70d8ee003ec4d7ef7b85b99be5161deb09fc0453c52c967c8489b87a0f21596bfc826c6882e61e0aff6f317fa5b2c007ca380251baec876f66397
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hot-glue (0.6.19)
4
+ hot-glue (0.6.20)
5
5
  ffaker (~> 2.16)
6
6
  kaminari (~> 1.2)
7
7
  rails (> 5.1)
data/README.md CHANGED
@@ -1361,20 +1361,34 @@ Use `before` to make the labels come before or `after` to make them come after.
1361
1361
 
1362
1362
 
1363
1363
  ### Code insertions
1364
+ Insert some code into the `new`, `create` or `update` action actions.
1364
1365
 
1365
- ### `--code-before-create=`
1366
- ### `--code-after-create=`
1367
- ### `--code-before-update=`
1368
- ### `--code-after-update=`
1369
-
1370
- Insert some code into the `create` action or `update` actions.
1371
- The **before code** is called _after authorization_ but _before saving_ (which creates the record, or fails validation).
1372
- The **after create** code is called after the record is saved (and thus has an id in the case of the create action).
1373
- Both should be wrapped in quotation marks when specified in the command line, and use semicolons to separate multiple lines of code.
1366
+ Wrapped in quotation marks when specified in the command line, and use semicolons to separate multiple lines of code.
1374
1367
  (Notice the funky indentation of the lines in the generated code. Adjust you input to get the indentation correct.)
1375
1368
 
1376
1369
 
1377
1370
 
1371
+ #### `--code-before-create=`
1372
+
1373
+ called _after authorization_ but _before saving the new record_
1374
+ (which creates the record, or fails validation).
1375
+ Here you can do things like set default values, or modify the params before the record is saved.
1376
+
1377
+ #### `--code-after-create=`
1378
+ is called after the record is saved (and thus has an id in the case of the create action).
1379
+
1380
+ #### `--code-before-update=`
1381
+ is called in the `update` action _before_ it is saved.
1382
+ `
1383
+ #### `--code-after-update=`
1384
+ is called in the `update` action _after_ it is saved.
1385
+
1386
+ #### `--code-after-new=`
1387
+ is called in the `new` after the .new() call
1388
+
1389
+
1390
+
1391
+
1378
1392
  ### `--search=` (options: simple, set, false predicate, default: false)
1379
1393
 
1380
1394
 
@@ -2019,6 +2033,22 @@ These automatic pickups for partials are detected at build time. This means that
2019
2033
  # VERSION HISTORY
2020
2034
 
2021
2035
 
2036
+ #### 2025-07-05 v0.6.21
2037
+ •Now use new code insertion `--code-after-new` for code that happens directly after `.new()` call. use semicolon (`;`) to create linebreaks; no reason why the factories should insert flash messages
2038
+
2039
+ • removes duplicitous flash messages in factory context
2040
+
2041
+ • adds documentation for `--code-before-create`, `--code-after-create`, `--code-before-update`, `--code-after-update` (these features were already implemented)
2042
+
2043
+ • updates are now built using `.assign_attributes` followed by `.save` (previously, they were updated with one `.update()` call); this allows your Pundit policy to check if the changed values are valid and raise an exception if not allowed based on the changed data (can be checked on Rails models with `.changed` or `.changes`; see https://api.rubyonrails.org/classes/ActiveModel/Dirty.html)
2044
+
2045
+ • Fixes to timezone aware input. If your `current_user` (or auth object) has a method `timezone`, your datetime and time inputs will be timezone-aware.
2046
+
2047
+ If a timezone is present, datetimes & times will be converted from database-native UTC into the current user's timezone when displayed (either as viewable or editable)
2048
+
2049
+ If a user puts a time into the interface, it is assumed to be in the user's timezone and is converted to UTC before being saved.
2050
+
2051
+
2022
2052
  #### 2025-06-13 v0.6.20
2023
2053
  Breaking changes:
2024
2054
  • the setting in your hot_glue.yml file for `:pundit_default:` has been renamed just `:pundit:`.
@@ -74,20 +74,31 @@ module HotGlue
74
74
  (Time.now.utc.month == 11 && Time.now.utc.day < (7 - Time.now.utc.wday))
75
75
  end
76
76
 
77
- def modify_date_inputs_on_params(modified_params, current_user_object = nil, field_list = nil)
78
- use_timezone = (current_user_object.try(:timezone)) || Time.zone
77
+ def modify_date_inputs_on_params(modified_params, current_user_object = nil, field_list = {})
78
+
79
+ use_timezone = if current_user_object.try(:timezone)
80
+ (ActiveSupport::TimeZone[current_user_object.timezone])
81
+ else
82
+ Time.zone
83
+ end
84
+
85
+
79
86
  uses_dst = (current_user_object.try(:locale_uses_dst)) || false
80
87
 
81
88
  modified_params = modified_params.tap do |params|
82
89
  params.keys.each{|k|
83
-
84
- if field_list.nil? # legacy pre v0.5.18 behavior
85
- include_me = k.ends_with?("_at") || k.ends_with?("_date")
86
- else
87
- include_me = field_list.include?(k.to_sym)
90
+ if field_list.is_a?(Hash)
91
+ include_me = field_list[k.to_sym].present?
92
+ elsif field_list.is_a?(Array)
93
+ field_list.include?(k.to_sym)
88
94
  end
95
+
96
+ parsables = {datetime: "%Y-%m-%d %H:%M %z",
97
+ time: "%H:%M %z"}
98
+
89
99
  if include_me && params[k].present?
90
100
  if use_timezone
101
+
91
102
  parse_date = "#{params[k].gsub("T", " ")} #{use_timezone.formatted_offset}"
92
103
  # note: as according to https://stackoverflow.com/questions/20111413/html5-datetime-local-control-how-to-hide-seconds
93
104
  # there is no way to set the seconds to 00 in the datetime-local input field
@@ -96,8 +107,12 @@ module HotGlue
96
107
  # if they already exist in your database, you should zero them out
97
108
  # or apply .change(sec: 0) when displaying them as output in the form
98
109
  # this will prevent seconds from being added by the browser
99
- parsed_time = Time.strptime(parse_date, "%Y-%m-%d %H:%M %Z")
100
- parsed_time = parsed_time.to_time - 60.minutes if uses_dst && is_dst_now?
110
+ if field_list.is_a?(Array)
111
+ parsed_time = Time.strptime(parse_date, "%Y-%m-%d %H:%M %z")
112
+ else
113
+ parsed_time = Time.strptime(parse_date, parsables[field_list[k.to_sym]])
114
+ end
115
+ # parsed_time = parsed_time.to_time - 60.minutes if uses_dst && is_dst_now?
101
116
  params[k] = parsed_time
102
117
  end
103
118
  end
@@ -39,6 +39,7 @@ class Field
39
39
  @god = scaffold.god
40
40
 
41
41
 
42
+
42
43
  # TODO: remove knowledge of subclasses from Field
43
44
  unless self.class == AttachmentField || self.class == RelatedSetField
44
45
  @sql_type = eval("#{class_name}.columns_hash['#{name}']").sql_type
@@ -194,7 +195,8 @@ class Field
194
195
  end
195
196
 
196
197
  def modify_binary?
197
- !!(modify_as && modify_as[name.to_sym] && modify_as[name.to_sym][:binary])
198
+ return false if !modify_as
199
+ modify_as[:binary]
198
200
  end
199
201
 
200
202
  def display_boolean_as
@@ -10,7 +10,7 @@ class TimeField < Field
10
10
 
11
11
  def line_field_output
12
12
  "<% unless #{singular}.#{name}.nil? %>
13
- <%= #{singular}.#{name}.in_time_zone(current_timezone).strftime('%l:%M %p ') %>
13
+ <%= #{singular}.#{name}.in_time_zone(current_timezone).strftime('%l:%M %p %Z') %>
14
14
  <% else %>
15
15
  <span class=''>MISSING</span>
16
16
  <% end %>"
@@ -106,6 +106,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
106
106
  class_option :code_after_create, default: nil
107
107
  class_option :code_before_update, default: nil
108
108
  class_option :code_after_update, default: nil
109
+ class_option :code_after_new, default: nil
109
110
  class_option :record_scope, default: nil
110
111
  class_option :no_nav_menu, type: :boolean, default: false # suppress writing to _nav template
111
112
  class_option :include_object_names, type: :boolean, default: false
@@ -531,6 +532,7 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
531
532
  @code_after_create = options['code_after_create']
532
533
  @code_before_update = options['code_before_update']
533
534
  @code_after_update = options['code_after_update']
535
+ @code_after_new = options['code_after_new']
534
536
 
535
537
  buttons_width = ((!@no_edit && 1) || 0) + ((!@no_delete && 1) || 0) + @magic_buttons.count
536
538
 
@@ -967,10 +969,8 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
967
969
  #{@factory_creation}
968
970
  "
969
971
  res << "\n " + "@#{singular} = factory.#{singular}" unless res.include?("@#{singular} = factory.#{singular}")
970
- res << "\n flash[:notice] = \"Successfully created \#{@#{singular}.name}\" unless @#{singular}.new_record?
971
- rescue ActiveRecord::RecordInvalid
972
+ res << "\n rescue ActiveRecord::RecordInvalid
972
973
  @#{singular} = factory.#{singular}
973
- flash[:alert] = \"Oops, your #{singular} could not be created. #{@hawk_alarm}\"
974
974
  @action = 'new'
975
975
  end"
976
976
  res
@@ -1174,13 +1174,17 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1174
1174
  end
1175
1175
 
1176
1176
  def datetime_fields_list
1177
- @columns.select do |col|
1178
- if @the_object.columns_hash[col.to_s]
1179
- @the_object.columns_hash[col.to_s].type == :datetime
1177
+ @columns.each_with_object({}) do |col, hash|
1178
+ column = @the_object.columns_hash[col.to_s]
1179
+ if column && [:datetime, :time].include?(column.type)
1180
+ hash[col.to_sym] = column.type
1180
1181
  end
1181
1182
  end
1182
1183
  end
1183
1184
 
1185
+
1186
+
1187
+
1184
1188
  def form_path_new_helper
1185
1189
  HotGlue.optionalized_ternary(namespace: @namespace,
1186
1190
  target: @controller_build_folder,
@@ -1320,12 +1324,13 @@ class HotGlue::ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
1320
1324
  # to know who the current user under this design
1321
1325
  # for timeinput = user_centered , we need to know who the current user is
1322
1326
  # so we can set the time zone to the user's time zone
1323
- #
1327
+
1324
1328
  if options['auth']
1325
1329
  options['auth']
1326
1330
  elsif @god
1327
- # do we use current_user here
1328
1331
  "nil"
1332
+ else
1333
+ @auth
1329
1334
  end
1330
1335
  end
1331
1336
 
@@ -95,6 +95,8 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
95
95
  @<%= singular_name %> = <%= class_name %>.new<% if eval("#{class_name}.reflect_on_association(:#{@object_owner_sym})").class == ActiveRecord::Reflection::BelongsToReflection %>(<%= @object_owner_sym %>: <%= @object_owner_eval %>)<% end %><% elsif @object_owner_optional && any_nested? %>
96
96
  @<%= singular_name %> = <%= class_name %>.new({}.merge(<%= @nested_set.last[:singular] %> ? {<%= @object_owner_sym %>: <%= @object_owner_eval %>} : {}))<% else %>
97
97
  @<%= singular_name %> = <%= class_name %>.new(<% if any_nested? %><%= @object_owner_sym %>: <%= @object_owner_eval %><% end %>)<% end %>
98
+ <%= @code_after_new ? @code_after_new.gsub(";","\n") + "\n" : "" %>
99
+
98
100
  <% if @pundit && !@pundit_policy_override %>
99
101
  authorize @<%= singular %><% elsif @pundit && @pundit_policy_override %>
100
102
  skip_authorization
@@ -216,19 +218,20 @@ class <%= controller_class_name %> < <%= controller_descends_from %>
216
218
  <% end %>
217
219
  <% if @hawk_keys.any? %> modified_params = hawk_params({<%= hawk_to_ruby %>}, modified_params)<% end %>
218
220
  <%= controller_attachment_orig_filename_pickup_syntax %>
221
+ @<%= singular_name %>.assign_attributes(modified_params)
219
222
  <% if @pundit && !@pundit_policy_override %>
220
223
  authorize @<%= singular_name %>
221
224
  <%= @code_before_update ? "\n " + @code_before_update.gsub(";", "\n") : "" %>
222
225
 
223
- if @<%= singular_name %>.update(modified_params)
226
+ if @<%= singular_name %>.save
224
227
 
225
228
  <% elsif @pundit && @pundit_policy_override %>
226
229
  skip_authorization
227
230
  raise Pundit::NotAuthorizedError if ! <%= @pundit_policy_override %>.update?
228
- if @<%= singular_name %>.update(modified_params)
231
+ if @<%= singular_name %>.save
229
232
  <% else %>
230
233
  <%= @code_before_update ? "\n " + @code_before_update.gsub(";", "\n") : "" %>
231
- if @<%= singular_name %>.update(modified_params)<% end %>
234
+ if @<%= singular_name %>.save<% end %>
232
235
  <%= post_action_parental_updates.compact.join("\n ") %>
233
236
  <%= @code_after_update ? "\n " + @code_after_update.gsub(";", "\n") : "" %>
234
237
  <% if @display_list_after_update %> load_all_<%= plural %><% end %>
@@ -1,5 +1,5 @@
1
1
  module HotGlue
2
2
  class Version
3
- CURRENT = '0.6.20'
3
+ CURRENT = '0.6.21'
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.20
4
+ version: 0.6.21
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-06-13 00:00:00.000000000 Z
11
+ date: 2025-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails