brick 1.0.79 → 1.0.81

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: eedc546e7e9693459cf228ee376650cdf53c0325e55d50ef24bbf46d421f8738
4
- data.tar.gz: c4feda4b5db8334363d05f3418dc172f0dbf408c21192222008a5b9a174ae448
3
+ metadata.gz: 2627490165a63200a49afb7707882489986217bc170491e88f64eb9faf880b6b
4
+ data.tar.gz: f12adff07785ffd5c4a877f555cd7899de859f99ae9b18b84eda6f3d20ac5c15
5
5
  SHA512:
6
- metadata.gz: 0c9713099c057b9c9041121576a4f38d5949213926a47d597f88f4a9021ce14cd3df2a30c14b8b929b92ba4549ec4492bdfd8de13cb0a4f710e911c00eab67b6
7
- data.tar.gz: 27ca4aa6d40e165aaca5b09cf5b2ce97737b26adc8424b1d25d81b9813100679e9e06a61279c4fd8b96d750a89a4c4cb8eafbfe2d425a4d4c6868644820f297d
6
+ metadata.gz: f112e1bf44fc39e80bced64a2d9fb4dd16297e2c549f66d0842fb65d7f3644170fa18c3c784c59c5a93db57233a77bfa5f288dca89be1b3dec6172bb670f147b
7
+ data.tar.gz: 0c2061b9b662c00aeb85a76db20fb59962302dd8b6ab17225ded332eadf4485392e3f5e44538b8f99d525666b8a036bb2fbd53a2604bbf7f69aca3ad8400fa4d
@@ -909,7 +909,7 @@ Module.class_exec do
909
909
  # Vabc instead of VABC)
910
910
  singular_class_name = ::Brick.namify(plural_class_name, :underscore).singularize.camelize
911
911
  full_class_name << "::#{singular_class_name}"
912
- if plural_class_name == 'BrickSwagger' ||
912
+ if plural_class_name == 'BrickOpenapi' ||
913
913
  (
914
914
  (::Brick.config.add_status || ::Brick.config.add_orphans) &&
915
915
  plural_class_name == 'BrickGem'
@@ -1035,7 +1035,7 @@ class Object
1035
1035
  # puts "Warning: Class name for a model that references table \"#{matching
1036
1036
  # }\" should be \"#{ActiveSupport::Inflector.singularize(inheritable_name || model_name)}\"."
1037
1037
  # end
1038
- return
1038
+ return unless singular_table_name.singularize.blank?
1039
1039
  end
1040
1040
 
1041
1041
  full_model_name = full_name.split('::').tap { |fn| fn[-1] = model_name }.join('::')
@@ -1070,31 +1070,40 @@ class Object
1070
1070
  true
1071
1071
  end
1072
1072
  code << " def self.is_view?; true; end\n"
1073
- end
1074
1073
 
1075
- db_pks = relation[:cols]&.map(&:first)
1076
- has_pk = _brick_primary_key(relation).length.positive? && (db_pks & _brick_primary_key).sort == _brick_primary_key.sort
1077
- our_pks = relation[:pkey].values.first
1078
- # No primary key, but is there anything UNIQUE?
1079
- # (Sort so that if there are multiple UNIQUE constraints we'll pick one that uses the least number of columns.)
1080
- our_pks = relation[:ukeys].values.sort { |a, b| a.length <=> b.length }.first unless our_pks&.present?
1081
- if has_pk
1082
- code << " # Primary key: #{_brick_primary_key.join(', ')}\n" unless _brick_primary_key == ['id']
1083
- elsif our_pks&.present?
1084
- if our_pks.length > 1 && respond_to?(:'primary_keys=') # Using the composite_primary_keys gem?
1085
- new_model_class.primary_keys = our_pks
1086
- code << " self.primary_keys = #{our_pks.map(&:to_sym).inspect}\n"
1087
- else
1088
- new_model_class.primary_key = (pk_sym = our_pks.first.to_sym)
1089
- code << " self.primary_key = #{pk_sym.inspect}\n"
1074
+ new_model_class.primary_key = nil
1075
+ code << " self.primary_key = nil\n"
1076
+
1077
+ new_model_class.define_method :'readonly?' do
1078
+ true
1090
1079
  end
1091
- _brick_primary_key(relation) # Set the newly-found PK in the instance variable
1092
- elsif (possible_pk = ActiveRecord::Base.get_primary_key(base_class.name)) && relation[:cols][possible_pk]
1093
- new_model_class.primary_key = (possible_pk = possible_pk.to_sym)
1094
- code << " self.primary_key = #{possible_pk.inspect}\n"
1080
+ code << " def readonly?; true; end\n"
1095
1081
  else
1096
- code << " # Could not identify any column(s) to use as a primary key\n" unless is_view
1082
+ db_pks = relation[:cols]&.map(&:first)
1083
+ has_pk = (bpk = _brick_primary_key(relation)).present? && (db_pks & bpk).sort == bpk.sort
1084
+ our_pks = relation[:pkey].values.first
1085
+ # No primary key, but is there anything UNIQUE?
1086
+ # (Sort so that if there are multiple UNIQUE constraints we'll pick one that uses the least number of columns.)
1087
+ our_pks = relation[:ukeys].values.sort { |a, b| a.length <=> b.length }.first unless our_pks&.present?
1088
+ if has_pk
1089
+ code << " # Primary key: #{_brick_primary_key.join(', ')}\n" unless _brick_primary_key == ['id']
1090
+ elsif our_pks&.present?
1091
+ if our_pks.length > 1 && respond_to?(:'primary_keys=') # Using the composite_primary_keys gem?
1092
+ new_model_class.primary_keys = our_pks
1093
+ code << " self.primary_keys = #{our_pks.map(&:to_sym).inspect}\n"
1094
+ else
1095
+ new_model_class.primary_key = (pk_sym = our_pks.first.to_sym)
1096
+ code << " self.primary_key = #{pk_sym.inspect}\n"
1097
+ end
1098
+ _brick_primary_key(relation) # Set the newly-found PK in the instance variable
1099
+ elsif (possible_pk = ActiveRecord::Base.get_primary_key(base_class.name)) && relation[:cols][possible_pk]
1100
+ new_model_class.primary_key = (possible_pk = possible_pk.to_sym)
1101
+ code << " self.primary_key = #{possible_pk.inspect}\n"
1102
+ else
1103
+ code << " # Could not identify any column(s) to use as a primary key\n"
1104
+ end
1097
1105
  end
1106
+
1098
1107
  if (sti_col = relation.fetch(:sti_col, nil))
1099
1108
  new_model_class.send(:'inheritance_column=', sti_col)
1100
1109
  code << " self.inheritance_column = #{sti_col.inspect}\n"
@@ -1303,13 +1312,13 @@ class Object
1303
1312
  instance_variable_set(:@orphans, ::Brick.find_orphans(::Brick.set_db_schema(params)))
1304
1313
  end
1305
1314
  return [new_controller_class, code + "end # BrickGem controller\n"]
1306
- when 'BrickSwagger'
1307
- is_swagger = true
1315
+ when 'BrickOpenapi'
1316
+ is_openapi = true
1308
1317
  end
1309
1318
 
1310
1319
  self.protect_from_forgery unless: -> { self.request.format.js? }
1311
1320
  self.define_method :index do
1312
- if (is_swagger || request.env['REQUEST_PATH'].start_with?(::Brick.api_root)) &&
1321
+ if (is_openapi || request.env['REQUEST_PATH'].start_with?(::Brick.api_root)) &&
1313
1322
  !params&.key?('_brick_schema') &&
1314
1323
  (referrer_params = request.env['HTTP_REFERER']&.split('?')&.last&.split('&')&.map { |x| x.split('=') }).present?
1315
1324
  if params
@@ -1320,7 +1329,7 @@ class Object
1320
1329
  end
1321
1330
  ::Brick.set_db_schema(params || api_params)
1322
1331
 
1323
- if is_swagger
1332
+ if is_openapi
1324
1333
  json = { 'openapi': '3.0.1', 'info': { 'title': Rswag::Ui.config.config_object[:urls].last&.fetch(:name, 'API documentation'), 'version': ::Brick.config.api_version },
1325
1334
  'servers': [
1326
1335
  { 'url': '{scheme}://{defaultHost}', 'variables': {
@@ -1417,7 +1426,7 @@ class Object
1417
1426
  @_brick_erd = params['_brick_erd']&.to_i
1418
1427
  end
1419
1428
 
1420
- unless is_swagger
1429
+ unless is_openapi
1421
1430
  ::Brick.set_db_schema
1422
1431
  _, order_by_txt = model._brick_calculate_ordering(default_ordering(table_name, pk)) if pk
1423
1432
  code << " def index\n"
@@ -1555,7 +1564,7 @@ class Object
1555
1564
  private params_name
1556
1565
  # Get column names for params from relations[model.table_name][:cols].keys
1557
1566
  end
1558
- end # unless is_swagger
1567
+ end # unless is_openapi
1559
1568
  code << "end # #{class_name}\n"
1560
1569
  end # class definition
1561
1570
  [built_controller, code]
@@ -1745,7 +1754,7 @@ module ActiveRecord::ConnectionHandling
1745
1754
  measures = []
1746
1755
  ::Brick.is_oracle = true if ActiveRecord::Base.connection.adapter_name == 'OracleEnhanced'
1747
1756
  case ActiveRecord::Base.connection.adapter_name
1748
- when 'PostgreSQL', 'SQLite', 'SQLServer' # These bring back a hash for each row because the query uses column aliases
1757
+ when 'PostgreSQL', 'SQLite' # These bring back a hash for each row because the query uses column aliases
1749
1758
  # schema ||= 'public' if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
1750
1759
  ActiveRecord::Base.retrieve_schema_and_tables(sql, is_postgres, is_mssql, schema).each do |r|
1751
1760
  # If Apartment gem lists the table as being associated with a non-tenanted model then use whatever it thinks
@@ -1776,7 +1785,7 @@ module ActiveRecord::ConnectionHandling
1776
1785
  # puts "KEY! #{r['relation_name']}.#{col_name} #{r['key']} #{r['const']}" if r['key']
1777
1786
  relation[:col_descrips][col_name] = r['column_description'] if r['column_description']
1778
1787
  end
1779
- else # MySQL2 and OracleEnhanced act a little differently, bringing back an array for each row
1788
+ else # MySQL2, OracleEnhanced, and MSSQL act a little differently, bringing back an array for each row
1780
1789
  schema_and_tables = case ActiveRecord::Base.connection.adapter_name
1781
1790
  when 'OracleEnhanced'
1782
1791
  sql =
@@ -1932,7 +1941,10 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
1932
1941
  v[:schema] = schema_names.join('.') unless schema_names.empty?
1933
1942
  # %%% If more than one schema has the same table name, will need to add a schema name prefix to have uniqueness
1934
1943
  v[:resource] = rel_name.last
1935
- v[:class_name] = (schema_names + [rel_name.last.singularize]).map(&:camelize).join('::')
1944
+ if (singular = rel_name.last.singularize).blank?
1945
+ singular = rel_name.last
1946
+ end
1947
+ v[:class_name] = (schema_names + [singular]).map(&:camelize).join('::')
1936
1948
  end
1937
1949
  ::Brick.load_additional_references if initializer_loaded
1938
1950
 
@@ -2156,11 +2168,6 @@ module Brick
2156
2168
 
2157
2169
  return if is_class || ::Brick.config.exclude_hms&.any? { |exclusion| fk[1] == exclusion[0] && fk[2] == exclusion[1] && primary_table == exclusion[2] } || hms.nil?
2158
2170
 
2159
- # if fk[1].end_with?('Suppliers') && fk[4] == 'People'
2160
- # puts fk.inspect
2161
- # binding.pry
2162
- # end
2163
-
2164
2171
  if (assoc_hm = hms.fetch((hm_cnstr_name = "hm_#{cnstr_name}"), nil))
2165
2172
  if assoc_hm[:fk].is_a?(String)
2166
2173
  assoc_hm[:fk] = [assoc_hm[:fk], fk[2]] unless fk[2] == assoc_hm[:fk]
@@ -189,8 +189,8 @@ module Brick
189
189
  end.keys.sort.each_with_object(+'') do |v, s|
190
190
  s << "<option value=\"#{prefix}#{v.underscore.gsub('.', '/')}\">#{v}</option>"
191
191
  end.html_safe
192
- table_options << '<option value="brick_status">(Status)</option>'.html_safe if ::Brick.config.add_status
193
- table_options << '<option value="brick_orphans">(Orphans)</option>'.html_safe if is_orphans
192
+ table_options << "<option value=\"#{prefix}brick_status\">(Status)</option>".html_safe if ::Brick.config.add_status
193
+ table_options << "<option value=\"#{prefix}brick_orphans\">(Orphans)</option>".html_safe if is_orphans
194
194
  css = +"<style>
195
195
  h1, h3 {
196
196
  margin-bottom: 0;
@@ -603,7 +603,21 @@ if (headerTop) {
603
603
  erd_markup = if @_brick_model
604
604
  "<div id=\"mermaidErd\" class=\"mermaid\">
605
605
  erDiagram
606
- <% model_short_name = #{@_brick_model.name.split('::').last.inspect}
606
+ <% def sidelinks(shown_classes, klass)
607
+ links = []
608
+ # %%% Not yet showing these as they can get just a bit intense!
609
+ # klass.reflect_on_all_associations.select { |a| shown_classes.key?(a.klass) }.each do |assoc|
610
+ # unless shown_classes[assoc.klass].key?(klass.name)
611
+ # links << \" #\{klass.name.split('::').last} #\{assoc.macro == :belongs_to ? '}o--||' : '||--o{'} #\{assoc.klass.name.split('::').last} : \\\"\\\"\"n\"
612
+ # shown_classes[assoc.klass][klass.name] = nil
613
+ # end
614
+ # end
615
+ # shown_classes[klass] ||= {}
616
+ links.join
617
+ end
618
+
619
+ model_short_name = #{@_brick_model.name.split('::').last.inspect}
620
+ shown_classes = {}
607
621
  @_brick_bt_descrip&.each do |bt|
608
622
  bt_class = bt[1].first.first
609
623
  callbacks[bt_name = bt_class.name.split('::').last] = bt_class
@@ -613,6 +627,7 @@ erDiagram
613
627
  bt_underscored = bt[1].first.first.name.underscore.singularize
614
628
  bt.first unless bt.first.to_s == bt_underscored.split('/').last # Was: bt_underscored.tr('/', '_')
615
629
  }\\\"\".html_safe %>
630
+ <%= sidelinks(shown_classes, bt_class).html_safe %>
616
631
  <% end
617
632
  last_through = nil
618
633
  @_brick_hm_counts&.each do |hm|
@@ -627,6 +642,7 @@ erDiagram
627
642
  %><%= \"\n\"
628
643
  %><% else
629
644
  %> <%= \"#\{model_short_name} ||--o{ #\{through_name}\".html_safe %> : \"\"
645
+ <%= sidelinks(shown_classes, through_assoc.active_record).html_safe %>
630
646
  <% last_through = through
631
647
  end
632
648
  %> <%= \"#\{through_name} }o--|| #\{hm_name}\".html_safe %> : \"\"
@@ -636,6 +652,7 @@ erDiagram
636
652
  hm.first.to_s unless hm.first.to_s.downcase == hm_class.name.underscore.pluralize.tr('/', '_')
637
653
  }\\\"\".html_safe %><%
638
654
  end %>
655
+ <%= sidelinks(shown_classes, hm_class).html_safe %>
639
656
  <% end
640
657
  def dt_lookup(dt)
641
658
  { 'integer' => 'int', }[dt] || dt&.tr(' ', '_') || 'int'
@@ -989,11 +1006,13 @@ erDiagram
989
1006
  <select id=\"tbl\">#{table_options}</select>
990
1007
  <h1>Orphans<%= \" for #\{}\" if false %></h1>
991
1008
  <% @orphans.each do |o|
992
- via = \" (via #\{o[4]})\" unless \"#\{o[2].split('.').last.underscore.singularize}_id\" == o[4] %>
993
- <a href=\"/<%= o[0].split('.').last %>/<%= o[1] %>\">
994
- <%= \"#\{o[0]} #\{o[1]} refers#\{via} to non-existent #\{o[2]} #\{o[3]}#\{\" (in table \\\"#\{o[5]}\\\")\" if o[5]}\" %>
995
- </a><br>
996
- <% end %>
1009
+ if (klass = ::Brick.relations[o[0]]&.fetch(:class_name, nil)&.constantize) %>
1010
+ <%= via = \" (via #\{o[4]})\" unless \"#\{o[2].split('.').last.underscore.singularize}_id\" == o[4]
1011
+ link_to(\"#\{o[0]} #\{o[1]} refers#\{via} to non-existent #\{o[2]} #\{o[3]}#\{\" (in table \\\"#\{o[5]}\\\")\" if o[5]}\",
1012
+ send(\"#\{klass._brick_index(:singular)\}_path\".to_sym, o[1])) %>
1013
+ <br>
1014
+ <% end
1015
+ end %>
997
1016
  #{script}"
998
1017
  end
999
1018
 
@@ -1324,6 +1343,45 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1324
1343
  # go make sure we've loaded additional references (virtual foreign keys and polymorphic associations).
1325
1344
  # (This should only happen if for whatever reason the initializer file was not exactly config/initializers/brick.rb.)
1326
1345
  ::Brick.load_additional_references
1346
+
1347
+ # If the RailsAdmin gem is present, add our auto-creatable model names into its list of viable models.
1348
+ if Object.const_defined?('RailsAdmin')
1349
+ RailsAdmin::Config.class_exec do
1350
+ class << self
1351
+
1352
+ private
1353
+
1354
+ alias _brick_viable_models viable_models
1355
+ def viable_models
1356
+ return _brick_viable_models if class_variables.include?(:@@system_models)
1357
+
1358
+ @@system_models = (vm = _brick_viable_models) + (::Brick.auto_models - vm)
1359
+ end
1360
+ end
1361
+ end
1362
+
1363
+ RailsAdmin::Config::Actions::Show.class_exec do
1364
+ register_instance_option :enabled? do
1365
+ !(bindings[:object] && bindings[:object].class.is_view?)
1366
+ end
1367
+ end
1368
+
1369
+ RailsAdmin::Config::Actions::HistoryShow.class_exec do
1370
+ register_instance_option :enabled? do
1371
+ !(bindings[:object] && bindings[:object].class.is_view?)
1372
+ end
1373
+ end
1374
+
1375
+ RailsAdmin.config do |config|
1376
+ ::Brick.relations.select { |_k, v| v.key?(:isView) }.each do |_k, relation|
1377
+ config.model(relation[:class_name]) do # new_model_class
1378
+ list do
1379
+ sort_by (sort_col = relation[:cols].first.first)
1380
+ end
1381
+ end
1382
+ end
1383
+ end
1384
+ end
1327
1385
  end
1328
1386
  end
1329
1387
  end
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 79
8
+ TINY = 81
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
@@ -96,7 +96,6 @@ if ActiveRecord.version < ::Gem::Version.new('5')
96
96
  )
97
97
  end
98
98
 
99
-
100
99
  # puts ::Brick::Util._patch_require(
101
100
  # 'cucumber/cli/options.rb', '/cucumber/cli/options', # /cli/options
102
101
  # [' def extract_environment_variables',
@@ -123,7 +122,7 @@ module Brick
123
122
  end
124
123
 
125
124
  class << self
126
- attr_accessor :default_schema, :db_schemas, :routes_done, :is_oracle, :is_eager_loading
125
+ attr_accessor :default_schema, :db_schemas, :routes_done, :is_oracle, :is_eager_loading, :auto_models
127
126
 
128
127
  def set_db_schema(params = nil)
129
128
  schema = (params ? params['_brick_schema'] : ::Brick.default_schema)
@@ -540,6 +539,7 @@ In config/initializers/brick.rb appropriate entries would look something like:
540
539
 
541
540
  def display_classes(prefix, rels, max_length)
542
541
  rels.sort.each do |rel|
542
+ (::Brick.auto_models ||= []) << rel.first
543
543
  puts "#{rel.first}#{' ' * (max_length - rel.first.length)} /#{prefix}#{rel.last}"
544
544
  end
545
545
  puts "\n"
@@ -548,84 +548,112 @@ In config/initializers/brick.rb appropriate entries would look something like:
548
548
 
549
549
  module RouteSet
550
550
  def finalize!
551
- return super if ::Brick.routes_done
552
-
553
- ::Brick.routes_done = true
554
- tables = []
555
- views = []
556
- table_class_length = 38 # Length of "Classes that can be built from tables:"
557
- view_class_length = 37 # Length of "Classes that can be built from views:"
558
- existing_controllers = routes.each_with_object({}) { |r, s| c = r.defaults[:controller]; s[c] = nil if c }
559
- ::Rails.application.routes.append do
560
- brick_routes_create = lambda do |schema_name, controller_name, v, options|
561
- if schema_name # && !Object.const_defined('Apartment')
562
- send(:namespace, schema_name) do
551
+ unless ::Rails.application.routes.named_routes.route_defined?(:brick_status_path)
552
+ existing_controllers = routes.each_with_object({}) { |r, s| c = r.defaults[:controller]; s[c] = nil if c }
553
+ ::Rails.application.routes.append do
554
+ tables = []
555
+ views = []
556
+ table_class_length = 38 # Length of "Classes that can be built from tables:"
557
+ view_class_length = 37 # Length of "Classes that can be built from views:"
558
+
559
+ brick_routes_create = lambda do |schema_name, controller_name, v, options|
560
+ if schema_name # && !Object.const_defined('Apartment')
561
+ send(:namespace, schema_name) do
562
+ send(:resources, v[:resource].to_sym, **options)
563
+ end
564
+ else
563
565
  send(:resources, v[:resource].to_sym, **options)
564
566
  end
565
- else
566
- send(:resources, v[:resource].to_sym, **options)
567
567
  end
568
- end
569
568
 
570
- # %%% TODO: If no auto-controllers then enumerate the controllers folder in order to build matching routes
571
- # If auto-controllers and auto-models are both enabled then this makes sense:
572
- controller_prefix = (::Brick.config.path_prefix ? "#{::Brick.config.path_prefix}/" : '')
573
- ::Brick.relations.each do |k, v|
574
- unless !(controller_name = v.fetch(:resource, nil)&.pluralize) || existing_controllers.key?(controller_name)
575
- options = {}
576
- options[:only] = [:index, :show] if v.key?(:isView)
577
- # First do the API routes
578
- full_resource = nil
579
- if (schema_name = v.fetch(:schema, nil))
580
- full_resource = "#{schema_name}/#{v[:resource]}"
581
- send(:get, "#{::Brick.api_root}#{full_resource}", { to: "#{controller_prefix}#{schema_name}/#{controller_name}#index" }) if Object.const_defined?('Rswag::Ui')
582
- else
583
- # Normally goes to something like: /api/v1/employees
584
- send(:get, "#{::Brick.api_root}#{v[:resource]}", { to: "#{controller_prefix}#{controller_name}#index" }) if Object.const_defined?('Rswag::Ui')
585
- end
586
- # Now the normal routes
587
- if ::Brick.config.path_prefix
588
- # Was: send(:scope, path: ::Brick.config.path_prefix) do
589
- send(:namespace, ::Brick.config.path_prefix) do
569
+ # %%% TODO: If no auto-controllers then enumerate the controllers folder in order to build matching routes
570
+ # If auto-controllers and auto-models are both enabled then this makes sense:
571
+ controller_prefix = (::Brick.config.path_prefix ? "#{::Brick.config.path_prefix}/" : '')
572
+ ::Brick.relations.each do |k, v|
573
+ unless !(controller_name = v.fetch(:resource, nil)&.pluralize) || existing_controllers.key?(controller_name)
574
+ options = {}
575
+ options[:only] = [:index, :show] if v.key?(:isView)
576
+ # First do the API routes
577
+ full_resource = nil
578
+ if (schema_name = v.fetch(:schema, nil))
579
+ full_resource = "#{schema_name}/#{v[:resource]}"
580
+ send(:get, "#{::Brick.api_root}#{full_resource}", { to: "#{controller_prefix}#{schema_name}/#{controller_name}#index" }) if Object.const_defined?('Rswag::Ui')
581
+ else
582
+ # Normally goes to something like: /api/v1/employees
583
+ send(:get, "#{::Brick.api_root}#{v[:resource]}", { to: "#{controller_prefix}#{controller_name}#index" }) if Object.const_defined?('Rswag::Ui')
584
+ end
585
+ # Now the normal routes
586
+ if ::Brick.config.path_prefix
587
+ # Was: send(:scope, path: ::Brick.config.path_prefix) do
588
+ send(:namespace, ::Brick.config.path_prefix) do
589
+ brick_routes_create.call(schema_name, controller_name, v, options)
590
+ end
591
+ else
590
592
  brick_routes_create.call(schema_name, controller_name, v, options)
591
593
  end
592
- else
593
- brick_routes_create.call(schema_name, controller_name, v, options)
594
+
595
+ if (class_name = v.fetch(:class_name, nil))
596
+ if v.key?(:isView)
597
+ view_class_length = class_name.length if class_name.length > view_class_length
598
+ views
599
+ else
600
+ table_class_length = class_name.length if class_name.length > table_class_length
601
+ tables
602
+ end << [class_name, full_resource || v[:resource]]
603
+ end
594
604
  end
605
+ end
595
606
 
596
- if (class_name = v.fetch(:class_name, nil))
597
- if v.key?(:isView)
598
- view_class_length = class_name.length if class_name.length > view_class_length
599
- views
607
+ if ::Brick.config.add_status && instance_variable_get(:@set).named_routes.names.exclude?(:brick_status)
608
+ get("/#{controller_prefix}brick_status", to: 'brick_gem#status', as: 'brick_status')
609
+ end
610
+
611
+ if ::Brick.config.add_orphans && instance_variable_get(:@set).named_routes.names.exclude?(:brick_orphans)
612
+ get("/#{controller_prefix}brick_orphans", to: 'brick_gem#orphans', as: 'brick_orphans')
613
+ end
614
+
615
+ unless ::Brick.routes_done
616
+ if Object.const_defined?('Rswag::Ui')
617
+ rswag_path = ::Rails.application.routes.routes.find { |r| r.app.app == Rswag::Ui::Engine }&.instance_variable_get(:@path_formatter)&.instance_variable_get(:@parts)&.join
618
+ if (doc_endpoint = Rswag::Ui.config.config_object[:urls]&.last)
619
+ puts "Mounting OpenApi 3.0 documentation endpoint for \"#{doc_endpoint[:name]}\" on #{doc_endpoint[:url]}"
620
+ send(:get, doc_endpoint[:url], { to: 'brick_openapi#index' })
621
+ endpoint_parts = doc_endpoint[:url]&.split('/')
622
+ if rswag_path && endpoint_parts
623
+ puts "API documentation now available when navigating to: /#{endpoint_parts&.find(&:present?)}/index.html"
624
+ else
625
+ puts "In order to make documentation available you can put this into your routes.rb:"
626
+ puts " mount Rswag::Ui::Engine => '/#{endpoint_parts&.find(&:present?) || 'api-docs'}'"
627
+ end
600
628
  else
601
- table_class_length = class_name.length if class_name.length > table_class_length
602
- tables
603
- end << [class_name, full_resource || v[:resource]]
629
+ sample_path = rswag_path || '/api-docs'
630
+ puts
631
+ puts "Brick: rswag-ui gem detected -- to make OpenAPI 3.0 documentation available from a path such as '#{sample_path}/v1/swagger.json',"
632
+ puts ' put code such as this in an initializer:'
633
+ puts ' Rswag::Ui.configure do |config|'
634
+ puts " config.swagger_endpoint '#{sample_path}/v1/swagger.json', 'API V1 Docs'"
635
+ puts ' end'
636
+ unless rswag_path
637
+ puts
638
+ puts ' and put this into your routes.rb:'
639
+ puts " mount Rswag::Ui::Engine => '/api-docs'"
640
+ end
641
+ end
604
642
  end
605
- end
606
- end
607
- puts "\n" if tables.present? || views.present?
608
- if tables.present?
609
- puts "Classes that can be built from tables:#{' ' * (table_class_length - 38)} Path:"
610
- puts "======================================#{' ' * (table_class_length - 38)} ====="
611
- ::Brick.display_classes(controller_prefix, tables, table_class_length)
612
- end
613
- if views.present?
614
- puts "Classes that can be built from views:#{' ' * (view_class_length - 37)} Path:"
615
- puts "=====================================#{' ' * (view_class_length - 37)} ====="
616
- ::Brick.display_classes(controller_prefix, views, view_class_length)
617
- end
618
643
 
619
- if ::Brick.config.add_status && instance_variable_get(:@set).named_routes.names.exclude?(:brick_status)
620
- get("/#{controller_prefix}brick_status", to: 'brick_gem#status', as: 'brick_status')
621
- end
622
- if ::Brick.config.add_orphans && instance_variable_get(:@set).named_routes.names.exclude?(:brick_orphans)
623
- get("/#{controller_prefix}brick_orphans", to: 'brick_gem#orphans', as: 'brick_orphans')
624
- end
625
- if Object.const_defined?('Rswag::Ui') && doc_endpoint = Rswag::Ui.config.config_object[:urls].last
626
- # Serves JSON swagger info from a path such as '/api-docs/v1/swagger.json'
627
- puts "Mounting swagger info endpoint for \"#{doc_endpoint[:name]}\" on #{doc_endpoint[:url]}"
628
- send(:get, doc_endpoint[:url], { to: 'brick_swagger#index' })
644
+ ::Brick.routes_done = true
645
+ puts "\n" if tables.present? || views.present?
646
+ if tables.present?
647
+ puts "Classes that can be built from tables:#{' ' * (table_class_length - 38)} Path:"
648
+ puts "======================================#{' ' * (table_class_length - 38)} ====="
649
+ ::Brick.display_classes(controller_prefix, tables, table_class_length)
650
+ end
651
+ if views.present?
652
+ puts "Classes that can be built from views:#{' ' * (view_class_length - 37)} Path:"
653
+ puts "=====================================#{' ' * (view_class_length - 37)} ====="
654
+ ::Brick.display_classes(controller_prefix, views, view_class_length)
655
+ end
656
+ end
629
657
  end
630
658
  end
631
659
  super
@@ -98,40 +98,40 @@ module Brick
98
98
 
99
99
  bar = case (possible_additional_references = possible_additional_references.values.flatten).length
100
100
  when 0
101
- +"# Brick.additional_references = [['orders', 'customer_id', 'customer'],
102
- # ['customer', 'region_id', 'regions']]"
101
+ +" # Brick.additional_references = [['orders', 'customer_id', 'customer'],
102
+ # ['customer', 'region_id', 'regions']]"
103
103
  when 1
104
- +"# # Here is a possible additional reference that has been auto-identified for the #{ActiveRecord::Base.connection.current_database} database:
105
- # Brick.additional_references = [#{possible_additional_references.first}]"
104
+ +" # # Here is a possible additional reference that has been auto-identified for the #{ActiveRecord::Base.connection.current_database} database:
105
+ # Brick.additional_references = [#{possible_additional_references.first}]"
106
106
  else
107
- +"# # Here are possible additional references that have been auto-identified for the #{ActiveRecord::Base.connection.current_database} database:
108
- # Brick.additional_references = [
109
- # #{possible_additional_references.join(",\n# ")}
110
- # ]"
107
+ +" # # Here are possible additional references that have been auto-identified for the #{ActiveRecord::Base.connection.current_database} database:
108
+ # Brick.additional_references = [
109
+ # #{possible_additional_references.join(",\n # ")}
110
+ # ]"
111
111
  end
112
112
  if resembles_fks.length > 0
113
- bar << "\n# # Columns named somewhat like a foreign key which you may want to consider:
114
- # # #{resembles_fks.join(', ')}"
113
+ bar << "\n # # Columns named somewhat like a foreign key which you may want to consider:
114
+ # # #{resembles_fks.join(', ')}"
115
115
  end
116
116
 
117
117
  poly = case (possible_polymorphics = possible_polymorphics.values.flatten.map { |poss_poly| "#{poss_poly} => nil"}).length
118
118
  when 0
119
119
  " like this:
120
- # Brick.polymorphics = {
121
- # 'comments.commentable' => nil,
122
- # 'images.imageable' => nil
123
- # }"
120
+ # Brick.polymorphics = {
121
+ # 'comments.commentable' => nil,
122
+ # 'images.imageable' => nil
123
+ # }"
124
124
  when 1
125
125
  ".
126
- # # Here is a possible polymorphic association that has been auto-identified for the #{ActiveRecord::Base.connection.current_database} database:
127
- # Brick.polymorphics = { #{possible_additional_references.first} }"
126
+ # # Here is a possible polymorphic association that has been auto-identified for the #{ActiveRecord::Base.connection.current_database} database:
127
+ # Brick.polymorphics = { #{possible_additional_references.first} }"
128
128
 
129
129
  else
130
130
  ".
131
- # # Here are possible polymorphic associations that have been auto-identified for the #{ActiveRecord::Base.connection.current_database} database:
132
- # Brick.polymorphics = {
133
- # #{possible_polymorphics.join(",\n# ")}
134
- # }"
131
+ # # Here are possible polymorphic associations that have been auto-identified for the #{ActiveRecord::Base.connection.current_database} database:
132
+ # Brick.polymorphics = {
133
+ # #{possible_polymorphics.join(",\n # ")}
134
+ # }"
135
135
  end
136
136
 
137
137
  create_file(filename, "# frozen_string_literal: true
@@ -139,161 +139,169 @@ module Brick
139
139
  # # Settings for the Brick gem
140
140
  # # (By default this auto-creates models, controllers, views, and routes on-the-fly.)
141
141
 
142
- # # Custom path prefix to apply to all auto-generated Brick routes. Also causes auto-generated controllers
143
- # # to be created inside a module with the same name.
144
- # ::Brick.path_prefix = 'admin'
145
-
146
- # # Normally all are enabled in development mode, and for security reasons only models are enabled in production
147
- # # and test. This allows you to either (a) turn off models entirely, or (b) enable controllers, views, and routes
148
- # # in production.
149
- # Brick.enable_routes = true # Setting this to \"false\" will disable routes in development
150
- # Brick.enable_models = false
151
- # Brick.enable_controllers = true # Setting this to \"false\" will disable controllers in development
152
- # Brick.enable_views = true # Setting this to \"false\" will disable views in development
153
-
154
- # ::Brick.api_root = '/api/v1/' # Path from which to serve out API resources when the RSwag gem is present
155
-
156
- # # By default models are auto-created for database views, and set to be read-only. This can be skipped.
157
- # Brick.skip_database_views = true
158
-
159
- # # Any tables or views you'd like to skip when auto-creating models
160
- # Brick.exclude_tables = ['custom_metadata', 'version_info']
161
-
162
- # # Class that auto-generated models should inherit from
163
- # Brick.models_inherit_from = ApplicationRecord
164
-
165
- # # When table names have specific prefixes automatically place them in their own module with a table_name_prefix.
166
- # Brick.table_name_prefixes = { 'nav_' => 'Navigation' }
167
-
168
- # # COLUMN SEQUENCING AND INCLUSION / EXCLUSION
169
-
170
- # # By default if there is a primary key present then rows in an index view are ordered by this primary key. To
171
- # # use a different rule for doing ORDER BY, you can override this default ordering done by The Brick, for instance
172
- # # to have the rows in a contact list sorted by email:
173
- # Brick.order = { 'contacts' => { _brick_default: :email } }
174
- # # or by last name then first name:
175
- # Brick.order = { 'contacts' => { _brick_default: [:lastname, :firstname] } }
176
- # # Totally legitimate to have the default order be the name of a belongs_to or has_many association instead of an
177
- # # actual column name, in which case for has_many it just orders by the count of how many records are associated,
178
- # # and for belongs_to it's based on the primary table's DSL if any is defined (since that is what is used to
179
- # # calculate what is shown when a foreign table lists out related records). If contacts relates to addresses,
180
- # # then this is perfectly fine:
181
- # Brick.order = { 'contacts' => { _brick_default: :address } }
182
- # # You can even have a specific custom clause used in the ORDER BY. In this case it is recommended to include a
183
- # # special placeholder for the table name with the sequence \"^^^\". Here is an example of having the default
184
- # # ordering happening on the \"code\" column, and also defining custom sorting to be done, in this case proper
185
- # # ordering if that code is stored as a dotted numeric value:
186
- # Brick.order = { 'document_trees' => { _brick_default: :code,
187
- # code: \"ORDER BY STRING_TO_ARRAY(^^^.code, '.')::int[]\" } }
188
-
189
- # # Sequence of columns for each model. This also allows you to add read-only calculated columns in the same
190
- # # kind of way that they can be added in the include: portion of include/exclude columns, below.
191
- # # Designated by { <table name> => [<column name>, <column name>] }
192
- # Brick.column_sequence = { 'users' => ['email', 'profile.firstname', 'profile.lastname'] }
193
-
194
- # # Specific columns to include or exclude for each model. If there are only inclusions then only those
195
- # # columns show. If there are any exclusions then all non-excluded columns are attempted to be shown,
196
- # # which negates the usefulness of inclusions except to add calculated column detail built from DSL.
197
- # # Designated by <table name>.<column name>
198
- # Brick.column_sequence = { 'users' => { include: ['email', 'profile.firstname', 'profile.lastname'] },
199
- # 'profile' => { exclude: ['birthdate'] } }
200
-
201
- # # EXTRA FOREIGN KEYS AND OTHER HAS_MANY SETTINGS
202
-
203
- # # Additional table references which are used to create has_many / belongs_to associations inside auto-created
204
- # # models. (You can consider these to be \"virtual foreign keys\" if you wish)... You only have to add these
205
- # # in cases where your database for some reason does not have foreign key constraints defined. Sometimes for
206
- # # performance reasons or just out of sheer laziness these might be missing.
207
- # # Each of these virtual foreign keys is defined as an array having three values:
208
- # # foreign table name / foreign key column / primary table name.
209
- # # (We boldly expect that the primary key identified by ActiveRecord on the primary table will be accurate,
210
- # # usually this is \"id\" but there are some good smarts that are used in case some other column has been set
211
- # # to be the primary key.)
142
+ if Object.const_defined?('Brick')
143
+ # # Custom path prefix to apply to all auto-generated Brick routes. Also causes auto-generated controllers
144
+ # # to be created inside a module with the same name.
145
+ # ::Brick.path_prefix = 'admin'
146
+
147
+ # # Normally all are enabled in development mode, and for security reasons only models are enabled in production
148
+ # # and test. This allows you to either (a) turn off models entirely, or (b) enable controllers, views, and routes
149
+ # # in production.
150
+ # Brick.enable_routes = true # Setting this to \"false\" will disable routes in development
151
+ # Brick.enable_models = false
152
+ # Brick.enable_controllers = true # Setting this to \"false\" will disable controllers in development
153
+ # Brick.enable_views = true # Setting this to \"false\" will disable views in development
154
+
155
+ # # If The Brick sees that RSwag gem is present, it allows for API resources to be automatically served out.
156
+ # # You can configure the root path for these resources:
157
+ # ::Brick.api_root = '/api/v1/'
158
+ # # You may also want to add an OpenAPI 3.0 documentation endpoint using Rswag::Ui:
159
+ # Rswag::Ui.configure do |config|
160
+ # config.swagger_endpoint '/api-docs/v1/swagger.json', 'API V1 Docs'
161
+ # end
162
+
163
+ # # By default models are auto-created for database views, and set to be read-only. This can be skipped.
164
+ # Brick.skip_database_views = true
165
+
166
+ # # Any tables or views you'd like to skip when auto-creating models
167
+ # Brick.exclude_tables = ['custom_metadata', 'version_info']
168
+
169
+ # # Class that auto-generated models should inherit from
170
+ # Brick.models_inherit_from = ApplicationRecord
171
+
172
+ # # When table names have specific prefixes automatically place them in their own module with a table_name_prefix.
173
+ # Brick.table_name_prefixes = { 'nav_' => 'Navigation' }
174
+
175
+ # # COLUMN SEQUENCING AND INCLUSION / EXCLUSION
176
+
177
+ # # By default if there is a primary key present then rows in an index view are ordered by this primary key. To
178
+ # # use a different rule for doing ORDER BY, you can override this default ordering done by The Brick, for instance
179
+ # # to have the rows in a contact list sorted by email:
180
+ # Brick.order = { 'contacts' => { _brick_default: :email } }
181
+ # # or by last name then first name:
182
+ # Brick.order = { 'contacts' => { _brick_default: [:lastname, :firstname] } }
183
+ # # Totally legitimate to have the default order be the name of a belongs_to or has_many association instead of an
184
+ # # actual column name, in which case for has_many it just orders by the count of how many records are associated,
185
+ # # and for belongs_to it's based on the primary table's DSL if any is defined (since that is what is used to
186
+ # # calculate what is shown when a foreign table lists out related records). If contacts relates to addresses,
187
+ # # then this is perfectly fine:
188
+ # Brick.order = { 'contacts' => { _brick_default: :address } }
189
+ # # You can even have a specific custom clause used in the ORDER BY. In this case it is recommended to include a
190
+ # # special placeholder for the table name with the sequence \"^^^\". Here is an example of having the default
191
+ # # ordering happening on the \"code\" column, and also defining custom sorting to be done, in this case proper
192
+ # # ordering if that code is stored as a dotted numeric value:
193
+ # Brick.order = { 'document_trees' => { _brick_default: :code,
194
+ # code: \"ORDER BY STRING_TO_ARRAY(^^^.code, '.')::int[]\" } }
195
+
196
+ # # Sequence of columns for each model. This also allows you to add read-only calculated columns in the same
197
+ # # kind of way that they can be added in the include: portion of include/exclude columns, below.
198
+ # # Designated by { <table name> => [<column name>, <column name>] }
199
+ # Brick.column_sequence = { 'users' => ['email', 'profile.firstname', 'profile.lastname'] }
200
+
201
+ # # Specific columns to include or exclude for each model. If there are only inclusions then only those
202
+ # # columns show. If there are any exclusions then all non-excluded columns are attempted to be shown,
203
+ # # which negates the usefulness of inclusions except to add calculated column detail built from DSL.
204
+ # # Designated by <table name>.<column name>
205
+ # Brick.column_sequence = { 'users' => { include: ['email', 'profile.firstname', 'profile.lastname'] },
206
+ # 'profile' => { exclude: ['birthdate'] } }
207
+
208
+ # # EXTRA FOREIGN KEYS AND OTHER HAS_MANY SETTINGS
209
+
210
+ # # Additional table references which are used to create has_many / belongs_to associations inside auto-created
211
+ # # models. (You can consider these to be \"virtual foreign keys\" if you wish)... You only have to add these
212
+ # # in cases where your database for some reason does not have foreign key constraints defined. Sometimes for
213
+ # # performance reasons or just out of sheer laziness these might be missing.
214
+ # # Each of these virtual foreign keys is defined as an array having three values:
215
+ # # foreign table name / foreign key column / primary table name.
216
+ # # (We boldly expect that the primary key identified by ActiveRecord on the primary table will be accurate,
217
+ # # usually this is \"id\" but there are some good smarts that are used in case some other column has been set
218
+ # # to be the primary key.)
212
219
  #{bar}
213
220
 
214
- # # Custom columns to add to a table, minimally defined with a name and DSL string.
215
- # Brick.custom_columns = { 'users' => { messages: ['[COUNT(messages)] messages', 'messages'] },
216
- # 'orders' => { salesperson: '[salesperson.first] [salesperson.last]',
217
- # products: ['[COUNT(order_items.product)] products', 'order_items.product' ] }
218
- # }
219
-
220
- # # Skip creating a has_many association for these (only retain the belongs_to built from this additional_reference).
221
- # # (Uses the same exact three-part format as would define an additional_reference)
222
- # # Say for instance that we didn't care to display the favourite colours that users have:
223
- # Brick.exclude_hms = [['users', 'favourite_colour_id', 'colours']]
224
-
225
- # # Skip showing counts for these specific has_many associations when building auto-generated #index views.
226
- # # When there are related tables with a significant number of records (generally 100,000 or more), this can lessen
227
- # # the load on the database considerably, sometimes fixing what might appear to be an index page that just \"hangs\"
228
- # # for no apparent reason.
229
- # Brick.skip_index_hms = ['User.litany_of_woes']
230
-
231
- # # By default primary tables involved in a foreign key relationship will indicate a \"has_many\" relationship pointing
232
- # # back to the foreign table. In order to represent a \"has_one\" association instead, an override can be provided
233
- # # using the primary model name and the association name which you instead want to have treated as a \"has_one\":
234
- # Brick.has_ones = [['User', 'user_profile']]
235
- # # If you want to use an alternate name for the \"has_one\", such as in the case above calling the association \"profile\"
236
- # # instead of \"user_profile\", then apply that as a third parameter like this:
237
- # Brick.has_ones = [['User', 'user_profile', 'profile']]
238
-
239
- # # We normally don't show the timestamp columns \"created_at\", \"updated_at\", and \"deleted_at\", and also do
240
- # # not consider them when finding associative tables to support an N:M association. (That is, ones that can be a
241
- # # part of a has_many :through association.) If you want to use different exclusion columns than our defaults
242
- # # then this setting resets that list. For instance, here is an override that is useful in the Sakila sample
243
- # # database:
244
- # Brick.metadata_columns = ['last_update']
245
-
246
- # # Columns for which to add a validate presence: true even though the database doesn't have them marked as NOT NULL.
247
- # # Designated by <table name>.<column name>
248
- # Brick.not_nullables = ['users.name']
249
-
250
- # # FRIENDLY DSL
251
-
252
- # # A simple DSL is available to allow more user-friendly display of objects. Normally a user object might be shown
253
- # # as its first non-metadata column, or if that is not available then something like \"User #45\" where 45 is that
254
- # # object's ID. If there is no primary key then even that is not possible, so the object's .to_s method is called.
255
- # # To override these defaults and specify exactly what you want shown, such as first names and last names for a
256
- # # user, then you can use model_descrips like this, putting expressions with property references in square brackets:
257
- # Brick.model_descrips = { 'User' => '[profile.firstname] [profile.lastname]' }
258
-
259
- # # SINGLE TABLE INHERITANCE
260
-
261
- # # Specify STI subclasses either directly by name or as a general module prefix that should always relate to a specific
262
- # # parent STI class. The prefixed :: here for these examples is mandatory. Also having a suffixed :: means instead of
263
- # # a class reference, this is for a general namespace reference. So in this case requests for, say, either of the
264
- # # non-existent classes Animals::Cat or Animals::Goat (or anything else with the module prefix of \"Animals::\" would
265
- # # build a model that inherits from Animal. And a request specifically for the class Snake would build a new model
266
- # # that inherits from Reptile, and no other request would do this -- only specifically for Snake. The ending ::
267
- # # indicates that it's a module prefix instead of a specific class name.
268
- # Brick.sti_namespace_prefixes = { '::Animals::' => 'Animal',
269
- # '::Snake' => 'Reptile' }
270
-
271
- # # Custom inheritance_column to be used for STI. This is by default \"type\", and applies to all models. With this
272
- # # option you can change this either for specific models, or apply a new overall name generally:
273
- # Brick.sti_type_column = 'sti_type'
274
- # Brick.sti_type_column = { 'rails_type' => ['sales.specialoffer'] }
275
-
276
- # # POLYMORPHIC ASSOCIATIONS
277
-
278
- # # Database schema to use when analysing existing data, such as deriving a list of polymorphic classes in the case that
279
- # # it wasn't originally specified.
280
- # Brick.schema_behavior = :namespaced
281
- #{Brick.config.schema_behavior.present? ? "Brick.schema_behavior = { multitenant: { schema_to_analyse: #{
221
+ # # Custom columns to add to a table, minimally defined with a name and DSL string.
222
+ # Brick.custom_columns = { 'users' => { messages: ['[COUNT(messages)] messages', 'messages'] },
223
+ # 'orders' => { salesperson: '[salesperson.first] [salesperson.last]',
224
+ # products: ['[COUNT(order_items.product)] products', 'order_items.product' ] }
225
+ # }
226
+
227
+ # # Skip creating a has_many association for these (only retain the belongs_to built from this additional_reference).
228
+ # # (Uses the same exact three-part format as would define an additional_reference)
229
+ # # Say for instance that we didn't care to display the favourite colours that users have:
230
+ # Brick.exclude_hms = [['users', 'favourite_colour_id', 'colours']]
231
+
232
+ # # Skip showing counts for these specific has_many associations when building auto-generated #index views.
233
+ # # When there are related tables with a significant number of records (generally 100,000 or more), this can lessen
234
+ # # the load on the database considerably, sometimes fixing what might appear to be an index page that just \"hangs\"
235
+ # # for no apparent reason.
236
+ # Brick.skip_index_hms = ['User.litany_of_woes']
237
+
238
+ # # By default primary tables involved in a foreign key relationship will indicate a \"has_many\" relationship pointing
239
+ # # back to the foreign table. In order to represent a \"has_one\" association instead, an override can be provided
240
+ # # using the primary model name and the association name which you instead want to have treated as a \"has_one\":
241
+ # Brick.has_ones = [['User', 'user_profile']]
242
+ # # If you want to use an alternate name for the \"has_one\", such as in the case above calling the association \"profile\"
243
+ # # instead of \"user_profile\", then apply that as a third parameter like this:
244
+ # Brick.has_ones = [['User', 'user_profile', 'profile']]
245
+
246
+ # # We normally don't show the timestamp columns \"created_at\", \"updated_at\", and \"deleted_at\", and also do
247
+ # # not consider them when finding associative tables to support an N:M association. (That is, ones that can be a
248
+ # # part of a has_many :through association.) If you want to use different exclusion columns than our defaults
249
+ # # then this setting resets that list. For instance, here is an override that is useful in the Sakila sample
250
+ # # database:
251
+ # Brick.metadata_columns = ['last_update']
252
+
253
+ # # Columns for which to add a validate presence: true even though the database doesn't have them marked as NOT NULL.
254
+ # # Designated by <table name>.<column name>
255
+ # Brick.not_nullables = ['users.name']
256
+
257
+ # # FRIENDLY DSL
258
+
259
+ # # A simple DSL is available to allow more user-friendly display of objects. Normally a user object might be shown
260
+ # # as its first non-metadata column, or if that is not available then something like \"User #45\" where 45 is that
261
+ # # object's ID. If there is no primary key then even that is not possible, so the object's .to_s method is called.
262
+ # # To override these defaults and specify exactly what you want shown, such as first names and last names for a
263
+ # # user, then you can use model_descrips like this, putting expressions with property references in square brackets:
264
+ # Brick.model_descrips = { 'User' => '[profile.firstname] [profile.lastname]' }
265
+
266
+ # # SINGLE TABLE INHERITANCE
267
+
268
+ # # Specify STI subclasses either directly by name or as a general module prefix that should always relate to a specific
269
+ # # parent STI class. The prefixed :: here for these examples is mandatory. Also having a suffixed :: means instead of
270
+ # # a class reference, this is for a general namespace reference. So in this case requests for, say, either of the
271
+ # # non-existent classes Animals::Cat or Animals::Goat (or anything else with the module prefix of \"Animals::\" would
272
+ # # build a model that inherits from Animal. And a request specifically for the class Snake would build a new model
273
+ # # that inherits from Reptile, and no other request would do this -- only specifically for Snake. The ending ::
274
+ # # indicates that it's a module prefix instead of a specific class name.
275
+ # Brick.sti_namespace_prefixes = { '::Animals::' => 'Animal',
276
+ # '::Snake' => 'Reptile' }
277
+
278
+ # # Custom inheritance_column to be used for STI. This is by default \"type\", and applies to all models. With this
279
+ # # option you can change this either for specific models, or apply a new overall name generally:
280
+ # Brick.sti_type_column = 'sti_type'
281
+ # Brick.sti_type_column = { 'rails_type' => ['sales.specialoffer'] }
282
+
283
+ # # POLYMORPHIC ASSOCIATIONS
284
+
285
+ # # Database schema to use when analysing existing data, such as deriving a list of polymorphic classes in the case that
286
+ # # it wasn't originally specified.
287
+ # Brick.schema_behavior = :namespaced
288
+ #{Brick.config.schema_behavior.present? ? " Brick.schema_behavior = { multitenant: { schema_to_analyse: #{
282
289
  Brick.config.schema_behavior[:multitenant]&.fetch(:schema_to_analyse, nil).inspect}" :
283
- "# Brick.schema_behavior = { multitenant: { schema_to_analyse: 'engineering'"
290
+ " # Brick.schema_behavior = { multitenant: { schema_to_analyse: 'engineering'"
284
291
  } } }
285
292
 
286
- # # Polymorphic associations are set up by providing a model name and polymorphic association name#{poly}
293
+ # # Polymorphic associations are set up by providing a model name and polymorphic association name#{poly}
287
294
 
288
- # # DEFAULT ROOT ROUTE
295
+ # # DEFAULT ROOT ROUTE
289
296
 
290
- # # If a default route is not supplied, Brick attempts to find the most \"central\" table and wires up the default
291
- # # route to go to the :index action for what would be a controller for that table. You can specify any controller
292
- # # name and action you wish in order to override this and have that be the default route when none other has been
293
- # # specified in routes.rb or elsewhere. (Or just use an empty string in order to disable this behaviour.)
294
- # Brick.default_route_fallback = 'customers' # This defaults to \"customers#index\"
295
- # Brick.default_route_fallback = 'orders#outstanding' # Example of a non-RESTful route
296
- # Brick.default_route_fallback = '' # Omits setting a default route in the absence of any other
297
+ # # If a default route is not supplied, Brick attempts to find the most \"central\" table and wires up the default
298
+ # # route to go to the :index action for what would be a controller for that table. You can specify any controller
299
+ # # name and action you wish in order to override this and have that be the default route when none other has been
300
+ # # specified in routes.rb or elsewhere. (Or just use an empty string in order to disable this behaviour.)
301
+ # Brick.default_route_fallback = 'customers' # This defaults to \"customers#index\"
302
+ # Brick.default_route_fallback = 'orders#outstanding' # Example of a non-RESTful route
303
+ # Brick.default_route_fallback = '' # Omits setting a default route in the absence of any other
304
+ end
297
305
  ")
298
306
  end
299
307
  end
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.79
4
+ version: 1.0.81
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-15 00:00:00.000000000 Z
11
+ date: 2022-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord