brick 1.0.183 → 1.0.185

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: 78c32d3b30786e5d03ea9cbc0decf042a808270fb7dc43809da36604d3fa8586
4
- data.tar.gz: 9735242b6967624178bc3ed2d65368f3530fe172a27e1a7554e505d4a3ba9854
3
+ metadata.gz: d930911e6903179271b74220c325ba024dfebe26f87eec06111772bfe1dd6b39
4
+ data.tar.gz: fb0767bf7e59c56dffbe1999ee86ca3cefe66040dd26387019f2d45b8776fcd3
5
5
  SHA512:
6
- metadata.gz: 7fed1dc602b5fa4420670c7cfb923870b8fefa6ae14d61ce8a72597bc29054130eb7c871de9fcfdc06af3a7fd9b7588f4ac2267b846ba92f3c49c0b233d8a640
7
- data.tar.gz: c613f387851e56aaa32256cd2d8170293323df3d8f86de200bf1c350b025b516df386ce608c4bef6c8d5905d377a354cf72dc949eda617b2188ed37c441ebbc9
6
+ metadata.gz: d03584188eaf7ba5a41b37fd80470f6eeb8c166949f4e19f1e2a9ccf958b94d0864c25f16363fbaae1980c36d8e82ec0eacf731cd5bdee97ec819a68be4b9836
7
+ data.tar.gz: 5fc2966228117b7d35e5370ff64f2f46e85e8bfa8a1a4a4df8732e91fe0e0f4c0a5050cc7b77d44217538a7bc46681a24ebd03d0fc6ff69f483f7a7861f74a38
@@ -48,10 +48,14 @@ if ::Gem::Version.new(RUBY_VERSION) >= ::Gem::Version.new('2.7')
48
48
  end
49
49
  end
50
50
 
51
- unless ActiveRecord.const_defined?(:NoDatabaseError) # Generic version of NoDatabaseError for Rails <= 4.0
51
+ unless ActiveRecord.const_defined?(:NoDatabaseError)
52
52
  require 'active_model'
53
+ require 'active_record/deprecator' if ActiveRecord.version >= Gem::Version.new('7.1.0')
53
54
  require 'active_record/errors'
54
- class ::ActiveRecord::NoDatabaseError < ::ActiveRecord::StatementInvalid
55
+ # Generic version of NoDatabaseError for Rails <= 4.0
56
+ unless ActiveRecord.const_defined?(:NoDatabaseError)
57
+ class ::ActiveRecord::NoDatabaseError < ::ActiveRecord::StatementInvalid
58
+ end
55
59
  end
56
60
  end
57
61
 
data/lib/brick/config.rb CHANGED
@@ -164,6 +164,15 @@ module Brick
164
164
  @mutex.synchronize { @additional_references = references }
165
165
  end
166
166
 
167
+ # References to disregard when auto-building migrations, models, and seeds
168
+ def defer_references_for_generation
169
+ @mutex.synchronize { @defer_references_for_generation }
170
+ end
171
+
172
+ def defer_references_for_generation=(drfg)
173
+ @mutex.synchronize { @defer_references_for_generation = drfg }
174
+ end
175
+
167
176
  # Custom columns to add to a table, minimally defined with a name and DSL string
168
177
  def custom_columns
169
178
  @mutex.synchronize { @custom_columns }
@@ -1966,7 +1966,7 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1966
1966
  def viable_models
1967
1967
  return _brick_viable_models if ::RailsAdmin::Config.class_variables.include?(:@@system_models)
1968
1968
 
1969
- brick_models = ::Brick.relations.map { |_k, v| v[:class_name] }
1969
+ brick_models = ::Brick.relations.each_with_object([]) { |rel, s| s << rel.last[:class_name] unless rel.first.is_a?(Symbol) }
1970
1970
 
1971
1971
  # The original from RailsAdmin (now aliased as _brick_viable_models) loads all classes
1972
1972
  # in the whole project. This Brick approach is a little more tame.
@@ -1999,7 +1999,7 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1999
1999
  end
2000
2000
 
2001
2001
  RailsAdmin.config do |config|
2002
- ::Brick.relations.select { |_k, v| v.key?(:isView) }.each do |_k, relation|
2002
+ ::Brick.relations.select { |_k, v| v.is_a?(Hash) && v.key?(:isView) }.each do |_k, relation|
2003
2003
  config.model(relation[:class_name]) do # new_model_class
2004
2004
  list do
2005
2005
  sort_by (sort_col = relation[:cols].first.first)
@@ -48,7 +48,9 @@ module Brick::Rails::FormBuilder
48
48
  col&.type
49
49
  end
50
50
  case (col_type ||= col&.sql_type)
51
- when :string, :text, :citext
51
+ when :string, :text, :citext,
52
+ :enum # Support for the activerecord-mysql-enum gem
53
+ spit_out_text_field = nil
52
54
  if ::Brick::Rails::FormBuilder.is_bcrypt?(val) # || .readonly?
53
55
  is_revert = false
54
56
  out << ::Brick::Rails::FormBuilder.hide_bcrypt(val, nil, 1000)
@@ -57,13 +59,20 @@ module Brick::Rails::FormBuilder
57
59
  enum_html_options = attr.kind_of?(Enumerize::Multiple) ? html_options.merge({ multiple: true, size: opts.length + 1 }) : html_options
58
60
  out << self.select(method.to_sym, [["(No #{method} chosen)", '^^^brick_NULL^^^']] + opts, { value: val || '^^^brick_NULL^^^' }, enum_html_options)
59
61
  else
60
- out << self.text_field(method.to_sym, html_options)
62
+ spit_out_text_field = true
63
+ end
64
+ elsif col_type == :enum
65
+ if col.respond_to?(:limit) && col.limit.present?
66
+ out << self.select(method.to_sym, [["(No #{method} chosen)", '^^^brick_NULL^^^']] + col.limit, { value: val.to_s || '^^^brick_NULL^^^' }, html_options)
67
+ else
68
+ spit_out_text_field = true
61
69
  end
62
70
  else
63
71
  template.instance_variable_set(:@_text_fields_present, true)
64
72
  out << self.hidden_field(method.to_sym, html_options)
65
73
  out << "<trix-editor input=\"#{self.field_id(method)}\"></trix-editor>"
66
74
  end
75
+ out << self.text_field(method.to_sym, html_options) if spit_out_text_field
67
76
  when :boolean
68
77
  out << self.check_box(method.to_sym)
69
78
  when :integer, :decimal, :float
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 183
8
+ TINY = 185
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
@@ -162,6 +162,8 @@ module Brick
162
162
  h[:db_name] = db_name if db_name
163
163
  end
164
164
  end
165
+ rescue ActiveRecord::NoDatabaseError
166
+ {}
165
167
  end
166
168
 
167
169
  def apartment_multitenant
@@ -475,6 +477,21 @@ module Brick
475
477
  end
476
478
  end
477
479
 
480
+ # References to disregard when auto-building migrations, models, and seeds
481
+ # @api public
482
+ def defer_references_for_generation=(drfg)
483
+ if drfg
484
+ drfg = [drfg] unless drfg.empty? || drfg.first.is_a?(Array)
485
+ Brick.config.defer_references_for_generation = drfg
486
+ end
487
+ end
488
+
489
+ def drfgs
490
+ (::Brick.config.defer_references_for_generation || []).each_with_object({}) do |drfg, s|
491
+ s[drfg.first] = [drfg[1..-1]]
492
+ end
493
+ end
494
+
478
495
  # Custom columns to add to a table, minimally defined with a name and DSL string.
479
496
  # @api public
480
497
  def custom_columns=(cust_cols)
@@ -1901,7 +1918,7 @@ module ActiveRecord
1901
1918
  private
1902
1919
 
1903
1920
  # %%% Pretty much have to flat-out replace this guy (I think anyway)
1904
- # Good with Rails 5.24 through 7 on this
1921
+ # Good with Rails 5.2.4 through 7.1 on this
1905
1922
  # Ransack gem includes Polyamorous which replaces #build in a different way (which we handle below)
1906
1923
  unless Gem::Specification.all_names.any? { |g| g.start_with?('ransack-') }
1907
1924
  def build(associations, base_klass, root = nil, path = '')
@@ -2026,15 +2043,17 @@ end
2026
2043
 
2027
2044
  # Keyword arguments updates for Rails <= 5.2.x and Ruby >= 3.0
2028
2045
  if ActiveRecord.version < ::Gem::Version.new('6.0') && ruby_version >= ::Gem::Version.new('3.0')
2029
- admsm = ActionDispatch::MiddlewareStack::Middleware
2030
- admsm.class_exec do
2031
- # redefine #build
2032
- def build(app, **kwargs)
2033
- if args.length > 1 && args.last.is_a?(Hash)
2034
- kwargs.merge!(args.pop)
2046
+ if Object.const_defined?('ActionDispatch')
2047
+ admsm = ActionDispatch::MiddlewareStack::Middleware
2048
+ admsm.class_exec do
2049
+ # redefine #build
2050
+ def build(app, **kwargs)
2051
+ if args.length > 1 && args.last.is_a?(Hash)
2052
+ kwargs.merge!(args.pop)
2053
+ end
2054
+ # binding.pry if klass == ActionDispatch::Static # ActionDispatch::Reloader
2055
+ klass.new(app, *args, **kwargs, &block)
2035
2056
  end
2036
- # binding.pry if klass == ActionDispatch::Static # ActionDispatch::Reloader
2037
- klass.new(app, *args, **kwargs, &block)
2038
2057
  end
2039
2058
  end
2040
2059
 
@@ -2086,16 +2105,18 @@ if ActiveRecord.version < ::Gem::Version.new('6.0') && ruby_version >= ::Gem::Ve
2086
2105
  end
2087
2106
  end
2088
2107
 
2089
- module ActionController::RequestForgeryProtection
2090
- private
2108
+ if Object.const_defined?('ActionController')
2109
+ module ActionController::RequestForgeryProtection
2110
+ private
2091
2111
 
2092
- # Creates the authenticity token for the current request.
2093
- def form_authenticity_token(*args, form_options: {}) # :doc:
2094
- if method(:masked_authenticity_token).arity == 1
2095
- masked_authenticity_token(session) # AR <= 4.2 doesn't use form_options
2096
- else
2097
- form_options.merge!(args.pop) if args.last.is_a?(Hash)
2098
- masked_authenticity_token(session, form_options: form_options)
2112
+ # Creates the authenticity token for the current request.
2113
+ def form_authenticity_token(*args, form_options: {}) # :doc:
2114
+ if method(:masked_authenticity_token).arity == 1
2115
+ masked_authenticity_token(session) # AR <= 4.2 doesn't use form_options
2116
+ else
2117
+ form_options.merge!(args.pop) if args.last.is_a?(Hash)
2118
+ masked_authenticity_token(session, form_options: form_options)
2119
+ end
2099
2120
  end
2100
2121
  end
2101
2122
  end
@@ -26,11 +26,16 @@ module Brick
26
26
  'SDO_GEOMETRY' => 'geometry',
27
27
  # MSSQL data types
28
28
  'int' => 'integer',
29
+ 'char' => 'string',
30
+ 'varchar' => 'string',
29
31
  'nvarchar' => 'string',
30
32
  'nchar' => 'string',
31
33
  'datetime2' => 'timestamp',
32
34
  'bit' => 'boolean',
33
35
  'varbinary' => 'binary',
36
+ 'tinyint' => 'integer', # %%% Need to put in "limit: 2"
37
+ 'year' => 'date',
38
+ 'set' => 'string',
34
39
  # Sqlite data types
35
40
  'TEXT' => 'text',
36
41
  '' => 'string',
@@ -111,8 +116,12 @@ module Brick
111
116
  while (fringe = chosen.reject do |tbl|
112
117
  snag_fks = []
113
118
  snags = relations.fetch(tbl, nil)&.fetch(:fks, nil)&.select do |_k, v|
114
- v[:is_bt] && !v[:polymorphic] &&
115
- tbl != v[:inverse_table] && # Ignore self-referencing associations (stuff like "parent_id")
119
+ # Skip any foreign keys which should be deferred ...
120
+ !Brick.drfgs[tbl]&.any? do |drfg|
121
+ drfg[0] == v.fetch(:fk, nil) && drfg[1] == v.fetch(:inverse_table, nil)
122
+ end &&
123
+ v[:is_bt] && !v[:polymorphic] && # ... and polymorphics ...
124
+ tbl != v[:inverse_table] && # ... and self-referencing associations (stuff like "parent_id")
116
125
  !done.include?(v[:inverse_table]) &&
117
126
  ::Brick.config.ignore_migration_fks.exclude?(snag_fk = "#{tbl}.#{v[:fk]}") &&
118
127
  snag_fks << snag_fk
@@ -66,8 +66,12 @@ module Brick
66
66
  tbl = seed_model.table_name
67
67
  snag_fks = []
68
68
  snags = ::Brick.relations.fetch(tbl, nil)&.fetch(:fks, nil)&.select do |_k, v|
69
- v[:is_bt] && !v[:polymorphic] &&
70
- tbl != v[:inverse_table] && # Ignore self-referencing associations (stuff like "parent_id")
69
+ # Skip any foreign keys which should be deferred ...
70
+ !Brick.drfgs[tbl]&.any? do |drfg|
71
+ drfg[0] == v.fetch(:fk, nil) && drfg[1] == v.fetch(:inverse_table, nil)
72
+ end &&
73
+ v[:is_bt] && !v[:polymorphic] && # ... and polymorphics ...
74
+ tbl != v[:inverse_table] && # ... and self-referencing associations (stuff like "parent_id")
71
75
  !done.any? { |done_seed_model| done_seed_model.table_name == v[:inverse_table] } &&
72
76
  ::Brick.config.ignore_migration_fks.exclude?(snag_fk = "#{tbl}.#{v[:fk]}") &&
73
77
  snag_fks << snag_fk
@@ -151,7 +155,7 @@ module Brick
151
155
  puts "\n*** Created seeds for #{done.length} models in db/seeds.rb ***"
152
156
  if (stuck_sorted = stuck_counts.to_a.sort { |a, b| b.last <=> a.last }).length.positive?
153
157
  puts "-----------------------------------------"
154
- puts "Unable to create migrations for #{stuck_sorted.length} tables#{
158
+ puts "Unable to create seeds for #{stuck_sorted.length} tables#{
155
159
  ". Here's the top 5 blockers" if stuck_sorted.length > 5
156
160
  }:"
157
161
  pp stuck_sorted[0..4]
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.183
4
+ version: 1.0.185
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-10-15 00:00:00.000000000 Z
11
+ date: 2023-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord