brick 1.0.80 → 1.0.82
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 +31 -22
- data/lib/brick/frameworks/rails/engine.rb +43 -16
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +37 -17
- data/lib/generators/brick/install_generator.rb +178 -168
- 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: 74df340edd3b41626ea7f72409064b27ae10ddfd6eb41dd66ecc6704044156bd
|
4
|
+
data.tar.gz: 82181c7ffe7a26b6ab02bfc4faaedf031d78e5e4880f6316e1ea2143da8a9655
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 644d3d343e774f8682a575c8fad849c27ee60c279e30a689874b608f056b1aee39a936ec85e91878d2200deeaf49ad78188866b6548ccf6dae43fbadbe80752a
|
7
|
+
data.tar.gz: '09f1f3383f9db0f3519215bb372a238478a0ae5176090bd2992a4f43f6e41b8aaef9f2a449573413ee886cc08cd94b868e0ec81a822b20d8dd0cc9e4eebf635e'
|
data/lib/brick/extensions.rb
CHANGED
@@ -59,6 +59,10 @@ end
|
|
59
59
|
|
60
60
|
module ActiveRecord
|
61
61
|
class Base
|
62
|
+
def self.is_brick?
|
63
|
+
instance_variables.include?(:@_brick_built) && instance_variable_get(:@_brick_built)
|
64
|
+
end
|
65
|
+
|
62
66
|
def self._assoc_names
|
63
67
|
@_assoc_names ||= {}
|
64
68
|
end
|
@@ -521,7 +525,7 @@ module ActiveRecord
|
|
521
525
|
# CUSTOM COLUMNS
|
522
526
|
# ==============
|
523
527
|
klass._br_cust_cols.each do |k, cc|
|
524
|
-
if respond_to?(k) # Name already taken?
|
528
|
+
if rel_dupe.respond_to?(k) # Name already taken?
|
525
529
|
# %%% Use ensure_unique here in this kind of fashion:
|
526
530
|
# cnstr_name = ensure_unique(+"(brick) #{for_tbl}_#{pri_tbl}", bts, hms)
|
527
531
|
# binding.pry
|
@@ -641,11 +645,13 @@ module ActiveRecord
|
|
641
645
|
[a.table_name, a.foreign_key, a.source_reflection.macro]
|
642
646
|
end
|
643
647
|
next if bail_out
|
648
|
+
|
644
649
|
# count_column is determined from the originating HMT member
|
645
650
|
if (src_ref = hm.source_reflection).nil?
|
646
651
|
puts "*** Warning: Could not determine destination model for this HMT association in model #{klass.name}:\n has_many :#{hm.name}, through: :#{hm.options[:through]}"
|
652
|
+
puts
|
647
653
|
nix << k
|
648
|
-
|
654
|
+
next
|
649
655
|
elsif src_ref.macro == :belongs_to # Traditional HMT using an associative table
|
650
656
|
"br_t#{idx}.#{hm.foreign_key}"
|
651
657
|
else # A HMT that goes HM -> HM, something like Categories -> Products -> LineItems
|
@@ -676,15 +682,15 @@ module ActiveRecord
|
|
676
682
|
pri_tbl.table_name
|
677
683
|
end
|
678
684
|
on_clause = []
|
679
|
-
if fk_col.is_a?(Array) # Composite key?
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
685
|
+
hm_selects = if fk_col.is_a?(Array) # Composite key?
|
686
|
+
fk_col.each_with_index { |fk_col_part, idx| on_clause << "#{tbl_alias}.#{fk_col_part} = #{pri_tbl_name}.#{pri_tbl.primary_key[idx]}" }
|
687
|
+
fk_col.dup
|
688
|
+
else
|
689
|
+
on_clause << "#{tbl_alias}.#{fk_col} = #{pri_tbl_name}.#{pri_tbl.primary_key}"
|
690
|
+
[fk_col]
|
691
|
+
end
|
686
692
|
if poly_type
|
687
|
-
|
693
|
+
hm_selects << poly_type
|
688
694
|
on_clause << "#{tbl_alias}.#{poly_type} = '#{name}'"
|
689
695
|
end
|
690
696
|
unless from_clause
|
@@ -696,9 +702,9 @@ module ActiveRecord
|
|
696
702
|
hm.table_name
|
697
703
|
end
|
698
704
|
end
|
699
|
-
group_bys = ::Brick.is_oracle || is_mssql ?
|
705
|
+
group_bys = ::Brick.is_oracle || is_mssql ? hm_selects : (1..hm_selects.length).to_a
|
700
706
|
join_clause = "LEFT OUTER
|
701
|
-
JOIN (SELECT #{
|
707
|
+
JOIN (SELECT #{hm_selects.map { |s| "#{'br_t0.' if from_clause}#{s}" }.join(', ')}, COUNT(#{'DISTINCT ' if hm.options[:through]}#{count_column
|
702
708
|
}) AS c_t_ FROM #{from_clause || hm_table_name} GROUP BY #{group_bys.join(', ')}) #{tbl_alias}"
|
703
709
|
joins!("#{join_clause} ON #{on_clause.join(' AND ')}")
|
704
710
|
end
|
@@ -735,8 +741,10 @@ JOIN (SELECT #{selects.map { |s| "#{'br_t0.' if from_clause}#{s}" }.join(', ')},
|
|
735
741
|
else
|
736
742
|
s << v
|
737
743
|
end
|
738
|
-
else # String stuff just comes straight through
|
744
|
+
else # String stuff (which defines a custom ORDER BY) just comes straight through
|
739
745
|
s << v
|
746
|
+
# Avoid "PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list" in Postgres
|
747
|
+
selects << v if is_distinct
|
740
748
|
end
|
741
749
|
end
|
742
750
|
order!(*final_order_by)
|
@@ -909,7 +917,7 @@ Module.class_exec do
|
|
909
917
|
# Vabc instead of VABC)
|
910
918
|
singular_class_name = ::Brick.namify(plural_class_name, :underscore).singularize.camelize
|
911
919
|
full_class_name << "::#{singular_class_name}"
|
912
|
-
if plural_class_name == '
|
920
|
+
if plural_class_name == 'BrickOpenapi' ||
|
913
921
|
(
|
914
922
|
(::Brick.config.add_status || ::Brick.config.add_orphans) &&
|
915
923
|
plural_class_name == 'BrickGem'
|
@@ -1138,6 +1146,7 @@ class Object
|
|
1138
1146
|
end # class definition
|
1139
1147
|
# Having this separate -- will this now work out better?
|
1140
1148
|
built_model.class_exec do
|
1149
|
+
@_brick_built = true
|
1141
1150
|
hmts&.each do |hmt_fk, hms|
|
1142
1151
|
hmt_fk = hmt_fk.tr('.', '_')
|
1143
1152
|
hms.each do |hm|
|
@@ -1312,13 +1321,13 @@ class Object
|
|
1312
1321
|
instance_variable_set(:@orphans, ::Brick.find_orphans(::Brick.set_db_schema(params)))
|
1313
1322
|
end
|
1314
1323
|
return [new_controller_class, code + "end # BrickGem controller\n"]
|
1315
|
-
when '
|
1316
|
-
|
1324
|
+
when 'BrickOpenapi'
|
1325
|
+
is_openapi = true
|
1317
1326
|
end
|
1318
1327
|
|
1319
1328
|
self.protect_from_forgery unless: -> { self.request.format.js? }
|
1320
1329
|
self.define_method :index do
|
1321
|
-
if (
|
1330
|
+
if (is_openapi || request.env['REQUEST_PATH'].start_with?(::Brick.api_root)) &&
|
1322
1331
|
!params&.key?('_brick_schema') &&
|
1323
1332
|
(referrer_params = request.env['HTTP_REFERER']&.split('?')&.last&.split('&')&.map { |x| x.split('=') }).present?
|
1324
1333
|
if params
|
@@ -1329,7 +1338,7 @@ class Object
|
|
1329
1338
|
end
|
1330
1339
|
::Brick.set_db_schema(params || api_params)
|
1331
1340
|
|
1332
|
-
if
|
1341
|
+
if is_openapi
|
1333
1342
|
json = { 'openapi': '3.0.1', 'info': { 'title': Rswag::Ui.config.config_object[:urls].last&.fetch(:name, 'API documentation'), 'version': ::Brick.config.api_version },
|
1334
1343
|
'servers': [
|
1335
1344
|
{ 'url': '{scheme}://{defaultHost}', 'variables': {
|
@@ -1426,7 +1435,7 @@ class Object
|
|
1426
1435
|
@_brick_erd = params['_brick_erd']&.to_i
|
1427
1436
|
end
|
1428
1437
|
|
1429
|
-
unless
|
1438
|
+
unless is_openapi
|
1430
1439
|
::Brick.set_db_schema
|
1431
1440
|
_, order_by_txt = model._brick_calculate_ordering(default_ordering(table_name, pk)) if pk
|
1432
1441
|
code << " def index\n"
|
@@ -1564,7 +1573,7 @@ class Object
|
|
1564
1573
|
private params_name
|
1565
1574
|
# Get column names for params from relations[model.table_name][:cols].keys
|
1566
1575
|
end
|
1567
|
-
end # unless
|
1576
|
+
end # unless is_openapi
|
1568
1577
|
code << "end # #{class_name}\n"
|
1569
1578
|
end # class definition
|
1570
1579
|
[built_controller, code]
|
@@ -1754,7 +1763,7 @@ module ActiveRecord::ConnectionHandling
|
|
1754
1763
|
measures = []
|
1755
1764
|
::Brick.is_oracle = true if ActiveRecord::Base.connection.adapter_name == 'OracleEnhanced'
|
1756
1765
|
case ActiveRecord::Base.connection.adapter_name
|
1757
|
-
when 'PostgreSQL', 'SQLite'
|
1766
|
+
when 'PostgreSQL', 'SQLite' # These bring back a hash for each row because the query uses column aliases
|
1758
1767
|
# schema ||= 'public' if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
1759
1768
|
ActiveRecord::Base.retrieve_schema_and_tables(sql, is_postgres, is_mssql, schema).each do |r|
|
1760
1769
|
# If Apartment gem lists the table as being associated with a non-tenanted model then use whatever it thinks
|
@@ -1785,7 +1794,7 @@ module ActiveRecord::ConnectionHandling
|
|
1785
1794
|
# puts "KEY! #{r['relation_name']}.#{col_name} #{r['key']} #{r['const']}" if r['key']
|
1786
1795
|
relation[:col_descrips][col_name] = r['column_description'] if r['column_description']
|
1787
1796
|
end
|
1788
|
-
else # MySQL2 and
|
1797
|
+
else # MySQL2, OracleEnhanced, and MSSQL act a little differently, bringing back an array for each row
|
1789
1798
|
schema_and_tables = case ActiveRecord::Base.connection.adapter_name
|
1790
1799
|
when 'OracleEnhanced'
|
1791
1800
|
sql =
|
@@ -130,15 +130,15 @@ module Brick
|
|
130
130
|
next unless @_brick_model.instance_methods.include?(through) &&
|
131
131
|
(associative = @_brick_model._br_associatives.fetch(hm.first, nil))
|
132
132
|
|
133
|
-
tbl_nm = if hm_assoc.
|
134
|
-
|
133
|
+
tbl_nm = if (source = hm_assoc.source_reflection).macro == :belongs_to
|
134
|
+
hm_assoc.through_reflection&.name # for standard HMT, which is HM -> BT
|
135
135
|
else
|
136
|
-
|
136
|
+
source.inverse_of&.name # For HM -> HM style HMT
|
137
137
|
end
|
138
138
|
# If there is no inverse available for the source belongs_to association, make one based on the class name
|
139
139
|
unless tbl_nm
|
140
140
|
tbl_nm = associative.class_name.underscore
|
141
|
-
tbl_nm.slice!(0) if tbl_nm[0] ==
|
141
|
+
tbl_nm.slice!(0) if tbl_nm[0] == '/'
|
142
142
|
tbl_nm = tbl_nm.tr('/', '_').pluralize
|
143
143
|
end
|
144
144
|
"'#{tbl_nm}.#{associative.foreign_key}'"
|
@@ -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 <<
|
193
|
-
table_options <<
|
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
|
-
<%
|
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
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
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
|
|
@@ -1312,10 +1331,18 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
|
|
1312
1331
|
prepend ::Brick::RouteSet
|
1313
1332
|
end
|
1314
1333
|
# Do the root route before the Rails Welcome one would otherwise take precedence
|
1315
|
-
|
1316
|
-
|
1317
|
-
::
|
1318
|
-
|
1334
|
+
if (route = ::Brick.config.default_route_fallback).present?
|
1335
|
+
action = "#{route}#{'#index' unless route.index('#')}"
|
1336
|
+
if ::Brick.config.path_prefix
|
1337
|
+
::Rails.application.routes.append do
|
1338
|
+
send(:namespace, ::Brick.config.path_prefix) do
|
1339
|
+
send(:root, action)
|
1340
|
+
end
|
1341
|
+
end
|
1342
|
+
elsif ::Rails.application.routes.named_routes.send(:routes)[:root].nil?
|
1343
|
+
::Rails.application.routes.append do
|
1344
|
+
send(:root, action)
|
1345
|
+
end
|
1319
1346
|
end
|
1320
1347
|
end
|
1321
1348
|
end
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -113,15 +113,15 @@ if Gem::Specification.all_names.any? { |g| g.start_with?('rails-') }
|
|
113
113
|
require 'brick/frameworks/rails'
|
114
114
|
end
|
115
115
|
module Brick
|
116
|
-
|
117
|
-
|
118
|
-
|
116
|
+
class << self
|
117
|
+
def sti_models
|
118
|
+
@sti_models ||= {}
|
119
|
+
end
|
119
120
|
|
120
|
-
|
121
|
-
|
122
|
-
|
121
|
+
def existing_stis
|
122
|
+
@existing_stis ||= Brick.config.sti_namespace_prefixes.each_with_object({}) { |snp, s| s[snp.first[2..-1]] = snp.last unless snp.first.end_with?('::') }
|
123
|
+
end
|
123
124
|
|
124
|
-
class << self
|
125
125
|
attr_accessor :default_schema, :db_schemas, :routes_done, :is_oracle, :is_eager_loading, :auto_models
|
126
126
|
|
127
127
|
def set_db_schema(params = nil)
|
@@ -203,11 +203,9 @@ module Brick
|
|
203
203
|
skip_hms = {}
|
204
204
|
hms.each do |hmt|
|
205
205
|
if (through = hmt.last.options[:through])
|
206
|
-
|
207
|
-
|
206
|
+
# ::Brick.relations[hmt.last.through_reflection.table_name]
|
207
|
+
skip_hms[through] = nil if hms[through] && model.is_brick?
|
208
208
|
# End up with a hash of HMT names pointing to join-table associations
|
209
|
-
# Last part was: hmt.last.name
|
210
|
-
# Changed up because looking for: hms[:issue_issue_duplicates]
|
211
209
|
model._br_associatives[hmt.first] = hms[through] # || hms["#{(opt = hmt.last.options)[:through].to_s.singularize}_#{opt[:source].to_s.pluralize}".to_sym]
|
212
210
|
elsif hmt.last.inverse_of.nil?
|
213
211
|
puts "SKIPPING #{hmt.last.name.inspect}"
|
@@ -612,13 +610,35 @@ In config/initializers/brick.rb appropriate entries would look something like:
|
|
612
610
|
get("/#{controller_prefix}brick_orphans", to: 'brick_gem#orphans', as: 'brick_orphans')
|
613
611
|
end
|
614
612
|
|
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
613
|
unless ::Brick.routes_done
|
614
|
+
if Object.const_defined?('Rswag::Ui')
|
615
|
+
rswag_path = ::Rails.application.routes.routes.find { |r| r.app.app == Rswag::Ui::Engine }&.instance_variable_get(:@path_formatter)&.instance_variable_get(:@parts)&.join
|
616
|
+
if (doc_endpoint = Rswag::Ui.config.config_object[:urls]&.last)
|
617
|
+
puts "Mounting OpenApi 3.0 documentation endpoint for \"#{doc_endpoint[:name]}\" on #{doc_endpoint[:url]}"
|
618
|
+
send(:get, doc_endpoint[:url], { to: 'brick_openapi#index' })
|
619
|
+
endpoint_parts = doc_endpoint[:url]&.split('/')
|
620
|
+
if rswag_path && endpoint_parts
|
621
|
+
puts "API documentation now available when navigating to: /#{endpoint_parts&.find(&:present?)}/index.html"
|
622
|
+
else
|
623
|
+
puts "In order to make documentation available you can put this into your routes.rb:"
|
624
|
+
puts " mount Rswag::Ui::Engine => '/#{endpoint_parts&.find(&:present?) || 'api-docs'}'"
|
625
|
+
end
|
626
|
+
else
|
627
|
+
sample_path = rswag_path || '/api-docs'
|
628
|
+
puts
|
629
|
+
puts "Brick: rswag-ui gem detected -- to make OpenAPI 3.0 documentation available from a path such as '#{sample_path}/v1/swagger.json',"
|
630
|
+
puts ' put code such as this in an initializer:'
|
631
|
+
puts ' Rswag::Ui.configure do |config|'
|
632
|
+
puts " config.swagger_endpoint '#{sample_path}/v1/swagger.json', 'API V1 Docs'"
|
633
|
+
puts ' end'
|
634
|
+
unless rswag_path
|
635
|
+
puts
|
636
|
+
puts ' and put this into your routes.rb:'
|
637
|
+
puts " mount Rswag::Ui::Engine => '/api-docs'"
|
638
|
+
end
|
639
|
+
end
|
640
|
+
end
|
641
|
+
|
622
642
|
::Brick.routes_done = true
|
623
643
|
puts "\n" if tables.present? || views.present?
|
624
644
|
if tables.present?
|
@@ -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,171 @@ 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
|
-
|
143
|
-
# # to
|
144
|
-
#
|
145
|
-
|
146
|
-
|
147
|
-
# #
|
148
|
-
# #
|
149
|
-
#
|
150
|
-
# Brick.
|
151
|
-
# Brick.
|
152
|
-
# Brick.
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
# #
|
157
|
-
# Brick.
|
158
|
-
|
159
|
-
#
|
160
|
-
#
|
161
|
-
|
162
|
-
|
163
|
-
#
|
164
|
-
|
165
|
-
|
166
|
-
#
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
#
|
171
|
-
|
172
|
-
# #
|
173
|
-
# Brick.
|
174
|
-
|
175
|
-
#
|
176
|
-
|
177
|
-
# #
|
178
|
-
# #
|
179
|
-
# #
|
180
|
-
#
|
181
|
-
#
|
182
|
-
#
|
183
|
-
# #
|
184
|
-
# #
|
185
|
-
# #
|
186
|
-
#
|
187
|
-
#
|
188
|
-
|
189
|
-
# #
|
190
|
-
# #
|
191
|
-
# #
|
192
|
-
#
|
193
|
-
|
194
|
-
#
|
195
|
-
|
196
|
-
# #
|
197
|
-
# #
|
198
|
-
#
|
199
|
-
#
|
200
|
-
|
201
|
-
# #
|
202
|
-
|
203
|
-
# #
|
204
|
-
# #
|
205
|
-
#
|
206
|
-
#
|
207
|
-
|
208
|
-
# #
|
209
|
-
|
210
|
-
# #
|
211
|
-
# # to be
|
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
|
-
#
|
295
|
-
#
|
296
|
-
# Brick.default_route_fallback = ''
|
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
|
+
# This defaults to \"customers#index\", and if there was also a prefix set called \"admin\" then it would instead
|
302
|
+
# go to \"admin/customers#index\".
|
303
|
+
# Brick.default_route_fallback = 'customers'
|
304
|
+
# Brick.default_route_fallback = 'orders#outstanding' # Example of a non-RESTful route
|
305
|
+
# Brick.default_route_fallback = '' # Omits setting a default route in the absence of any other
|
306
|
+
end
|
297
307
|
")
|
298
308
|
end
|
299
309
|
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.
|
4
|
+
version: 1.0.82
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|