brick 1.0.148 → 1.0.150

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: 66301eacecd8c8f5dc5587f234ce373673a9d8544dad12e6ae27e0b1a99bed40
4
- data.tar.gz: 226f44c9814fe1b47db39be49a3c35f499dd8795197523f74e8072de641d4cdd
3
+ metadata.gz: 7914cc56d8cd8919835028d5ad9b05a50a2b17baf32c9699d1f78bbaf9417e0d
4
+ data.tar.gz: a7f945e136fe8401c54e8fd24a4d92a5cef24b22bb68d2caceac28d809ff8f07
5
5
  SHA512:
6
- metadata.gz: ab20a8565d71699db3bb960dc82e8091072be169011f62beb505527e5946f406fde89dab610d26717d3be118fab0ee7daf38c774c6f0a92f9d655f54cba3d0d5
7
- data.tar.gz: 2b2f29c67712b001bfe43a03b881eec48eee7cf73686fe54da8e4aa30e88af91f7b23f67e95620eccde2b171a44f4e117d0326451c5917c4ef699b6141344382
6
+ metadata.gz: fa3ed344e3d4beed83cf9a6fd7059d78032497f8a6c51c825fd50d163e61bd8029afe3dd82e055631d8258b0c9cf54f7d176e064c47fe9fb5a70cc25cdb67faf
7
+ data.tar.gz: e43ca92a155c805d4dc5be0a2548d9612bc0b1a92cb2e65722ca4c55c81dbef9b476493d6764eece75489e9caf60e2a1046ca960d9a58cafe060aeae11db954a
@@ -95,7 +95,7 @@ module ActiveRecord
95
95
  return @_brick_primary_key if instance_variable_defined?(:@_brick_primary_key)
96
96
 
97
97
  pk = begin
98
- primary_key.is_a?(String) ? [primary_key] : primary_key || []
98
+ primary_key.is_a?(String) ? [primary_key] : primary_key.dup || []
99
99
  rescue
100
100
  []
101
101
  end
@@ -907,7 +907,7 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
907
907
  s << v
908
908
  end
909
909
  else # String stuff (which defines a custom ORDER BY) just comes straight through
910
- v = v.split('.').map { |x| _br_quoted_name(x) }.join('.')
910
+ # v = v.split('.').map { |x| _br_quoted_name(x) }.join('.')
911
911
  s << v
912
912
  # Avoid "PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list" in Postgres
913
913
  selects << v if is_distinct
@@ -1695,7 +1695,7 @@ class Object
1695
1695
  when Symbol
1696
1696
  order_tbl[order_default] || order_default
1697
1697
  else
1698
- pk.map { |part| "#{table_name}.#{part}"}.join(', ') # If it's not a custom ORDER BY, just use the key
1698
+ pk.map { |part| "#{table_name}.#{part}"} # If it's not a custom ORDER BY, just use the key
1699
1699
  end
1700
1700
  end
1701
1701
 
@@ -2238,12 +2238,7 @@ class Object
2238
2238
 
2239
2239
  if is_need_params
2240
2240
  code << " def #{params_name}\n"
2241
- permits = model.columns_hash.keys.map(&:to_sym)
2242
- permits_txt = permits.map(&:inspect) +
2243
- model.reflect_on_all_associations.select { |assoc| assoc.macro == :has_many && assoc.options[:through] }.map do |assoc|
2244
- permits << { "#{assoc.name.to_s.singularize}_ids".to_sym => [] }
2245
- "#{assoc.name.to_s.singularize}_ids: []"
2246
- end
2241
+ permits_txt = self._brick_find_permits(model, (permits = model.columns_hash.keys.map(&:to_sym)))
2247
2242
  code << " params.require(:#{require_name = model.name.underscore.tr('/', '_')
2248
2243
  }).permit(#{permits_txt.join(', ')})\n"
2249
2244
  code << " end\n"
@@ -2259,6 +2254,98 @@ class Object
2259
2254
  [built_controller, code]
2260
2255
  end
2261
2256
 
2257
+ def _brick_find_permits(model, current_permits)
2258
+ model.reflect_on_all_associations.select { |assoc| assoc.macro == :has_many }.each_with_object([]) do |assoc, s|
2259
+ if assoc.options[:through]
2260
+ current_permits << { "#{assoc.name.to_s.singularize}_ids".to_sym => [] }
2261
+ s << "#{assoc.name.to_s.singularize}_ids: []"
2262
+ elsif assoc.active_record.instance_methods.include?(:"#{assoc.name}_attributes=")
2263
+ # Support nested attributes which use the friendly_id gem
2264
+ self._brick_nested_friendly_id if Object.const_defined?('FriendlyId') &&
2265
+ assoc.klass.instance_variable_get(:@friendly_id_config)
2266
+ new_attrib_text = self._brick_find_permits(assoc.klass, (new_permits = assoc.klass.columns_hash.keys.map(&:to_sym)))
2267
+ new_permits << :_destroy
2268
+ current_permits << { "#{assoc.name}_attributes".to_sym => new_permits }
2269
+ s << "#{assoc.name}_attributes: #{new_attrib_text}"
2270
+ end
2271
+ end
2272
+ current_permits
2273
+ end
2274
+
2275
+ def _brick_nested_friendly_id
2276
+ unless @_brick_nested_friendly_id
2277
+ ::ActiveRecord::Base.class_exec do
2278
+ if private_instance_methods.include?(:assign_nested_attributes_for_collection_association)
2279
+ alias _brick_anafca assign_nested_attributes_for_collection_association
2280
+ def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
2281
+ association = association(association_name)
2282
+ slug_column = association.klass.instance_variable_get(:@friendly_id_config)&.slug_column
2283
+ return _brick_anafca unless slug_column
2284
+
2285
+ # Here is the FriendlyId version of #assign_nested_attributes_for_collection_association
2286
+ options = nested_attributes_options[association_name]
2287
+ attributes_collection = attributes_collection.to_h if attributes_collection.respond_to?(:permitted?)
2288
+
2289
+ unless attributes_collection.is_a?(Hash) || attributes_collection.is_a?(Array)
2290
+ raise ArgumentError, "Hash or Array expected for attribute `#{association_name}`, got #{attributes_collection.class.name} (#{attributes_collection.inspect})"
2291
+ end
2292
+
2293
+ check_record_limit!(options[:limit], attributes_collection)
2294
+
2295
+ if attributes_collection.is_a? Hash
2296
+ keys = attributes_collection.keys
2297
+ attributes_collection = if keys.include?("id") || keys.include?(:id)
2298
+ [attributes_collection]
2299
+ else
2300
+ attributes_collection.values
2301
+ end
2302
+ end
2303
+ existing_records = if association.loaded?
2304
+ association.target
2305
+ else
2306
+ attribute_ids = attributes_collection.filter_map { |a| a["id"] || a[:id] }
2307
+ if attribute_ids.empty?
2308
+ []
2309
+ else # Implement the same logic as "friendly" scope
2310
+ association.scope.where(association.klass.primary_key => attribute_ids)
2311
+ .or(association.scope.where(slug_column => attribute_ids))
2312
+ end
2313
+ end
2314
+ attributes_collection.each do |attributes|
2315
+ attributes = attributes.to_h if attributes.respond_to?(:permitted?)
2316
+ attributes = attributes.with_indifferent_access
2317
+ if attributes["id"].blank? && attributes[slug_column].blank?
2318
+ unless reject_new_record?(association_name, attributes)
2319
+ association.reader.build(attributes.except(*::ActiveRecord::Base::UNASSIGNABLE_KEYS))
2320
+ end
2321
+ elsif (attr_id_str = attributes["id"].to_s) &&
2322
+ (existing_record = existing_records.detect { |record| record.id.to_s == attr_id_str ||
2323
+ record.send(slug_column).to_s == attr_id_str })
2324
+ unless call_reject_if(association_name, attributes)
2325
+ # Make sure we are operating on the actual object which is in the association's
2326
+ # proxy_target array (either by finding it, or adding it if not found)
2327
+ # Take into account that the proxy_target may have changed due to callbacks
2328
+ target_record = association.target.detect { |record| record.id.to_s == attr_id_str ||
2329
+ record.send(slug_column).to_s == attr_id_str }
2330
+ if target_record
2331
+ existing_record = target_record
2332
+ else
2333
+ association.add_to_target(existing_record, skip_callbacks: true)
2334
+ end
2335
+
2336
+ assign_to_or_mark_for_destruction(existing_record, attributes, options[:allow_destroy])
2337
+ end
2338
+ else
2339
+ raise_nested_attributes_record_not_found!(association_name, attributes["id"])
2340
+ end
2341
+ end
2342
+ end # anafca
2343
+ end
2344
+ end if ::ActiveRecord::QueryMethods.instance_methods.include?(:or)
2345
+ @_brick_nested_friendly_id = true
2346
+ end
2347
+ end
2348
+
2262
2349
  def _brick_get_hm_assoc_name(relation, hm_assoc, source = nil)
2263
2350
  assoc_name, needs_class = if (relation[:hm_counts][hm_assoc[:inverse_table]]&.> 1) &&
2264
2351
  hm_assoc[:alternate_name] != (source || name.underscore)
@@ -46,12 +46,12 @@ module Brick
46
46
  end
47
47
  end
48
48
  unless val_err || val.nil?
49
- if (geometry = RGeo::WKRep::WKBParser.new.parse(val.pack('c*'))).is_a?(RGeo::Cartesian::PointImpl) &&
50
- !(geometry.y == 0.0 && geometry.x == 0.0)
51
- # Create a POINT link to this style of Google maps URL: https://www.google.com/maps/place/38.7071296+-121.2810649/@38.7071296,-121.2810649,12z
52
- geometry = "<a href=\"https://www.google.com/maps/place/#{geometry.y}+#{geometry.x}/@#{geometry.y},#{geometry.x},12z\" target=\"blank\">#{geometry.to_s}</a>"
53
- end
54
- val = geometry
49
+ val = if ((geometry = RGeo::WKRep::WKBParser.new.parse(val.pack('c*'))).is_a?(RGeo::Cartesian::PointImpl) ||
50
+ geometry.is_a?(RGeo::Geos::CAPIPointImpl)) &&
51
+ !(geometry.y == 0.0 && geometry.x == 0.0)
52
+ # Create a POINT link to this style of Google maps URL: https://www.google.com/maps/place/38.7071296+-121.2810649/@38.7071296,-121.2810649,12z
53
+ "<a href=\"https://www.google.com/maps/place/#{geometry.y}+#{geometry.x}/@#{geometry.y},#{geometry.x},12z\" target=\"blank\">#{geometry.to_s}</a>"
54
+ end
55
55
  end
56
56
  val_err || val
57
57
  else
@@ -1760,14 +1760,17 @@ end
1760
1760
  <tr><td<%= ' class=\"orphan\"'.html_safe if err_msg %>><%= err_msg || '(none)' %></td></tr>
1761
1761
  <% else
1762
1762
  collection2.each do |br_#{hm_singular_name}| %>
1763
- <tr><td><%= br_descrip = if br_#{hm_singular_name}.respond_to?(descrip_cols&.first&.first&.last)
1763
+ <tr><td><%= br_descrip = if (dc = descrip_cols&.first&.first&.last) && br_#{hm_singular_name}.respond_to?(dc)
1764
1764
  br_#{hm_singular_name}.brick_descrip(
1765
1765
  descrip_cols&.first&.map { |col| br_#{hm_singular_name}.send(col.last) }
1766
1766
  )
1767
1767
  else # If the HM association has a scope, might not have picked up our SELECT detail
1768
1768
  pks = (klass = br_#{hm_singular_name}.class).primary_key
1769
- pks = [pks] unless pks.is_a?(Array)
1770
- pks.map! { |pk| br_#{hm_singular_name}.send(pk).to_s }
1769
+ pks = if pks.is_a?(Array)
1770
+ pks.map { |pk| br_#{hm_singular_name}.send(pk).to_s }
1771
+ else
1772
+ [br_#{hm_singular_name}.send(pks).to_s]
1773
+ end
1771
1774
  \"#\{klass.name} ##\{pks.join(', ')}\"
1772
1775
  end
1773
1776
  link_to(br_descrip, #{hm.first.klass._brick_index(:singular)}_path(slashify(#{obj_br_pk}))) %></td></tr>
@@ -104,7 +104,7 @@ module Brick::Rails::FormBuilder
104
104
  out << "<div id=\"_br_json_#{self.field_id(method)}\"></div>"
105
105
  else
106
106
  is_revert = false
107
- out << ::Brick::Rails.display_value(col_type, val).html_safe
107
+ out << (::Brick::Rails.display_value(col_type, val)&.html_safe || '')
108
108
  end
109
109
  end
110
110
  if is_revert
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 148
8
+ TINY = 150
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.148
4
+ version: 1.0.150
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-31 00:00:00.000000000 Z
11
+ date: 2023-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord