brick 1.0.184 → 1.0.186
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/compatibility.rb +6 -2
- data/lib/brick/extensions.rb +12 -6
- data/lib/brick/frameworks/rails/engine.rb +2 -2
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +41 -24
- 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: e5a41639892f2e1b8c16c55334cd7cb50f9bfd3a5bffd1eb093764deaad606d1
|
4
|
+
data.tar.gz: 4a18ba9341e71fb00bbc6dde1686b561de8cdd9b898905c680ba85f83cabf394
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c30f5f19ca9f5fe716d32d5efc5b0bc3a7d8addeeb9a8798cb34dc23efcc6abb92391854e899269875ccc2319b36b7361068e9ad17ad5d6245b16bf4ac7aaa89
|
7
|
+
data.tar.gz: d66d5544a948ad006294c654f8b7333b67b1a630c718c525a5fe40032414e4d307c0fe0aab70fcec47add3cd1feaed389ae3af75f69e3b480dbd4be3fc50a0a0
|
data/lib/brick/compatibility.rb
CHANGED
@@ -48,10 +48,14 @@ if ::Gem::Version.new(RUBY_VERSION) >= ::Gem::Version.new('2.7')
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
unless ActiveRecord.const_defined?(:NoDatabaseError)
|
51
|
+
unless ActiveRecord.const_defined?(:NoDatabaseError)
|
52
52
|
require 'active_model'
|
53
|
+
require 'active_record/deprecator' if ActiveRecord.version >= Gem::Version.new('7.1.0')
|
53
54
|
require 'active_record/errors'
|
54
|
-
|
55
|
+
# Generic version of NoDatabaseError for Rails <= 4.0
|
56
|
+
unless ActiveRecord.const_defined?(:NoDatabaseError)
|
57
|
+
class ::ActiveRecord::NoDatabaseError < ::ActiveRecord::StatementInvalid
|
58
|
+
end
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
data/lib/brick/extensions.rb
CHANGED
@@ -317,10 +317,15 @@ module ActiveRecord
|
|
317
317
|
tbl_parts[-1] = aps
|
318
318
|
tbl_parts << last_part
|
319
319
|
end
|
320
|
-
|
320
|
+
path_prefix = []
|
321
|
+
if ::Brick.config.path_prefix
|
322
|
+
tbl_parts.unshift(::Brick.config.path_prefix)
|
323
|
+
path_prefix << ::Brick.config.path_prefix
|
324
|
+
end
|
321
325
|
index = tbl_parts.map(&:underscore).join(separator)
|
322
|
-
# Rails applies an _index suffix to that route when the resource name
|
323
|
-
index << '_index' if mode != :singular && separator == '_' &&
|
326
|
+
# Rails applies an _index suffix to that route when the resource name isn't something plural
|
327
|
+
index << '_index' if mode != :singular && separator == '_' &&
|
328
|
+
index == (path_prefix + [name&.underscore&.tr('/', '_') || '_']).join(separator)
|
324
329
|
index
|
325
330
|
end
|
326
331
|
|
@@ -2044,9 +2049,10 @@ class Object
|
|
2044
2049
|
_schema, @_is_show_schema_list = ::Brick.set_db_schema(params || api_params)
|
2045
2050
|
|
2046
2051
|
if is_openapi
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2052
|
+
doc_endpoints = (Object.const_defined?('Rswag::Ui') &&
|
2053
|
+
(::Rswag::Ui.config.config_object[:urls])) ||
|
2054
|
+
::Brick.instance_variable_get(:@swagger_endpoints)
|
2055
|
+
api_name = doc_endpoints&.find { |api_url| api_url[:url] == request.path }&.fetch(:name, 'API documentation')
|
2050
2056
|
current_api_ver = current_api_root.split('/').last&.[](1..-1).to_i
|
2051
2057
|
json = { 'openapi': '3.0.1', 'info': { 'title': api_name, 'version': request_ver },
|
2052
2058
|
'servers': [
|
@@ -1966,7 +1966,7 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
|
|
1966
1966
|
def viable_models
|
1967
1967
|
return _brick_viable_models if ::RailsAdmin::Config.class_variables.include?(:@@system_models)
|
1968
1968
|
|
1969
|
-
brick_models = ::Brick.relations.
|
1969
|
+
brick_models = ::Brick.relations.each_with_object([]) { |rel, s| s << rel.last[:class_name] unless rel.first.is_a?(Symbol) }
|
1970
1970
|
|
1971
1971
|
# The original from RailsAdmin (now aliased as _brick_viable_models) loads all classes
|
1972
1972
|
# in the whole project. This Brick approach is a little more tame.
|
@@ -1999,7 +1999,7 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
|
|
1999
1999
|
end
|
2000
2000
|
|
2001
2001
|
RailsAdmin.config do |config|
|
2002
|
-
::Brick.relations.select { |_k, v| v.key?(:isView) }.each do |_k, relation|
|
2002
|
+
::Brick.relations.select { |_k, v| v.is_a?(Hash) && v.key?(:isView) }.each do |_k, relation|
|
2003
2003
|
config.model(relation[:class_name]) do # new_model_class
|
2004
2004
|
list do
|
2005
2005
|
sort_by (sort_col = relation[:cols].first.first)
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -162,6 +162,8 @@ module Brick
|
|
162
162
|
h[:db_name] = db_name if db_name
|
163
163
|
end
|
164
164
|
end
|
165
|
+
rescue ActiveRecord::NoDatabaseError
|
166
|
+
{}
|
165
167
|
end
|
166
168
|
|
167
169
|
def apartment_multitenant
|
@@ -208,7 +210,10 @@ module Brick
|
|
208
210
|
puts "Based on inclusion in ::Brick.polymorphics, marking association #{full_assoc_name} as being polymorphic."
|
209
211
|
a.options[:polymorphic] = true
|
210
212
|
end
|
211
|
-
if
|
213
|
+
if (through = a.options[:through]) && !a.through_reflection
|
214
|
+
puts "WARNING: In model #{model.name}, unable to utilise: has_many #{a.name}, through: #{through.inspect}"
|
215
|
+
end
|
216
|
+
if !a.polymorphic? && (a.belongs_to? || (through && a.through_reflection)) &&
|
212
217
|
!(a.klass && ::Brick.config.exclude_tables.exclude?(a.klass.table_name) &&
|
213
218
|
(!a.belongs_to? ||
|
214
219
|
((fk_type = a.foreign_key.is_a?(Array) ? a.foreign_key.map { |fk_part| model_cols[fk_part.to_s].type } : model_cols[a.foreign_key.to_s].type) &&
|
@@ -278,7 +283,7 @@ module Brick
|
|
278
283
|
is_invalid_source = true
|
279
284
|
end
|
280
285
|
if is_invalid_source
|
281
|
-
puts "
|
286
|
+
puts " due to invalid source #{a.source_reflection_name.inspect}."
|
282
287
|
next
|
283
288
|
end
|
284
289
|
else
|
@@ -321,6 +326,12 @@ module Brick
|
|
321
326
|
true
|
322
327
|
end
|
323
328
|
|
329
|
+
# Add a swagger endpoint in the same kind of way that RSwag UI does
|
330
|
+
def swagger_endpoint(url, name)
|
331
|
+
@swagger_endpoints ||= []
|
332
|
+
@swagger_endpoints << { url: url, name: name }
|
333
|
+
end
|
334
|
+
|
324
335
|
def is_geography?(val)
|
325
336
|
val.length < 31 && (val.length - 6) % 8 == 0 && val[0..5].bytes == [230, 16, 0, 0, 1, 12]
|
326
337
|
end
|
@@ -1130,39 +1141,45 @@ In config/initializers/brick.rb appropriate entries would look something like:
|
|
1130
1141
|
get("/#{controller_prefix}brick_crosstab/data", to: 'brick_gem#crosstab_data')
|
1131
1142
|
end
|
1132
1143
|
|
1133
|
-
if Object.const_defined?('Rswag::Ui')
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1144
|
+
if ((rswag_ui_present = Object.const_defined?('Rswag::Ui')) &&
|
1145
|
+
(rswag_path = routeset_to_use.routes.find { |r| r.app.app == ::Rswag::Ui::Engine }
|
1146
|
+
&.instance_variable_get(:@path_formatter)
|
1147
|
+
&.instance_variable_get(:@parts)&.join) &&
|
1148
|
+
(doc_endpoints = ::Rswag::Ui.config.config_object[:urls])) ||
|
1149
|
+
(doc_endpoints = ::Brick.instance_variable_get(:@swagger_endpoints))
|
1150
|
+
last_endpoint_parts = nil
|
1151
|
+
doc_endpoints.each do |doc_endpoint|
|
1137
1152
|
puts "Mounting OpenApi 3.0 documentation endpoint for \"#{doc_endpoint[:name]}\" on #{doc_endpoint[:url]}" unless ::Brick.routes_done
|
1138
1153
|
send(:get, doc_endpoint[:url], { to: 'brick_openapi#index' })
|
1139
1154
|
endpoint_parts = doc_endpoint[:url]&.split('/')
|
1140
|
-
|
1155
|
+
last_endpoint_parts = endpoint_parts
|
1141
1156
|
end
|
1142
1157
|
end
|
1143
1158
|
return if ::Brick.routes_done
|
1144
1159
|
|
1145
|
-
if
|
1146
|
-
if
|
1147
|
-
if rswag_path
|
1148
|
-
puts "API documentation now available when navigating to: /#{
|
1160
|
+
if doc_endpoints.present?
|
1161
|
+
if rswag_ui_present
|
1162
|
+
if rswag_path
|
1163
|
+
puts "API documentation now available when navigating to: /#{last_endpoint_parts&.find(&:present?)}/index.html"
|
1149
1164
|
else
|
1150
1165
|
puts "In order to make documentation available you can put this into your routes.rb:"
|
1151
|
-
puts " mount Rswag::Ui::Engine => '/#{
|
1166
|
+
puts " mount Rswag::Ui::Engine => '/#{last_endpoint_parts&.find(&:present?) || 'api-docs'}'"
|
1152
1167
|
end
|
1153
1168
|
else
|
1154
|
-
|
1169
|
+
puts 'A couple easy ways to create compelling documentation from this are to use Scalar API, or to add the rswag-ui gem.'
|
1170
|
+
end
|
1171
|
+
elsif rswag_ui_present
|
1172
|
+
sample_path = rswag_path || '/api-docs'
|
1173
|
+
puts
|
1174
|
+
puts "Brick: rswag-ui gem detected -- to make OpenAPI 3.0 documentation available from a path such as '#{sample_path}/v1/swagger.json',"
|
1175
|
+
puts ' put code such as this in an initializer:'
|
1176
|
+
puts ' Rswag::Ui.configure do |config|'
|
1177
|
+
puts " config.swagger_endpoint '#{sample_path}/v1/swagger.json', 'API V1 Docs'"
|
1178
|
+
puts ' end'
|
1179
|
+
unless rswag_path
|
1155
1180
|
puts
|
1156
|
-
puts
|
1157
|
-
puts
|
1158
|
-
puts ' Rswag::Ui.configure do |config|'
|
1159
|
-
puts " config.swagger_endpoint '#{sample_path}/v1/swagger.json', 'API V1 Docs'"
|
1160
|
-
puts ' end'
|
1161
|
-
unless rswag_path
|
1162
|
-
puts
|
1163
|
-
puts ' and put this into your routes.rb:'
|
1164
|
-
puts " mount Rswag::Ui::Engine => '/api-docs'"
|
1165
|
-
end
|
1181
|
+
puts ' and put this into your routes.rb:'
|
1182
|
+
puts " mount Rswag::Ui::Engine => '/api-docs'"
|
1166
1183
|
end
|
1167
1184
|
end
|
1168
1185
|
|
@@ -1916,7 +1933,7 @@ module ActiveRecord
|
|
1916
1933
|
private
|
1917
1934
|
|
1918
1935
|
# %%% Pretty much have to flat-out replace this guy (I think anyway)
|
1919
|
-
# Good with Rails 5.
|
1936
|
+
# Good with Rails 5.2.4 through 7.1 on this
|
1920
1937
|
# Ransack gem includes Polyamorous which replaces #build in a different way (which we handle below)
|
1921
1938
|
unless Gem::Specification.all_names.any? { |g| g.start_with?('ransack-') }
|
1922
1939
|
def build(associations, base_klass, root = nil, path = '')
|
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.186
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lorin Thwaits
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|