brick 1.0.183 → 1.0.184

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: 78c32d3b30786e5d03ea9cbc0decf042a808270fb7dc43809da36604d3fa8586
4
- data.tar.gz: 9735242b6967624178bc3ed2d65368f3530fe172a27e1a7554e505d4a3ba9854
3
+ metadata.gz: 78b2c6e3f1da384e5310953f39a9bb08f85bdeabf7d2cf4143e483ad4df9f146
4
+ data.tar.gz: e3bb0fc597cfb9908a87667b6e785f41dc73337fd834151dd8ce41af8aabca02
5
5
  SHA512:
6
- metadata.gz: 7fed1dc602b5fa4420670c7cfb923870b8fefa6ae14d61ce8a72597bc29054130eb7c871de9fcfdc06af3a7fd9b7588f4ac2267b846ba92f3c49c0b233d8a640
7
- data.tar.gz: c613f387851e56aaa32256cd2d8170293323df3d8f86de200bf1c350b025b516df386ce608c4bef6c8d5905d377a354cf72dc949eda617b2188ed37c441ebbc9
6
+ metadata.gz: d1f52d74e8feca2255c86423b4108ddad31daa3b49c4f54ae0c25080542e51e1b1a812238ea6313de51c2644f67ac4ab5ad7c9759fbfb535a07e8c3134010f39
7
+ data.tar.gz: 9b21a929ef26076909595907bfda0d74b73d274bb6442d58eb80beb4b152b6aaf97ec8a8177dc0057df9188dcfde9e9540f1573c6b59ae6be62b40ac0a7541d8
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 }
@@ -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 = 184
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
@@ -475,6 +475,21 @@ module Brick
475
475
  end
476
476
  end
477
477
 
478
+ # References to disregard when auto-building migrations, models, and seeds
479
+ # @api public
480
+ def defer_references_for_generation=(drfg)
481
+ if drfg
482
+ drfg = [drfg] unless drfg.empty? || drfg.first.is_a?(Array)
483
+ Brick.config.defer_references_for_generation = drfg
484
+ end
485
+ end
486
+
487
+ def drfgs
488
+ (::Brick.config.defer_references_for_generation || []).each_with_object({}) do |drfg, s|
489
+ s[drfg.first] = [drfg[1..-1]]
490
+ end
491
+ end
492
+
478
493
  # Custom columns to add to a table, minimally defined with a name and DSL string.
479
494
  # @api public
480
495
  def custom_columns=(cust_cols)
@@ -2026,15 +2041,17 @@ end
2026
2041
 
2027
2042
  # Keyword arguments updates for Rails <= 5.2.x and Ruby >= 3.0
2028
2043
  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)
2044
+ if Object.const_defined?('ActionDispatch')
2045
+ admsm = ActionDispatch::MiddlewareStack::Middleware
2046
+ admsm.class_exec do
2047
+ # redefine #build
2048
+ def build(app, **kwargs)
2049
+ if args.length > 1 && args.last.is_a?(Hash)
2050
+ kwargs.merge!(args.pop)
2051
+ end
2052
+ # binding.pry if klass == ActionDispatch::Static # ActionDispatch::Reloader
2053
+ klass.new(app, *args, **kwargs, &block)
2035
2054
  end
2036
- # binding.pry if klass == ActionDispatch::Static # ActionDispatch::Reloader
2037
- klass.new(app, *args, **kwargs, &block)
2038
2055
  end
2039
2056
  end
2040
2057
 
@@ -2086,16 +2103,18 @@ if ActiveRecord.version < ::Gem::Version.new('6.0') && ruby_version >= ::Gem::Ve
2086
2103
  end
2087
2104
  end
2088
2105
 
2089
- module ActionController::RequestForgeryProtection
2090
- private
2106
+ if Object.const_defined?('ActionController')
2107
+ module ActionController::RequestForgeryProtection
2108
+ private
2091
2109
 
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)
2110
+ # Creates the authenticity token for the current request.
2111
+ def form_authenticity_token(*args, form_options: {}) # :doc:
2112
+ if method(:masked_authenticity_token).arity == 1
2113
+ masked_authenticity_token(session) # AR <= 4.2 doesn't use form_options
2114
+ else
2115
+ form_options.merge!(args.pop) if args.last.is_a?(Hash)
2116
+ masked_authenticity_token(session, form_options: form_options)
2117
+ end
2099
2118
  end
2100
2119
  end
2101
2120
  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.184
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-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord