brick 1.0.79 → 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: eedc546e7e9693459cf228ee376650cdf53c0325e55d50ef24bbf46d421f8738
4
- data.tar.gz: c4feda4b5db8334363d05f3418dc172f0dbf408c21192222008a5b9a174ae448
3
+ metadata.gz: 17bf4590fae09ac7d48f3f607996bf6297d530a9b87f338ae4519178431bfa9c
4
+ data.tar.gz: 65c67de2f3cadad727971c31d2ce6aba476cdfb28dcfdb8f440028cd1657f3e0
5
5
  SHA512:
6
- metadata.gz: 0c9713099c057b9c9041121576a4f38d5949213926a47d597f88f4a9021ce14cd3df2a30c14b8b929b92ba4549ec4492bdfd8de13cb0a4f710e911c00eab67b6
7
- data.tar.gz: 27ca4aa6d40e165aaca5b09cf5b2ce97737b26adc8424b1d25d81b9813100679e9e06a61279c4fd8b96d750a89a4c4cb8eafbfe2d425a4d4c6868644820f297d
6
+ metadata.gz: f96ad491da932e615513d0b92b98dee2ceea3327a5938d1ae1c9f81b0cde29193a465227cf13510bbcb2306a68e72e097a02ce5f2f0f6308c00c6b5bb714fcf9
7
+ data.tar.gz: b0058bd2ba86e8d2a89276cf38061a07de63a509d65532d173079f255f73d3293b8550f902d9be00f2ff9962ba76a142691d1ce7fe28b1786de429120f3d9d31
@@ -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"
@@ -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]
@@ -1324,6 +1324,45 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1324
1324
  # go make sure we've loaded additional references (virtual foreign keys and polymorphic associations).
1325
1325
  # (This should only happen if for whatever reason the initializer file was not exactly config/initializers/brick.rb.)
1326
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
1327
1366
  end
1328
1367
  end
1329
1368
  end
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 79
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)
@@ -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,90 @@ 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
- end
595
594
 
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
600
- 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]]
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
604
604
  end
605
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
606
 
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' })
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
629
635
  end
630
636
  end
631
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.79
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-15 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