brick 1.0.185 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d930911e6903179271b74220c325ba024dfebe26f87eec06111772bfe1dd6b39
4
- data.tar.gz: fb0767bf7e59c56dffbe1999ee86ca3cefe66040dd26387019f2d45b8776fcd3
3
+ metadata.gz: e5a41639892f2e1b8c16c55334cd7cb50f9bfd3a5bffd1eb093764deaad606d1
4
+ data.tar.gz: 4a18ba9341e71fb00bbc6dde1686b561de8cdd9b898905c680ba85f83cabf394
5
5
  SHA512:
6
- metadata.gz: d03584188eaf7ba5a41b37fd80470f6eeb8c166949f4e19f1e2a9ccf958b94d0864c25f16363fbaae1980c36d8e82ec0eacf731cd5bdee97ec819a68be4b9836
7
- data.tar.gz: 5fc2966228117b7d35e5370ff64f2f46e85e8bfa8a1a4a4df8732e91fe0e0f4c0a5050cc7b77d44217538a7bc46681a24ebd03d0fc6ff69f483f7a7861f74a38
6
+ metadata.gz: c30f5f19ca9f5fe716d32d5efc5b0bc3a7d8addeeb9a8798cb34dc23efcc6abb92391854e899269875ccc2319b36b7361068e9ad17ad5d6245b16bf4ac7aaa89
7
+ data.tar.gz: d66d5544a948ad006294c654f8b7333b67b1a630c718c525a5fe40032414e4d307c0fe0aab70fcec47add3cd1feaed389ae3af75f69e3b480dbd4be3fc50a0a0
@@ -317,10 +317,15 @@ module ActiveRecord
317
317
  tbl_parts[-1] = aps
318
318
  tbl_parts << last_part
319
319
  end
320
- tbl_parts.unshift(::Brick.config.path_prefix) if ::Brick.config.path_prefix
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 is singular
323
- index << '_index' if mode != :singular && separator == '_' && index == index.singularize
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
- api_name = Rswag::Ui.config.config_object[:urls].find do |api_url|
2048
- api_url[:url] == request.path
2049
- end&.fetch(:name, 'API documentation')
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': [
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 185
8
+ TINY = 186
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
@@ -210,7 +210,10 @@ module Brick
210
210
  puts "Based on inclusion in ::Brick.polymorphics, marking association #{full_assoc_name} as being polymorphic."
211
211
  a.options[:polymorphic] = true
212
212
  end
213
- if !a.polymorphic? && (a.belongs_to? || (through = a.options[:through])) &&
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)) &&
214
217
  !(a.klass && ::Brick.config.exclude_tables.exclude?(a.klass.table_name) &&
215
218
  (!a.belongs_to? ||
216
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) &&
@@ -280,7 +283,7 @@ module Brick
280
283
  is_invalid_source = true
281
284
  end
282
285
  if is_invalid_source
283
- puts "WARNING: HMT relationship :#{a.name} in model #{model.name} has invalid source :#{a.source_reflection_name}."
286
+ puts " due to invalid source #{a.source_reflection_name.inspect}."
284
287
  next
285
288
  end
286
289
  else
@@ -323,6 +326,12 @@ module Brick
323
326
  true
324
327
  end
325
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
+
326
335
  def is_geography?(val)
327
336
  val.length < 31 && (val.length - 6) % 8 == 0 && val[0..5].bytes == [230, 16, 0, 0, 1, 12]
328
337
  end
@@ -1132,39 +1141,45 @@ In config/initializers/brick.rb appropriate entries would look something like:
1132
1141
  get("/#{controller_prefix}brick_crosstab/data", to: 'brick_gem#crosstab_data')
1133
1142
  end
1134
1143
 
1135
- if Object.const_defined?('Rswag::Ui')
1136
- rswag_path = routeset_to_use.routes.find { |r| r.app.app == Rswag::Ui::Engine }&.instance_variable_get(:@path_formatter)&.instance_variable_get(:@parts)&.join
1137
- first_endpoint_parts = nil
1138
- (doc_endpoints = Rswag::Ui.config.config_object[:urls])&.each do |doc_endpoint|
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|
1139
1152
  puts "Mounting OpenApi 3.0 documentation endpoint for \"#{doc_endpoint[:name]}\" on #{doc_endpoint[:url]}" unless ::Brick.routes_done
1140
1153
  send(:get, doc_endpoint[:url], { to: 'brick_openapi#index' })
1141
1154
  endpoint_parts = doc_endpoint[:url]&.split('/')
1142
- first_endpoint_parts ||= endpoint_parts
1155
+ last_endpoint_parts = endpoint_parts
1143
1156
  end
1144
1157
  end
1145
1158
  return if ::Brick.routes_done
1146
1159
 
1147
- if Object.const_defined?('Rswag::Ui')
1148
- if doc_endpoints.present?
1149
- if rswag_path && first_endpoint_parts
1150
- puts "API documentation now available when navigating to: /#{first_endpoint_parts&.find(&:present?)}/index.html"
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"
1151
1164
  else
1152
1165
  puts "In order to make documentation available you can put this into your routes.rb:"
1153
- puts " mount Rswag::Ui::Engine => '/#{first_endpoint_parts&.find(&:present?) || 'api-docs'}'"
1166
+ puts " mount Rswag::Ui::Engine => '/#{last_endpoint_parts&.find(&:present?) || 'api-docs'}'"
1154
1167
  end
1155
1168
  else
1156
- sample_path = rswag_path || '/api-docs'
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
1157
1180
  puts
1158
- puts "Brick: rswag-ui gem detected -- to make OpenAPI 3.0 documentation available from a path such as '#{sample_path}/v1/swagger.json',"
1159
- puts ' put code such as this in an initializer:'
1160
- puts ' Rswag::Ui.configure do |config|'
1161
- puts " config.swagger_endpoint '#{sample_path}/v1/swagger.json', 'API V1 Docs'"
1162
- puts ' end'
1163
- unless rswag_path
1164
- puts
1165
- puts ' and put this into your routes.rb:'
1166
- puts " mount Rswag::Ui::Engine => '/api-docs'"
1167
- end
1181
+ puts ' and put this into your routes.rb:'
1182
+ puts " mount Rswag::Ui::Engine => '/api-docs'"
1168
1183
  end
1169
1184
  end
1170
1185
 
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.185
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-25 00:00:00.000000000 Z
11
+ date: 2023-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord