brick 1.0.78 → 1.0.80

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: 52f0716e20661f909922bdcddf3401b79b87c33c7b118d1581dfdf9861dd702c
4
- data.tar.gz: 45323c512a8c7490b0ac715595ead6e6299d06a442b9c723318b90bcdce6106d
3
+ metadata.gz: 17bf4590fae09ac7d48f3f607996bf6297d530a9b87f338ae4519178431bfa9c
4
+ data.tar.gz: 65c67de2f3cadad727971c31d2ce6aba476cdfb28dcfdb8f440028cd1657f3e0
5
5
  SHA512:
6
- metadata.gz: 2ef6ac2089e1150bc9c74c6625fc3e7627f5ee06a42d1a2d5fe43790d99156abacc27ba2e042044ee42171f352718d99ae8b468ec9dca4350cd6631bead51ce7
7
- data.tar.gz: 8c4da365eb99677930a9f35f0cd5981b91adc790a13ecf55b5369da03fdf1592cccd01f911457cf204aa8769767d5a8537d856ff7080dec75543524b3e680904
6
+ metadata.gz: f96ad491da932e615513d0b92b98dee2ceea3327a5938d1ae1c9f81b0cde29193a465227cf13510bbcb2306a68e72e097a02ce5f2f0f6308c00c6b5bb714fcf9
7
+ data.tar.gz: b0058bd2ba86e8d2a89276cf38061a07de63a509d65532d173079f255f73d3293b8550f902d9be00f2ff9962ba76a142691d1ce7fe28b1786de429120f3d9d31
@@ -614,15 +614,16 @@ module ActiveRecord
614
614
  count_column = if hm.options[:through]
615
615
  # Build the chain of JOINs going to the final destination HMT table
616
616
  # (Usually just one JOIN, but could be many.)
617
- x = [hmt_assoc = hm]
617
+ hmt_assoc = hm
618
+ x = []
618
619
  x.unshift(hmt_assoc) while hmt_assoc.options[:through] && (hmt_assoc = klass.reflect_on_association(hmt_assoc.options[:through]))
619
- from_clause = +"#{x.first.klass.table_name} br_t0"
620
+ from_clause = +"#{x.first.table_name} br_t0"
620
621
  fk_col = x.shift.foreign_key
621
622
  link_back = [klass.primary_key] # %%% Inverse path back to the original object -- used to build out a link with a filter
622
623
  idx = 0
623
624
  bail_out = nil
624
- x[0..-2].map do |a|
625
- from_clause << "\n LEFT OUTER JOIN #{a.klass.table_name} br_t#{idx += 1} "
625
+ x.map do |a|
626
+ from_clause << "\n LEFT OUTER JOIN #{a.table_name} br_t#{idx += 1} "
626
627
  from_clause << if (src_ref = a.source_reflection).macro == :belongs_to
627
628
  "ON br_t#{idx}.id = br_t#{idx - 1}.#{a.foreign_key}"
628
629
  elsif src_ref.options[:as]
@@ -637,18 +638,22 @@ module ActiveRecord
637
638
  "ON br_t#{idx}.#{a.foreign_key} = br_t#{idx - 1}.id"
638
639
  end
639
640
  link_back.unshift(a.source_reflection.name)
640
- [a.klass.table_name, a.foreign_key, a.source_reflection.macro]
641
+ [a.table_name, a.foreign_key, a.source_reflection.macro]
641
642
  end
642
643
  next if bail_out
643
- # count_column is determined from the last HMT member
644
- if (src_ref = x.last.source_reflection).macro == :belongs_to # Traditional HMT using an associative table
645
- "br_t#{idx}.#{x.last.foreign_key}"
644
+ # count_column is determined from the originating HMT member
645
+ if (src_ref = hm.source_reflection).nil?
646
+ puts "*** Warning: Could not determine destination model for this HMT association in model #{klass.name}:\n has_many :#{hm.name}, through: :#{hm.options[:through]}"
647
+ nix << k
648
+ bail_out = true
649
+ elsif src_ref.macro == :belongs_to # Traditional HMT using an associative table
650
+ "br_t#{idx}.#{hm.foreign_key}"
646
651
  else # A HMT that goes HM -> HM, something like Categories -> Products -> LineItems
647
652
  "br_t#{idx}.#{src_ref.active_record.primary_key}"
648
653
  end
649
654
  else
650
- fk_col = hm.foreign_key
651
- poly_type = hm.inverse_of.foreign_type if hm.options.key?(:as)
655
+ fk_col = (inv = hm.inverse_of)&.foreign_key || hm.foreign_key
656
+ poly_type = inv.foreign_type if hm.options.key?(:as)
652
657
  pk = hm.klass.primary_key
653
658
  (pk.is_a?(Array) ? pk.first : pk) || '*'
654
659
  end
@@ -684,11 +689,11 @@ module ActiveRecord
684
689
  end
685
690
  unless from_clause
686
691
  hm_table_name = if is_mysql
687
- "`#{hm.klass.table_name}`"
692
+ "`#{hm.table_name}`"
688
693
  elsif is_postgres || is_mssql
689
- "\"#{(hm.klass.table_name).gsub('.', '"."')}\""
694
+ "\"#{(hm.table_name).gsub('.', '"."')}\""
690
695
  else
691
- hm.klass.table_name
696
+ hm.table_name
692
697
  end
693
698
  end
694
699
  group_bys = ::Brick.is_oracle || is_mssql ? selects : (1..selects.length).to_a
@@ -1030,7 +1035,7 @@ class Object
1030
1035
  # puts "Warning: Class name for a model that references table \"#{matching
1031
1036
  # }\" should be \"#{ActiveSupport::Inflector.singularize(inheritable_name || model_name)}\"."
1032
1037
  # end
1033
- return
1038
+ return unless singular_table_name.singularize.blank?
1034
1039
  end
1035
1040
 
1036
1041
  full_model_name = full_name.split('::').tap { |fn| fn[-1] = model_name }.join('::')
@@ -1065,31 +1070,40 @@ class Object
1065
1070
  true
1066
1071
  end
1067
1072
  code << " def self.is_view?; true; end\n"
1068
- end
1069
1073
 
1070
- db_pks = relation[:cols]&.map(&:first)
1071
- has_pk = _brick_primary_key(relation).length.positive? && (db_pks & _brick_primary_key).sort == _brick_primary_key.sort
1072
- our_pks = relation[:pkey].values.first
1073
- # No primary key, but is there anything UNIQUE?
1074
- # (Sort so that if there are multiple UNIQUE constraints we'll pick one that uses the least number of columns.)
1075
- our_pks = relation[:ukeys].values.sort { |a, b| a.length <=> b.length }.first unless our_pks&.present?
1076
- if has_pk
1077
- code << " # Primary key: #{_brick_primary_key.join(', ')}\n" unless _brick_primary_key == ['id']
1078
- elsif our_pks&.present?
1079
- if our_pks.length > 1 && respond_to?(:'primary_keys=') # Using the composite_primary_keys gem?
1080
- new_model_class.primary_keys = our_pks
1081
- code << " self.primary_keys = #{our_pks.map(&:to_sym).inspect}\n"
1082
- else
1083
- new_model_class.primary_key = (pk_sym = our_pks.first.to_sym)
1084
- 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
1085
1079
  end
1086
- _brick_primary_key(relation) # Set the newly-found PK in the instance variable
1087
- elsif (possible_pk = ActiveRecord::Base.get_primary_key(base_class.name)) && relation[:cols][possible_pk]
1088
- new_model_class.primary_key = (possible_pk = possible_pk.to_sym)
1089
- code << " self.primary_key = #{possible_pk.inspect}\n"
1080
+ code << " def readonly?; true; end\n"
1090
1081
  else
1091
- 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
1092
1105
  end
1106
+
1093
1107
  if (sti_col = relation.fetch(:sti_col, nil))
1094
1108
  new_model_class.send(:'inheritance_column=', sti_col)
1095
1109
  code << " self.inheritance_column = #{sti_col.inspect}\n"
@@ -1383,7 +1397,7 @@ class Object
1383
1397
  ordering = params['_brick_order']&.split(',')&.map(&:to_sym) || Object.send(:default_ordering, table_name, pk)
1384
1398
  order_by, _ = model._brick_calculate_ordering(ordering, true) # Don't do the txt part
1385
1399
 
1386
- @_brick_params = (ar_relation = model.all).brick_select(params, (selects = []), nil,
1400
+ @_brick_params = (ar_relation = model.all).brick_select(params, (selects = []), order_by,
1387
1401
  translations = {},
1388
1402
  join_array = ::Brick::JoinArray.new)
1389
1403
  # %%% Add custom HM count columns
@@ -1658,7 +1672,10 @@ module ActiveRecord::ConnectionHandling
1658
1672
  # .default_schema are specified then we can work with non-tenanted models more appropriately
1659
1673
  if (apartment = Object.const_defined?('Apartment')) &&
1660
1674
  File.exist?(apartment_initializer = ::Rails.root.join('config/initializers/apartment.rb'))
1661
- load apartment_initializer
1675
+ unless @_apartment_loaded
1676
+ load apartment_initializer
1677
+ @_apartment_loaded = true
1678
+ end
1662
1679
  apartment_excluded = Apartment.excluded_models
1663
1680
  end
1664
1681
  # Only for Postgres (Doesn't work in sqlite3 or MySQL)
@@ -1924,7 +1941,10 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
1924
1941
  v[:schema] = schema_names.join('.') unless schema_names.empty?
1925
1942
  # %%% If more than one schema has the same table name, will need to add a schema name prefix to have uniqueness
1926
1943
  v[:resource] = rel_name.last
1927
- 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('::')
1928
1948
  end
1929
1949
  ::Brick.load_additional_references if initializer_loaded
1930
1950
 
@@ -2148,11 +2168,6 @@ module Brick
2148
2168
 
2149
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?
2150
2170
 
2151
- # if fk[1].end_with?('Suppliers') && fk[4] == 'People'
2152
- # puts fk.inspect
2153
- # binding.pry
2154
- # end
2155
-
2156
2171
  if (assoc_hm = hms.fetch((hm_cnstr_name = "hm_#{cnstr_name}"), nil))
2157
2172
  if assoc_hm[:fk].is_a?(String)
2158
2173
  assoc_hm[:fk] = [assoc_hm[:fk], fk[2]] unless fk[2] == assoc_hm[:fk]
@@ -813,6 +813,24 @@ erDiagram
813
813
  hms_keys << (assoc_name = (assoc = hm.first).name.to_s)
814
814
  "#{assoc_name.inspect} => [#{(assoc.options[:through] && !assoc.through_reflection).inspect}, #{assoc.klass.name}, #{hm[1].inspect}, #{hm[2].inspect}]"
815
815
  end.join(', ')}}
816
+ # If the resource is missing, has the user simply created an inappropriately pluralised name for a table?
817
+ @#{table_name} ||= if dym_list = instance_variables.reject do |entry|
818
+ entry.to_s.start_with?('@_') ||
819
+ ['@cache_hit', '@marked_for_same_origin_verification', '@view_renderer', '@view_flow', '@output_buffer', '@virtual_path'].include?(entry.to_s)
820
+ end
821
+ msg = \"Can't find resource \\\"#{table_name}\\\".\"
822
+ # Can't be sure otherwise of what is up, so check DidYouMean and offer a suggestion.
823
+ if (dym = DidYouMean::SpellChecker.new(dictionary: dym_list).correct('@#{table_name}')).present?
824
+ msg << \"\nIf you meant \\\"#\{found_dym = dym.first[1..-1]}\\\" then to avoid this message add this entry into inflections.rb:\n\"
825
+ msg << \" inflect.singular('#\{found_dym}', '#{obj_name}')\"
826
+ puts
827
+ puts \"WARNING: #\{msg}\"
828
+ puts
829
+ @#{table_name} = instance_variable_get(dym.first.to_sym)
830
+ else
831
+ raise ActiveRecord::RecordNotFound.new(msg)
832
+ end
833
+ end
816
834
  col_keys = @#{table_name}.columns.each_with_object([]) do |col, s|
817
835
  col_name = col.name
818
836
  next if @_brick_incl&.exclude?(col_name) ||
@@ -1306,6 +1324,45 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1306
1324
  # go make sure we've loaded additional references (virtual foreign keys and polymorphic associations).
1307
1325
  # (This should only happen if for whatever reason the initializer file was not exactly config/initializers/brick.rb.)
1308
1326
  ::Brick.load_additional_references
1327
+
1328
+ # If the RailsAdmin gem is present, add our auto-creatable model names into its list of viable models.
1329
+ if Object.const_defined?('RailsAdmin')
1330
+ RailsAdmin::Config.class_exec do
1331
+ class << self
1332
+
1333
+ private
1334
+
1335
+ alias _brick_viable_models viable_models
1336
+ def viable_models
1337
+ return _brick_viable_models if class_variables.include?(:@@system_models)
1338
+
1339
+ @@system_models = (vm = _brick_viable_models) + (::Brick.auto_models - vm)
1340
+ end
1341
+ end
1342
+ end
1343
+
1344
+ RailsAdmin::Config::Actions::Show.class_exec do
1345
+ register_instance_option :enabled? do
1346
+ !(bindings[:object] && bindings[:object].class.is_view?)
1347
+ end
1348
+ end
1349
+
1350
+ RailsAdmin::Config::Actions::HistoryShow.class_exec do
1351
+ register_instance_option :enabled? do
1352
+ !(bindings[:object] && bindings[:object].class.is_view?)
1353
+ end
1354
+ end
1355
+
1356
+ RailsAdmin.config do |config|
1357
+ ::Brick.relations.select { |_k, v| v.key?(:isView) }.each do |_k, relation|
1358
+ config.model(relation[:class_name]) do # new_model_class
1359
+ list do
1360
+ sort_by (sort_col = relation[:cols].first.first)
1361
+ end
1362
+ end
1363
+ end
1364
+ end
1365
+ end
1309
1366
  end
1310
1367
  end
1311
1368
  end
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 78
8
+ TINY = 80
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)
@@ -179,13 +178,21 @@ module Brick
179
178
 
180
179
  case a.macro
181
180
  when :belongs_to
182
- s.first[a.foreign_key] = if a.polymorphic?
183
- primary_tables = relations[model.table_name][:fks].find { |_k, fk| fk[:assoc_name] == a.name.to_s }&.last&.fetch(:inverse_table, [])
184
- models = primary_tables&.map { |table| table.singularize.camelize.constantize }
185
- [a.name, models, true]
186
- else
187
- [a.name, a.klass]
188
- end
181
+ if a.polymorphic?
182
+ rel_poly_bt = relations[model.table_name][:fks].find { |_k, fk| fk[:assoc_name] == a.name.to_s }
183
+ if (primary_tables = rel_poly_bt&.last&.fetch(:inverse_table, [])).is_a?(Array)
184
+ models = primary_tables&.map { |table| table.singularize.camelize.constantize }
185
+ s.first[a.foreign_key] = [a.name, models, true]
186
+ else
187
+ # This will come up when using Devise invitable when invited_by_class_name is not
188
+ # specified because in that circumstance it adds a polymorphic :invited_by association,
189
+ # along with appropriate invited_by_type and invited_by_id columns.
190
+ puts "Missing any real indication as to which models \"has_many\" this polymorphic BT in model #{a.active_record.name}:"
191
+ puts " belongs_to :#{a.name}, polymorphic: true"
192
+ end
193
+ else
194
+ s.first[a.foreign_key] = [a.name, a.klass]
195
+ end
189
196
  when :has_many, :has_one # This gets has_many as well as has_many :through
190
197
  # %%% weed out ones that don't have an available model to reference
191
198
  s.last[a.name] = a
@@ -532,6 +539,7 @@ In config/initializers/brick.rb appropriate entries would look something like:
532
539
 
533
540
  def display_classes(prefix, rels, max_length)
534
541
  rels.sort.each do |rel|
542
+ (::Brick.auto_models ||= []) << rel.first
535
543
  puts "#{rel.first}#{' ' * (max_length - rel.first.length)} /#{prefix}#{rel.last}"
536
544
  end
537
545
  puts "\n"
@@ -540,84 +548,90 @@ In config/initializers/brick.rb appropriate entries would look something like:
540
548
 
541
549
  module RouteSet
542
550
  def finalize!
543
- return super if ::Brick.routes_done
544
-
545
- ::Brick.routes_done = true
546
- tables = []
547
- views = []
548
- table_class_length = 38 # Length of "Classes that can be built from tables:"
549
- view_class_length = 37 # Length of "Classes that can be built from views:"
550
- existing_controllers = routes.each_with_object({}) { |r, s| c = r.defaults[:controller]; s[c] = nil if c }
551
- ::Rails.application.routes.append do
552
- brick_routes_create = lambda do |schema_name, controller_name, v, options|
553
- if schema_name # && !Object.const_defined('Apartment')
554
- 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
555
565
  send(:resources, v[:resource].to_sym, **options)
556
566
  end
557
- else
558
- send(:resources, v[:resource].to_sym, **options)
559
567
  end
560
- end
561
568
 
562
- # %%% TODO: If no auto-controllers then enumerate the controllers folder in order to build matching routes
563
- # If auto-controllers and auto-models are both enabled then this makes sense:
564
- controller_prefix = (::Brick.config.path_prefix ? "#{::Brick.config.path_prefix}/" : '')
565
- ::Brick.relations.each do |k, v|
566
- unless !(controller_name = v.fetch(:resource, nil)&.pluralize) || existing_controllers.key?(controller_name)
567
- options = {}
568
- options[:only] = [:index, :show] if v.key?(:isView)
569
- # First do the API routes
570
- full_resource = nil
571
- if (schema_name = v.fetch(:schema, nil))
572
- full_resource = "#{schema_name}/#{v[:resource]}"
573
- send(:get, "#{::Brick.api_root}#{full_resource}", { to: "#{controller_prefix}#{schema_name}/#{controller_name}#index" }) if Object.const_defined?('Rswag::Ui')
574
- else
575
- # Normally goes to something like: /api/v1/employees
576
- send(:get, "#{::Brick.api_root}#{v[:resource]}", { to: "#{controller_prefix}#{controller_name}#index" }) if Object.const_defined?('Rswag::Ui')
577
- end
578
- # Now the normal routes
579
- if ::Brick.config.path_prefix
580
- # Was: send(:scope, path: ::Brick.config.path_prefix) do
581
- 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
582
592
  brick_routes_create.call(schema_name, controller_name, v, options)
583
593
  end
584
- else
585
- brick_routes_create.call(schema_name, controller_name, v, options)
586
- end
587
594
 
588
- if (class_name = v.fetch(:class_name, nil))
589
- if v.key?(:isView)
590
- view_class_length = class_name.length if class_name.length > view_class_length
591
- views
592
- else
593
- table_class_length = class_name.length if class_name.length > table_class_length
594
- tables
595
- end << [class_name, full_resource || v[:resource]]
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
596
604
  end
597
605
  end
598
- end
599
- puts "\n" if tables.present? || views.present?
600
- if tables.present?
601
- puts "Classes that can be built from tables:#{' ' * (table_class_length - 38)} Path:"
602
- puts "======================================#{' ' * (table_class_length - 38)} ====="
603
- ::Brick.display_classes(controller_prefix, tables, table_class_length)
604
- end
605
- if views.present?
606
- puts "Classes that can be built from views:#{' ' * (view_class_length - 37)} Path:"
607
- puts "=====================================#{' ' * (view_class_length - 37)} ====="
608
- ::Brick.display_classes(controller_prefix, views, view_class_length)
609
- end
610
606
 
611
- if ::Brick.config.add_status && instance_variable_get(:@set).named_routes.names.exclude?(:brick_status)
612
- get("/#{controller_prefix}brick_status", to: 'brick_gem#status', as: 'brick_status')
613
- end
614
- if ::Brick.config.add_orphans && instance_variable_get(:@set).named_routes.names.exclude?(:brick_orphans)
615
- get("/#{controller_prefix}brick_orphans", to: 'brick_gem#orphans', as: 'brick_orphans')
616
- end
617
- if Object.const_defined?('Rswag::Ui') && doc_endpoint = Rswag::Ui.config.config_object[:urls].last
618
- # Serves JSON swagger info from a path such as '/api-docs/v1/swagger.json'
619
- puts "Mounting swagger info endpoint for \"#{doc_endpoint[:name]}\" on #{doc_endpoint[:url]}"
620
- send(:get, doc_endpoint[:url], { to: 'brick_swagger#index' })
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
+ if Object.const_defined?('Rswag::Ui') && doc_endpoint = Rswag::Ui.config.config_object[:urls].last
616
+ # Serves JSON swagger info from a path such as '/api-docs/v1/swagger.json'
617
+ puts "Mounting swagger info endpoint for \"#{doc_endpoint[:name]}\" on #{doc_endpoint[:url]}"
618
+ send(:get, doc_endpoint[:url], { to: 'brick_swagger#index' })
619
+ end
620
+
621
+ unless ::Brick.routes_done
622
+ ::Brick.routes_done = true
623
+ puts "\n" if tables.present? || views.present?
624
+ if tables.present?
625
+ puts "Classes that can be built from tables:#{' ' * (table_class_length - 38)} Path:"
626
+ puts "======================================#{' ' * (table_class_length - 38)} ====="
627
+ ::Brick.display_classes(controller_prefix, tables, table_class_length)
628
+ end
629
+ if views.present?
630
+ puts "Classes that can be built from views:#{' ' * (view_class_length - 37)} Path:"
631
+ puts "=====================================#{' ' * (view_class_length - 37)} ====="
632
+ ::Brick.display_classes(controller_prefix, views, view_class_length)
633
+ end
634
+ end
621
635
  end
622
636
  end
623
637
  super
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.78
4
+ version: 1.0.80
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-14 00:00:00.000000000 Z
11
+ date: 2022-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord