brick 1.0.73 → 1.0.74
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brick/extensions.rb +18 -46
- data/lib/brick/frameworks/rails/engine.rb +1 -1
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +50 -19
- data/lib/generators/brick/install_generator.rb +1 -1
- 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: a7f077a36e2fd62546cdebfde2b9651807ceeaad9571008460423d9e994df44d
|
4
|
+
data.tar.gz: 368ca31e726fa377325b7ff7838e38cd6b79aa222bcec73cdd6cebc645908d28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4154837ca3926cb1cd8d4803d62a789f1aa6449625560c63c06708508543e218765288d13a763aab238ea946dfdc33391454793b02805a8cdf46f729cf436da
|
7
|
+
data.tar.gz: 599cd989ef47a99cb0b6b4cb1a1c53da892d5758ccd208ecb4bf1383a2f29c1bc4600458c4de357e5496f90f664984c10634f469a40f80bcc89a9e5592735899
|
data/lib/brick/extensions.rb
CHANGED
@@ -1141,16 +1141,18 @@ class Object
|
|
1141
1141
|
|
1142
1142
|
self.protect_from_forgery unless: -> { self.request.format.js? }
|
1143
1143
|
self.define_method :index do
|
1144
|
-
if is_swagger
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
end
|
1144
|
+
if (is_swagger || request.env['REQUEST_PATH'].start_with?(::Brick.api_root)) &&
|
1145
|
+
!params&.key?('_brick_schema') &&
|
1146
|
+
(referrer_params = request.env['HTTP_REFERER']&.split('?')&.last&.split('&')&.map { |x| x.split('=') }).present?
|
1147
|
+
if params
|
1148
|
+
referrer_params.each { |k, v| params.send(:parameters)[k] = v }
|
1149
|
+
else
|
1150
|
+
api_params = referrer_params&.to_h
|
1152
1151
|
end
|
1153
|
-
|
1152
|
+
end
|
1153
|
+
::Brick.set_db_schema(params || api_params)
|
1154
|
+
|
1155
|
+
if is_swagger
|
1154
1156
|
json = { 'openapi': '3.0.1', 'info': { 'title': Rswag::Ui.config.config_object[:urls].last&.fetch(:name, 'API documentation'), 'version': ::Brick.config.api_version },
|
1155
1157
|
'servers': [
|
1156
1158
|
{ 'url': '{scheme}://{defaultHost}', 'variables': {
|
@@ -1701,48 +1703,18 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
1701
1703
|
end
|
1702
1704
|
end
|
1703
1705
|
|
1704
|
-
tables = []
|
1705
|
-
views = []
|
1706
|
-
table_class_length = 0
|
1707
|
-
view_class_length = 0
|
1708
1706
|
relations.each do |k, v|
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
class_name =
|
1716
|
-
if v.key?(:isView)
|
1717
|
-
view_class_length = class_name.length if class_name.length > view_class_length
|
1718
|
-
views
|
1719
|
-
else
|
1720
|
-
table_class_length = class_name.length if class_name.length > table_class_length
|
1721
|
-
tables
|
1722
|
-
end << [class_name, name_parts]
|
1723
|
-
end
|
1724
|
-
puts "\n" if tables.present? || views.present?
|
1725
|
-
if tables.present?
|
1726
|
-
puts "Classes that can be built from tables:"
|
1727
|
-
display_classes(tables, table_class_length)
|
1707
|
+
rel_name = k.split('.').map { |rel_part| ::Brick.namify(rel_part, :underscore) }
|
1708
|
+
schema_names = rel_name[0..-2]
|
1709
|
+
schema_names.shift if ::Brick.apartment_multitenant && schema_names.first == Apartment.default_schema
|
1710
|
+
v[:schema] = schema_names.join('.') unless schema_names.empty?
|
1711
|
+
# %%% If more than one schema has the same table name, will need to add a schema name prefix to have uniqueness
|
1712
|
+
v[:resource] = rel_name.last
|
1713
|
+
v[:class_name] = (schema_names + [rel_name.last.singularize]).map(&:camelize).join('::')
|
1728
1714
|
end
|
1729
|
-
if views.present?
|
1730
|
-
puts "Classes that can be built from views:"
|
1731
|
-
display_classes(views, view_class_length)
|
1732
|
-
end
|
1733
|
-
|
1734
1715
|
::Brick.load_additional_references if initializer_loaded
|
1735
1716
|
end
|
1736
1717
|
|
1737
|
-
def display_classes(rels, max_length)
|
1738
|
-
rels.sort.each do |rel|
|
1739
|
-
rel_link = rel.last.dup.map(&:underscore)
|
1740
|
-
rel_link[-1] = rel_link[-1]
|
1741
|
-
puts "#{rel.first}#{' ' * (max_length - rel.first.length)} /#{rel_link.join('/')}"
|
1742
|
-
end
|
1743
|
-
puts "\n"
|
1744
|
-
end
|
1745
|
-
|
1746
1718
|
def retrieve_schema_and_tables(sql = nil, is_postgres = nil, is_mssql = nil, schema = nil)
|
1747
1719
|
is_mssql = ActiveRecord::Base.connection.adapter_name == 'SQLServer' if is_mssql.nil?
|
1748
1720
|
sql ||= "SELECT t.table_schema AS \"schema\", t.table_name AS relation_name, t.table_type,#{"
|
@@ -726,7 +726,7 @@ erDiagram
|
|
726
726
|
<td><h1>#{model_name}</h1></td>
|
727
727
|
<td id=\"imgErd\" title=\"Show ERD\"></td>
|
728
728
|
</tr></table>#{template_link}<%
|
729
|
-
if (description = (relation = Brick.relations[#{model_name}.table_name])&.fetch(:description, nil)) %><%=
|
729
|
+
if (description = (relation = Brick.relations[#{model_name}.table_name])&.fetch(:description, nil)).present? %><%=
|
730
730
|
description %><br><%
|
731
731
|
end
|
732
732
|
# FILTER PARAMETERS
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -494,6 +494,13 @@ In config/initializers/brick.rb appropriate entries would look something like:
|
|
494
494
|
def version
|
495
495
|
VERSION::STRING
|
496
496
|
end
|
497
|
+
|
498
|
+
def display_classes(rels, max_length)
|
499
|
+
rels.sort.each do |rel|
|
500
|
+
puts "#{rel.first}#{' ' * (max_length - rel.first.length)} /#{rel.last}"
|
501
|
+
end
|
502
|
+
puts "\n"
|
503
|
+
end
|
497
504
|
end
|
498
505
|
|
499
506
|
module RouteSet
|
@@ -501,35 +508,59 @@ In config/initializers/brick.rb appropriate entries would look something like:
|
|
501
508
|
return super if ::Brick.routes_done
|
502
509
|
|
503
510
|
::Brick.routes_done = true
|
511
|
+
tables = []
|
512
|
+
views = []
|
513
|
+
table_class_length = 38 # Length of "Classes that can be built from tables:"
|
514
|
+
view_class_length = 37 # Length of "Classes that can be built from views:"
|
504
515
|
existing_controllers = routes.each_with_object({}) { |r, s| c = r.defaults[:controller]; s[c] = nil if c }
|
505
516
|
::Rails.application.routes.append do
|
506
517
|
# %%% TODO: If no auto-controllers then enumerate the controllers folder in order to build matching routes
|
507
518
|
# If auto-controllers and auto-models are both enabled then this makes sense:
|
508
|
-
::Brick.relations.each do |
|
509
|
-
|
510
|
-
schema_names = rel_name[0..-2]
|
511
|
-
schema_names.shift if ::Brick.apartment_multitenant && schema_names.first == Apartment.default_schema
|
512
|
-
# %%% If more than one schema has the same table name, will need to add a schema name prefix to have uniqueness
|
513
|
-
k = rel_name.last
|
514
|
-
unless existing_controllers.key?(controller_name = k.pluralize)
|
519
|
+
::Brick.relations.each do |k, v|
|
520
|
+
unless !(controller_name = v.fetch(:resource, nil)&.pluralize) || existing_controllers.key?(controller_name)
|
515
521
|
options = {}
|
516
522
|
options[:only] = [:index, :show] if v.key?(:isView)
|
517
|
-
|
518
|
-
|
519
|
-
|
523
|
+
full_resource = nil
|
524
|
+
if (schema_name = v.fetch(:schema, nil)) # && !Object.const_defined('Apartment')
|
525
|
+
send(:namespace, schema_name) do
|
526
|
+
send(:resources, v[:resource].to_sym, **options)
|
520
527
|
end
|
521
|
-
|
528
|
+
full_resource = "#{schema_name}/#{v[:resource]}"
|
529
|
+
send(:get, "#{::Brick.api_root}#{full_resource}", { to: "#{schema_name}/#{controller_name}#index" }) if Object.const_defined?('Rswag::Ui')
|
522
530
|
else
|
523
|
-
send(:resources,
|
524
|
-
|
531
|
+
send(:resources, v[:resource].to_sym, **options)
|
532
|
+
# Normally goes to something like: /api/v1/employees
|
533
|
+
send(:get, "#{::Brick.api_root}#{v[:resource]}", { to: "#{controller_name}#index" }) if Object.const_defined?('Rswag::Ui')
|
534
|
+
end
|
535
|
+
|
536
|
+
if (class_name = v.fetch(:class_name, nil))
|
537
|
+
if v.key?(:isView)
|
538
|
+
view_class_length = class_name.length if class_name.length > view_class_length
|
539
|
+
views
|
540
|
+
else
|
541
|
+
table_class_length = class_name.length if class_name.length > table_class_length
|
542
|
+
tables
|
543
|
+
end << [class_name, full_resource || v[:resource]]
|
525
544
|
end
|
526
545
|
end
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
546
|
+
end
|
547
|
+
puts "\n" if tables.present? || views.present?
|
548
|
+
if tables.present?
|
549
|
+
puts "Classes that can be built from tables:#{' ' * (table_class_length - 38)} Path:"
|
550
|
+
puts "======================================#{' ' * (table_class_length - 38)} ====="
|
551
|
+
::Brick.display_classes(tables, table_class_length)
|
552
|
+
end
|
553
|
+
if views.present?
|
554
|
+
puts "Classes that can be built from views:#{' ' * (view_class_length - 37)} Path:"
|
555
|
+
puts "=====================================#{' ' * (view_class_length - 37)} ====="
|
556
|
+
::Brick.display_classes(views, view_class_length)
|
557
|
+
end
|
558
|
+
|
559
|
+
if ::Brick.config.add_status && instance_variable_get(:@set).named_routes.names.exclude?(:brick_status)
|
560
|
+
get('/brick_status', to: 'brick_gem#status', as: 'brick_status')
|
561
|
+
end
|
562
|
+
if ::Brick.config.add_orphans && instance_variable_get(:@set).named_routes.names.exclude?(:brick_orphans)
|
563
|
+
get('/brick_orphans', to: 'brick_gem#orphans', as: 'brick_orphans')
|
533
564
|
end
|
534
565
|
if Object.const_defined?('Rswag::Ui') && doc_endpoint = Rswag::Ui.config.config_object[:urls].last
|
535
566
|
# Serves JSON swagger info from a path such as '/api-docs/v1/swagger.json'
|
@@ -147,7 +147,7 @@ module Brick
|
|
147
147
|
# Brick.enable_controllers = true # Setting this to \"false\" will disable controllers in development
|
148
148
|
# Brick.enable_views = true # Setting this to \"false\" will disable views in development
|
149
149
|
|
150
|
-
# Brick.api_root = '/api/v1/' # Path from which to serve out API resources when the RSwag gem is present
|
150
|
+
# ::Brick.api_root = '/api/v1/' # Path from which to serve out API resources when the RSwag gem is present
|
151
151
|
|
152
152
|
# # By default models are auto-created for database views, and set to be read-only. This can be skipped.
|
153
153
|
# Brick.skip_database_views = true
|
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.74
|
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-09-
|
11
|
+
date: 2022-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|