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 +4 -4
- data/lib/brick/extensions.rb +35 -28
- data/lib/brick/frameworks/rails/engine.rb +39 -0
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +76 -70
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17bf4590fae09ac7d48f3f607996bf6297d530a9b87f338ae4519178431bfa9c
|
4
|
+
data.tar.gz: 65c67de2f3cadad727971c31d2ce6aba476cdfb28dcfdb8f440028cd1657f3e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f96ad491da932e615513d0b92b98dee2ceea3327a5938d1ae1c9f81b0cde29193a465227cf13510bbcb2306a68e72e097a02ce5f2f0f6308c00c6b5bb714fcf9
|
7
|
+
data.tar.gz: b0058bd2ba86e8d2a89276cf38061a07de63a509d65532d173079f255f73d3293b8550f902d9be00f2ff9962ba76a142691d1ce7fe28b1786de429120f3d9d31
|
data/lib/brick/extensions.rb
CHANGED
@@ -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
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/brick/version_number.rb
CHANGED
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
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
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
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
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
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
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
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
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.
|
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-
|
11
|
+
date: 2022-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|