brick 1.0.223 → 1.0.224

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: 7358b611b9073f3fafe55e9d3ac4b5d19ebba01604607f7aaf51eaa1b514ef6b
4
- data.tar.gz: 29adea32add038493e6f65ab1d426b378214861d9e2a61c0892ffee1a65e55bd
3
+ metadata.gz: 571fea9051ed0e8037ba73f0d3010f22f29b417b6def200fcf63894dced9289e
4
+ data.tar.gz: 6bace7cf19e59ca209a9b6395a7fce3324e4ca77bf13bd8a21bf7b3f0fe6604a
5
5
  SHA512:
6
- metadata.gz: c3c21da00d78d98e635c8986c939530fce1f9b18326d4c40c478cb48aa04bd52617c932eea9872f1142180de351d27936f16dd943cc955b3ad714db000800608
7
- data.tar.gz: 26ddbd8d7c7378448dadae1cf6d00dad47221fe5059012fc39c0bf6b1b4745ee9fa63f88e76888ff64e873a20d6a4322099817aaadf565a32254cf0e99911dc0
6
+ metadata.gz: 4ed1f0d0711c39d1174cf3306dd0c698ccc832478c32432eb84ce5a01a704da9fb24e9fda05d2986fe822fe21876aa34de4a0900f5cdacb1255446a74c07b2b9
7
+ data.tar.gz: 3b77a0656498452157fe25fb3c8c894acb8ee17fad51e6e203123d31d9d108fe59e8a7b1f265e4e168ab82c2d85cf461983079f7e753075d54ac6366d3e6d5e5
@@ -1658,7 +1658,7 @@ class Object
1658
1658
  end
1659
1659
  plural_class_name = ActiveSupport::Inflector.pluralize(model_name = class_name)
1660
1660
  # gsub is so that if it's namespaced then we turn the first part into what would be a schema name
1661
- singular_table_name = ::Brick.table_name_lookup[model_name] || ActiveSupport::Inflector.underscore(model_name).gsub('/', '.')
1661
+ singular_table_name = ::Brick.table_name_lookup&.fetch(model_name, nil) || ActiveSupport::Inflector.underscore(model_name).gsub('/', '.')
1662
1662
 
1663
1663
  if base_model
1664
1664
  table_name = base_model.table_name
@@ -2518,10 +2518,11 @@ class Object
2518
2518
  code << " def show\n"
2519
2519
  code << " #{find_by_name = "find_#{singular_table_name}"}\n"
2520
2520
  code << " end\n"
2521
+ find_obj = "find_#{singular_table_name}"
2521
2522
  self.define_method :show do
2522
2523
  _schema, @_is_show_schema_list = ::Brick.set_db_schema(params)
2523
2524
  _, singular_table_name = model.real_singular(params)
2524
- instance_variable_set("@#{singular_table_name}".to_sym, find_obj)
2525
+ instance_variable_set("@#{singular_table_name}".to_sym, send(find_obj))
2525
2526
  add_csp_hash("'unsafe-inline'")
2526
2527
  end
2527
2528
  end
@@ -2614,7 +2615,7 @@ class Object
2614
2615
  self.define_method :edit do
2615
2616
  _schema, @_is_show_schema_list = ::Brick.set_db_schema(params)
2616
2617
  _, singular_table_name = model.real_singular(params)
2617
- instance_variable_set("@#{singular_table_name}".to_sym, find_obj)
2618
+ instance_variable_set("@#{singular_table_name}".to_sym, send(find_obj))
2618
2619
  add_csp_hash
2619
2620
  end
2620
2621
 
@@ -2642,7 +2643,7 @@ class Object
2642
2643
  end
2643
2644
 
2644
2645
  _, singular_table_name = model.real_singular(params)
2645
- instance_variable_set("@#{singular_table_name}".to_sym, (obj = find_obj))
2646
+ instance_variable_set("@#{singular_table_name}".to_sym, (obj = send(find_obj)))
2646
2647
  upd_params = send(params_name_sym)
2647
2648
  json_overrides = ::Brick.config.json_columns&.fetch(table_name, nil)
2648
2649
  if model.respond_to?(:devise_modules)
@@ -2688,7 +2689,7 @@ class Object
2688
2689
  code << " end\n"
2689
2690
  self.define_method :destroy do
2690
2691
  ::Brick.set_db_schema(params)
2691
- if (obj = find_obj).send(:destroy)
2692
+ if (obj = send(find_obj)).send(:destroy)
2692
2693
  redirect_to send("#{model._brick_index}_path".to_sym)
2693
2694
  else
2694
2695
  redirect_to send("#{model._brick_index(:singular)}_path".to_sym, obj)
@@ -2699,11 +2700,11 @@ class Object
2699
2700
  code << "private\n" if pk.present? || is_need_params
2700
2701
 
2701
2702
  if pk.present?
2702
- code << " def find_#{singular_table_name}
2703
+ code << " def #{find_obj}
2703
2704
  id = params[:id]&.split(/[\\/,_]/)
2704
2705
  @#{singular_table_name} = #{model.name}.find(id.is_a?(Array) && id.length == 1 ? id.first : id)
2705
2706
  end\n"
2706
- self.define_method :find_obj do
2707
+ self.define_method(find_obj) do
2707
2708
  id = if pk.length == 1 # && model.columns_hash[pk.first]&.type == :string
2708
2709
  params[:id].gsub('^^sl^^', '/')
2709
2710
  else
@@ -2723,6 +2724,7 @@ class Object
2723
2724
  model.find(id_simplified)
2724
2725
  end
2725
2726
  end
2727
+ private find_obj
2726
2728
  end
2727
2729
 
2728
2730
  if is_need_params
@@ -106,6 +106,16 @@ function linkSchemas() {
106
106
  load inflections
107
107
  end
108
108
  require 'brick/join_array'
109
+
110
+ # Load it once at the start for Rails >= 7.2 ...
111
+ Module.class_exec &::Brick::ADD_CONST_MISSING if ActiveRecord.version >= Gem::Version.new('7.2.0')
112
+ # ... and also for Rails >= 5.0, whenever the app gets reloaded
113
+ if ::Rails.application.respond_to?(:reloader)
114
+ ::Rails.application.reloader.to_prepare { Module.class_exec &::Brick::ADD_CONST_MISSING }
115
+ else
116
+ Module.class_exec &::Brick::ADD_CONST_MISSING # Older Rails -- just load at the start
117
+ end
118
+
109
119
  # Now the Brick initializer since there may be important schema things configured
110
120
  if !::Brick.initializer_loaded && File.exist?(brick_initializer = ::Rails.root&.join('config/initializers/brick.rb') || '')
111
121
  ::Brick.initializer_loaded = load brick_initializer
@@ -180,12 +190,6 @@ function linkSchemas() {
180
190
  ::Brick.established_drf = "/#{::Brick.config.path_prefix}#{action[action.index('#')..-1]}"
181
191
  end
182
192
  end
183
-
184
- Module.class_exec &::Brick::ADD_CONST_MISSING # Load it once at the start ...
185
- # ... and also for Rails >= 5.0, whenever the app gets reloaded
186
- if ::Rails.application.respond_to?(:reloader)
187
- ::Rails.application.reloader.to_prepare { Module.class_exec &::Brick::ADD_CONST_MISSING }
188
- end
189
193
  end
190
194
 
191
195
  # After we're initialized and before running the rest of stuff, put our configuration in place
@@ -632,10 +636,17 @@ window.addEventListener(\"popstate\", linkSchemas);
632
636
 
633
637
  def path_keys(hm_assoc, fk_name, pk)
634
638
  pk.map!(&:to_sym)
635
- keys = if fk_name.is_a?(Array) && pk.is_a?(Array) # Composite keys?
636
- fk_name.zip(pk)
639
+ keys = if hm_assoc.macro == :has_and_belongs_to_many
640
+ # %%% Can a HABTM use composite keys?
641
+ # (If so then this should be rewritten to do a .zip() )
642
+ name_from_other_direction = hm_assoc.klass.reflect_on_all_associations.find { |a| a.join_table == hm_assoc.join_table }&.name
643
+ [["#{name_from_other_direction}.#{pk.first}", pk.first]]
637
644
  else
638
- [[fk_name, pk.length == 1 ? pk.first : pk.inspect]]
645
+ if fk_name.is_a?(Array) && pk.is_a?(Array) # Composite keys?
646
+ fk_name.zip(pk)
647
+ else
648
+ [[fk_name, pk.length == 1 ? pk.first : pk.inspect]]
649
+ end
639
650
  end
640
651
  if hm_assoc.options.key?(:as) && !(hmaar = hm_assoc.active_record).abstract_class?
641
652
  poly_type = if hmaar.column_names.include?(hmaar.inheritance_column)
@@ -689,7 +700,14 @@ window.addEventListener(\"popstate\", linkSchemas);
689
700
  skip_klass_hms = ::Brick.config.skip_index_hms[model_name] || {}
690
701
  hms_headers = hms.each_with_object([]) do |hm, s|
691
702
  hm_stuff = [(hm_assoc = hm.last),
692
- "H#{hm_assoc.macro == :has_one ? 'O' : 'M'}#{'T' if hm_assoc.options[:through]}",
703
+ "H#{case hm_assoc.macro
704
+ when :has_one
705
+ 'O'
706
+ when :has_and_belongs_to_many
707
+ 'ABTM'
708
+ else
709
+ 'M'
710
+ end}#{'T' if hm_assoc.options[:through]}",
693
711
  (assoc_name = hm.first)]
694
712
  hm_fk_name = if (through = hm_assoc.options[:through])
695
713
  next unless @_brick_model.instance_methods.include?(through) &&
@@ -76,8 +76,12 @@ module Brick::Rails::FormBuilder
76
76
  out << self.hidden_field(method.to_sym, html_options)
77
77
  out << "<trix-editor input=\"#{self.field_id(method)}\"></trix-editor>"
78
78
  end
79
- out << self.text_field(method.to_sym, html_options) if spit_out_text_field
80
- when :boolean
79
+ if spit_out_text_field
80
+ # %%% Need to update the max-width with javascript when page width is adjusted?
81
+ html_options.merge!(style: 'min-width: 154px;field-sizing: content;') # max-width: auto;
82
+ out << self.text_field(method.to_sym, html_options)
83
+ end
84
+ when :boolean
81
85
  out << self.check_box(method.to_sym)
82
86
  when :integer, :decimal, :float
83
87
  if model.respond_to?(:attribute_types) && (enum_type = model.attribute_types[method]).is_a?(ActiveRecord::Enum::EnumType)
data/lib/brick/rails.rb CHANGED
@@ -167,7 +167,7 @@ erDiagram
167
167
  %> <%= \"#\{through_name} }o--|| #\{hm_name}\".html_safe %> : \"\"
168
168
  <%= \"#{model_short_name} }o..o{ #\{hm_name} : \\\"#\{hm.first}\\\"\".html_safe %><%
169
169
  else # has_many
170
- %> <%= \"#{model_short_name} ||--o{ #\{hm_name} : \\\"#\{
170
+ %> <%= \"#{model_short_name} #\{hm.last.macro == :has_and_belongs_to_many ? '}o' : '||'}--o{ #\{hm_name} : \\\"#\{
171
171
  hm.first.to_s unless (last_hm = hm.first.to_s).downcase == hm_class.name.underscore.pluralize.tr('/', '_')
172
172
  }\\\"\".html_safe %><%
173
173
  end %>
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 223
8
+ TINY = 224
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
data/lib/brick.rb CHANGED
@@ -297,7 +297,7 @@ module Brick
297
297
  puts " due to invalid source #{a.source_reflection_name.inspect}."
298
298
  next
299
299
  end
300
- else
300
+ elsif a.macro != :has_and_belongs_to_many
301
301
  this_fks = (this_fk = a.foreign_key).is_a?(Array) ? this_fk.uniq : [this_fk.to_s]
302
302
  if !a.options.key?(:as) && a.klass.table_exists? && (this_fks - a.klass.column_names).length.positive?
303
303
  options = ", #{a.options.map { |k, v| "#{k.inspect} => #{v.inspect}" }.join(', ')}" if a.options.present?
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.223
4
+ version: 1.0.224
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-13 00:00:00.000000000 Z
11
+ date: 2024-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -257,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
257
257
  - !ruby/object:Gem::Version
258
258
  version: 1.3.6
259
259
  requirements: []
260
- rubygems_version: 3.4.19
260
+ rubygems_version: 3.1.6
261
261
  signing_key:
262
262
  specification_version: 4
263
263
  summary: Create a Rails app from data alone