brick 1.0.160 → 1.0.162

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: 735ad34b99ba52ae2575c786fdee6c359c5c53e6d2edf53b19bbb5d1f02869ec
4
- data.tar.gz: c603e9adebe13192e4be8724b51d563a6b39f89b15c61fab253debb9fc959a66
3
+ metadata.gz: 55c0fbbc54209abd96db599b62a47d8ad18358711c87f4ada1641080d394d6fb
4
+ data.tar.gz: 41c099baff51a4a6f28be3addbe52efea29880ec90421f9f44bab1dd189e3d60
5
5
  SHA512:
6
- metadata.gz: 14b5a64e366d218ac78bb3ec26370cddcdb506ee292974321a76331a40d272a33ce49b9cb4911314a7e33835bf44255dda73c04449062e159b499e2e0d88c61f
7
- data.tar.gz: cfa821c073296681b4b49e0d58538e076ac50ae1ea65b2df6ea8af1c92477842ee737c3d5950d803ce45f52daf48fca065f28bf6cc6a5e6518c408a64305ada6
6
+ metadata.gz: f76a35dd8f968285a10875ff39ba3b42047a6daf1f2e27bb4d46df20d12a67419645c4ca12e957653d0c61e732da2ed33979d140dd9963c7d151809f10baeae9
7
+ data.tar.gz: 5f449f0ceb5aada8686eded1721c62924ced58cb153e6e0dda845c41469aae075c0cf96c89e643e6b454f874c4515431244a3583a3ba519f538a0b18e059cd35
@@ -972,9 +972,14 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
972
972
  (!a.options[:polymorphic] && a.klass == klass && klass_cols.include?(a.foreign_key))
973
973
  )
974
974
  end
975
+
975
976
  # ActiveStorage compatibility
976
977
  selects << 'service_name' if klass.name == 'ActiveStorage::Blob' && ActiveStorage::Blob.columns_hash.key?('service_name')
977
978
  selects << 'blob_id' if klass.name == 'ActiveStorage::Attachment' && ActiveStorage::Attachment.columns_hash.key?('blob_id')
979
+ # Pay gem compatibility
980
+ selects << 'processor' if klass.name == 'Pay::Customer' && Pay::Customer.columns_hash.key?('processor')
981
+ selects << 'customer_id' if klass.name == 'Pay::Subscription' && Pay::Subscription.columns_hash.key?('customer_id')
982
+
978
983
  pieces, my_dsl = klass.brick_parse_dsl(join_array = ::Brick::JoinArray.new, [], translations = {}, false, nil, true)
979
984
  brick_select(
980
985
  selects, where_values_hash, nil, translations: translations, join_array: join_array,
@@ -1131,6 +1136,20 @@ if Object.const_defined?('ActionView')
1131
1136
  end
1132
1137
  end
1133
1138
  end
1139
+
1140
+ module ActionDispatch::Routing
1141
+ class Mapper
1142
+ module Base
1143
+ # Pro-actively assess Brick routes. Useful when there is a "catch all" wildcard route
1144
+ # at the end of an existing `routes.rb` file, which would normally steal the show and
1145
+ # not let Brick have any fun. So just call this right before any wildcard routes, and
1146
+ # you'll be in business!
1147
+ def mount_brick_routes
1148
+ add_brick_routes unless ::Brick.routes_done
1149
+ end
1150
+ end
1151
+ end
1152
+ end
1134
1153
  end
1135
1154
 
1136
1155
  if ActiveSupport::Dependencies.respond_to?(:autoload_module!) # %%% Only works with previous non-zeitwerk auto-loading
@@ -1807,7 +1826,7 @@ class Object
1807
1826
  cspd.select! { |val| val == "'self'" }
1808
1827
  cspd << style_value
1809
1828
  else
1810
- cspd << "'sha256-QHKxqKcUq7AER1QwEu5uQXRQwC8j4iTWkE8mpOmP7ms='"
1829
+ cspd << "'sha256-VbHigzrnU2KiWIjHStrKhnGxWRv25WXQNdKr5qhevD8='"
1811
1830
  end
1812
1831
  cspd << 'https://cdn.jsdelivr.net'
1813
1832
  end
@@ -1984,6 +1984,10 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1984
1984
  # In order to defer auto-creation of any routes that already exist, calculate Brick routes only after having loaded all others
1985
1985
  prepend ::Brick::RouteSet
1986
1986
  end
1987
+ ActionDispatch::Routing::Mapper.class_exec do
1988
+ include ::Brick::RouteMapper
1989
+ end
1990
+
1987
1991
  # Do the root route before the Rails Welcome one would otherwise take precedence
1988
1992
  if (route = ::Brick.config.default_route_fallback).present?
1989
1993
  action = "#{route}#{'#index' unless route.index('#')}"
@@ -246,6 +246,7 @@ module Brick::Rails::FormTags
246
246
  # Accommodate any valid STI by going up the chain of inheritance
247
247
  break unless bt_pair.nil? && poly_class_name = ::Brick.existing_stis[poly_class_name]
248
248
  end
249
+ table_name = model.name.split('::').last.underscore.pluralize
249
250
  puts "*** Might be missing an STI class called #{orig_poly_name} whose base class should have this:
250
251
  *** has_many :#{table_name}, as: :#{bt.first}
251
252
  *** Can probably auto-configure everything using these lines in an initialiser:
@@ -385,7 +386,11 @@ module Brick::Rails::FormTags
385
386
  if (links = _brick_resource_from_iv(true)).length == 1 # If there's only one match then use any text that was supplied
386
387
  link_to_brick(text || links.first.last.join('/'), links.first.first, **kwargs)
387
388
  else
388
- links.each_with_object([]) { |v, s| s << link if link = link_to_brick(v.join('/'), v, **kwargs) }.join(' &nbsp; ').html_safe
389
+ links.each_with_object([]) do |v, s|
390
+ if (link = link_to_brick(v.join('/'), v, **kwargs))
391
+ s << link
392
+ end
393
+ end.join(' &nbsp; ').html_safe
389
394
  end
390
395
  end
391
396
  end # link_to_brick
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 160
8
+ TINY = 162
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
@@ -794,296 +794,304 @@ In config/initializers/brick.rb appropriate entries would look something like:
794
794
 
795
795
  module RouteSet
796
796
  def finalize!
797
- routeset_to_use = ::Rails.application.routes
798
- return super if self != routeset_to_use || ::Brick.routes_done
797
+ if self == ::Rails.application.routes && !::Brick.routes_done
798
+ append do
799
+ add_brick_routes
800
+ end
801
+ end
802
+ super
803
+ end
804
+ end
799
805
 
806
+ module RouteMapper
807
+ def add_brick_routes
808
+ routeset_to_use = ::Rails.application.routes
800
809
  path_prefix = ::Brick.config.path_prefix
801
- existing_controllers = routes.each_with_object({}) do |r, s|
810
+ existing_controllers = routeset_to_use.routes.each_with_object({}) do |r, s|
802
811
  c = r.defaults[:controller]
803
812
  s[c] = nil if c
804
813
  end
805
- append do
806
- tables = []
807
- views = []
808
- table_class_length = 38 # Length of "Classes that can be built from tables:"
809
- view_class_length = 37 # Length of "Classes that can be built from views:"
810
-
811
- brick_namespace_create = lambda do |path_names, res_name, options|
812
- if path_names&.present?
813
- if (path_name = path_names.pop).is_a?(Array)
814
- module_name = path_name[1]
815
- path_name = path_name.first
816
- end
817
- send(:scope, { module: module_name || path_name, path: path_name, as: path_name }) do
818
- brick_namespace_create.call(path_names, res_name, options)
819
- end
820
- else
821
- send(:resources, res_name.to_sym, **options)
814
+
815
+ tables = []
816
+ views = []
817
+ table_class_length = 38 # Length of "Classes that can be built from tables:"
818
+ view_class_length = 37 # Length of "Classes that can be built from views:"
819
+
820
+ brick_namespace_create = lambda do |path_names, res_name, options|
821
+ if path_names&.present?
822
+ if (path_name = path_names.pop).is_a?(Array)
823
+ module_name = path_name[1]
824
+ path_name = path_name.first
825
+ end
826
+ send(:scope, { module: module_name || path_name, path: path_name, as: path_name }) do
827
+ brick_namespace_create.call(path_names, res_name, options)
822
828
  end
829
+ else
830
+ send(:resources, res_name.to_sym, **options)
823
831
  end
832
+ end
824
833
 
825
- # %%% TODO: If no auto-controllers then enumerate the controllers folder in order to build matching routes
826
- # If auto-controllers and auto-models are both enabled then this makes sense:
827
- controller_prefix = (path_prefix ? "#{path_prefix}/" : '')
828
- sti_subclasses = ::Brick.config.sti_namespace_prefixes.each_with_object(Hash.new { |h, k| h[k] = [] }) do |v, s|
829
- # Turn something like {"::Spouse"=>"Person", "::Friend"=>"Person"} into {"Person"=>["Spouse", "Friend"]}
830
- s[v.last] << v.first[2..-1] unless v.first.end_with?('::')
831
- end
832
- versioned_views = {} # Track which views have already been done for each api_root
833
- ::Brick.relations.each do |k, v|
834
- if (schema_name = v.fetch(:schema, nil))
835
- schema_prefix = "#{schema_name}."
836
- end
834
+ # %%% TODO: If no auto-controllers then enumerate the controllers folder in order to build matching routes
835
+ # If auto-controllers and auto-models are both enabled then this makes sense:
836
+ controller_prefix = (path_prefix ? "#{path_prefix}/" : '')
837
+ sti_subclasses = ::Brick.config.sti_namespace_prefixes.each_with_object(Hash.new { |h, k| h[k] = [] }) do |v, s|
838
+ # Turn something like {"::Spouse"=>"Person", "::Friend"=>"Person"} into {"Person"=>["Spouse", "Friend"]}
839
+ s[v.last] << v.first[2..-1] unless v.first.end_with?('::')
840
+ end
841
+ versioned_views = {} # Track which views have already been done for each api_root
842
+ ::Brick.relations.each do |k, v|
843
+ if (schema_name = v.fetch(:schema, nil))
844
+ schema_prefix = "#{schema_name}."
845
+ end
837
846
 
838
- next if !(resource_name = v.fetch(:resource, nil)) ||
839
- existing_controllers.key?(
840
- controller_prefix + (resource_name = "#{schema_prefix&.tr('.', '/')}#{resource_name}".pluralize)
841
- )
842
-
843
- object_name = k.split('.').last # Take off any first schema part
844
-
845
- full_schema_prefix = if (aps = v.fetch(:auto_prefixed_schema, nil))
846
- aps = aps[0..-2] if aps[-1] == '_'
847
- (schema_prefix&.dup || +'') << "#{aps}."
848
- else
849
- schema_prefix
850
- end
851
-
852
- # Track routes being built
853
- if (class_name = v.fetch(:class_name, nil))
854
- if v.key?(:isView)
855
- view_class_length = class_name.length if class_name.length > view_class_length
856
- views
857
- else
858
- table_class_length = class_name.length if class_name.length > table_class_length
859
- tables
860
- end << [class_name, aps, resource_name]
861
- end
847
+ next if !(resource_name = v.fetch(:resource, nil)) ||
848
+ existing_controllers.fetch(
849
+ controller_prefix + (resource_name = "#{schema_prefix&.tr('.', '/')}#{resource_name}".pluralize),
850
+ nil
851
+ )
862
852
 
863
- options = {}
864
- options[:only] = [:index, :show] if v.key?(:isView)
865
-
866
- # First do the normal routes
867
- prefixes = []
868
- prefixes << [aps, v[:class_name]&.split('::')[-2]&.underscore] if aps
869
- prefixes << schema_name if schema_name
870
- prefixes << path_prefix if path_prefix
871
- brick_namespace_create.call(prefixes, v[:resource], options)
872
- sti_subclasses.fetch(class_name, nil)&.each do |sc| # Add any STI subclass routes for this relation
873
- brick_namespace_create.call(prefixes, sc.underscore.tr('/', '_').pluralize, options)
874
- end
853
+ object_name = k.split('.').last # Take off any first schema part
875
854
 
876
- # Now the API routes if necessary
877
- full_resource = nil
878
- ::Brick.api_roots&.each do |api_root|
879
- api_done_views = (versioned_views[api_root] ||= {})
880
- found = nil
881
- test_ver_num = nil
882
- view_relation = nil
883
- # If it's a view then see if there's a versioned one available by searching for resource names
884
- # versioned with the closest number (equal to or less than) compared with our API version number.
885
- if v.key?(:isView)
886
- if (ver = object_name.match(/^v([\d_]*)/)&.captures&.first) && ver[-1] == '_'
887
- core_object_name = object_name[ver.length + 1..-1]
888
- next if api_done_views.key?(unversioned = "#{schema_prefix}v_#{core_object_name}")
889
-
890
- # Expect that the last item in the path generally holds versioning information
891
- api_ver = api_root.split('/')[-1]&.gsub('_', '.')
892
- vn_idx = api_ver.rindex(/[^\d._]/) # Position of the first numeric digit at the end of the version number
893
- # Was: .to_d
894
- test_ver_num = api_ver_num = api_ver[vn_idx + 1..-1].gsub('_', '.').to_i # Attempt to turn something like "v3" into the decimal value 3
895
- # puts [api_ver, vn_idx, api_ver_num, unversioned].inspect
896
-
897
- next if ver.to_i > api_ver_num # Don't surface any newer views in an older API
898
-
899
- test_ver_num -= 1 until test_ver_num.zero? ||
900
- (view_relation = ::Brick.relations.fetch(
901
- found = "#{schema_prefix}v#{test_ver_num}_#{core_object_name}", nil
902
- ))
903
- api_done_views[unversioned] = nil # Mark that for this API version this view is done
904
-
905
- # puts "Found #{found}" if view_relation
906
- # If we haven't found "v3_view_name" or "v2_view_name" or so forth, at the last
907
- # fall back to simply looking for "v_view_name", and then finally "view_name".
908
- no_v_prefix_name = "#{schema_prefix}#{core_object_name}"
909
- standard_prefix = 'v_'
910
- else
911
- core_object_name = object_name
912
- end
913
- if (rvp = ::Brick.config.api_remove_view_prefix) && core_object_name.start_with?(rvp)
914
- core_object_name.slice!(0, rvp.length)
915
- end
916
- no_prefix_name = "#{schema_prefix}#{core_object_name}"
917
- unversioned = "#{schema_prefix}#{standard_prefix}#{::Brick.config.api_add_view_prefix}#{core_object_name}"
855
+ full_schema_prefix = if (aps = v.fetch(:auto_prefixed_schema, nil))
856
+ aps = aps[0..-2] if aps[-1] == '_'
857
+ (schema_prefix&.dup || +'') << "#{aps}."
858
+ else
859
+ schema_prefix
860
+ end
861
+
862
+ # Track routes being built
863
+ if (class_name = v.fetch(:class_name, nil))
864
+ if v.key?(:isView)
865
+ view_class_length = class_name.length if class_name.length > view_class_length
866
+ views
867
+ else
868
+ table_class_length = class_name.length if class_name.length > table_class_length
869
+ tables
870
+ end << [class_name, aps, resource_name]
871
+ end
872
+
873
+ options = {}
874
+ options[:only] = [:index, :show] if v.key?(:isView)
875
+
876
+ # First do the normal routes
877
+ prefixes = []
878
+ prefixes << [aps, v[:class_name]&.split('::')[-2]&.underscore] if aps
879
+ prefixes << schema_name if schema_name
880
+ prefixes << path_prefix if path_prefix
881
+ brick_namespace_create.call(prefixes, v[:resource], options)
882
+ sti_subclasses.fetch(class_name, nil)&.each do |sc| # Add any STI subclass routes for this relation
883
+ brick_namespace_create.call(prefixes, sc.underscore.tr('/', '_').pluralize, options)
884
+ end
885
+
886
+ # Now the API routes if necessary
887
+ full_resource = nil
888
+ ::Brick.api_roots&.each do |api_root|
889
+ api_done_views = (versioned_views[api_root] ||= {})
890
+ found = nil
891
+ test_ver_num = nil
892
+ view_relation = nil
893
+ # If it's a view then see if there's a versioned one available by searching for resource names
894
+ # versioned with the closest number (equal to or less than) compared with our API version number.
895
+ if v.key?(:isView)
896
+ if (ver = object_name.match(/^v([\d_]*)/)&.captures&.first) && ver[-1] == '_'
897
+ core_object_name = object_name[ver.length + 1..-1]
898
+ next if api_done_views.key?(unversioned = "#{schema_prefix}v_#{core_object_name}")
899
+
900
+ # Expect that the last item in the path generally holds versioning information
901
+ api_ver = api_root.split('/')[-1]&.gsub('_', '.')
902
+ vn_idx = api_ver.rindex(/[^\d._]/) # Position of the first numeric digit at the end of the version number
903
+ # Was: .to_d
904
+ test_ver_num = api_ver_num = api_ver[vn_idx + 1..-1].gsub('_', '.').to_i # Attempt to turn something like "v3" into the decimal value 3
905
+ # puts [api_ver, vn_idx, api_ver_num, unversioned].inspect
906
+
907
+ next if ver.to_i > api_ver_num # Don't surface any newer views in an older API
908
+
909
+ test_ver_num -= 1 until test_ver_num.zero? ||
910
+ (view_relation = ::Brick.relations.fetch(
911
+ found = "#{schema_prefix}v#{test_ver_num}_#{core_object_name}", nil
912
+ ))
913
+ api_done_views[unversioned] = nil # Mark that for this API version this view is done
914
+
915
+ # puts "Found #{found}" if view_relation
916
+ # If we haven't found "v3_view_name" or "v2_view_name" or so forth, at the last
917
+ # fall back to simply looking for "v_view_name", and then finally "view_name".
918
+ no_v_prefix_name = "#{schema_prefix}#{core_object_name}"
919
+ standard_prefix = 'v_'
918
920
  else
919
- unversioned = k
921
+ core_object_name = object_name
922
+ end
923
+ if (rvp = ::Brick.config.api_remove_view_prefix) && core_object_name.start_with?(rvp)
924
+ core_object_name.slice!(0, rvp.length)
920
925
  end
926
+ no_prefix_name = "#{schema_prefix}#{core_object_name}"
927
+ unversioned = "#{schema_prefix}#{standard_prefix}#{::Brick.config.api_add_view_prefix}#{core_object_name}"
928
+ else
929
+ unversioned = k
930
+ end
921
931
 
922
- view_relation ||= ::Brick.relations.fetch(found = unversioned, nil) ||
923
- (no_v_prefix_name && ::Brick.relations.fetch(found = no_v_prefix_name, nil)) ||
924
- (no_prefix_name && ::Brick.relations.fetch(found = no_prefix_name, nil))
925
- if view_relation
926
- actions = view_relation.key?(:isView) ? [:index, :show] : ::Brick::ALL_API_ACTIONS # By default all actions are allowed
927
- # Call proc that limits which endpoints get surfaced based on version, table or view name, method (get list / get one / post / patch / delete)
928
- # Returning nil makes it do nothing, false makes it skip creating this endpoint, and an array of up to
929
- # these 3 things controls and changes the nature of the endpoint that gets built:
930
- # (updated api_name, name of different relation to route to, allowed actions such as :index, :show, :create, etc)
931
- proc_result = if (filter = ::Brick.config.api_filter).is_a?(Proc)
932
- begin
933
- num_args = filter.arity.negative? ? 6 : filter.arity
934
- filter.call(*[unversioned, k, view_relation, actions, api_ver_num, found, test_ver_num][0...num_args])
935
- rescue StandardError => e
936
- puts "::Brick.api_filter Proc error: #{e.message}"
937
- end
932
+ view_relation ||= ::Brick.relations.fetch(found = unversioned, nil) ||
933
+ (no_v_prefix_name && ::Brick.relations.fetch(found = no_v_prefix_name, nil)) ||
934
+ (no_prefix_name && ::Brick.relations.fetch(found = no_prefix_name, nil))
935
+ if view_relation
936
+ actions = view_relation.key?(:isView) ? [:index, :show] : ::Brick::ALL_API_ACTIONS # By default all actions are allowed
937
+ # Call proc that limits which endpoints get surfaced based on version, table or view name, method (get list / get one / post / patch / delete)
938
+ # Returning nil makes it do nothing, false makes it skip creating this endpoint, and an array of up to
939
+ # these 3 things controls and changes the nature of the endpoint that gets built:
940
+ # (updated api_name, name of different relation to route to, allowed actions such as :index, :show, :create, etc)
941
+ proc_result = if (filter = ::Brick.config.api_filter).is_a?(Proc)
942
+ begin
943
+ num_args = filter.arity.negative? ? 6 : filter.arity
944
+ filter.call(*[unversioned, k, view_relation, actions, api_ver_num, found, test_ver_num][0...num_args])
945
+ rescue StandardError => e
946
+ puts "::Brick.api_filter Proc error: #{e.message}"
938
947
  end
939
- # proc_result expects to receive back: [updated_api_name, to_other_relation, allowed_actions]
948
+ end
949
+ # proc_result expects to receive back: [updated_api_name, to_other_relation, allowed_actions]
940
950
 
941
- case proc_result
942
- when NilClass
943
- # Do nothing differently than what normal behaviour would be
944
- when FalseClass # Skip implementing this endpoint
945
- view_relation[:api][api_ver_num] = nil
946
- next
947
- when Array # Did they give back an array of actions?
948
- unless proc_result.any? { |pr| ::Brick::ALL_API_ACTIONS.exclude?(pr) }
949
- proc_result = [unversioned, to_relation, proc_result]
950
- end
951
- # Otherwise don't change this array because it's probably legit
952
- when String
953
- proc_result = [proc_result] # Treat this as the surfaced api_name (path) they want to use for this endpoint
954
- else
955
- puts "::Brick.api_filter Proc warning: Unable to parse this result returned: \n #{proc_result.inspect}"
956
- proc_result = nil # Couldn't understand what in the world was returned
951
+ case proc_result
952
+ when NilClass
953
+ # Do nothing differently than what normal behaviour would be
954
+ when FalseClass # Skip implementing this endpoint
955
+ view_relation[:api][api_ver_num] = nil
956
+ next
957
+ when Array # Did they give back an array of actions?
958
+ unless proc_result.any? { |pr| ::Brick::ALL_API_ACTIONS.exclude?(pr) }
959
+ proc_result = [unversioned, to_relation, proc_result]
957
960
  end
961
+ # Otherwise don't change this array because it's probably legit
962
+ when String
963
+ proc_result = [proc_result] # Treat this as the surfaced api_name (path) they want to use for this endpoint
964
+ else
965
+ puts "::Brick.api_filter Proc warning: Unable to parse this result returned: \n #{proc_result.inspect}"
966
+ proc_result = nil # Couldn't understand what in the world was returned
967
+ end
958
968
 
959
- if proc_result&.present?
960
- if proc_result[1] # to_other_relation
961
- if (new_view_relation = ::Brick.relations.fetch(proc_result[1], nil))
962
- k = proc_result[1] # Route this call over to this different relation
963
- view_relation = new_view_relation
964
- else
965
- puts "::Brick.api_filter Proc warning: Unable to find new suggested relation with name #{proc_result[1]} -- sticking with #{k} instead."
966
- end
967
- end
968
- if proc_result.first&.!=(k) # updated_api_name -- a different name than this relation would normally have
969
- found = proc_result.first
969
+ if proc_result&.present?
970
+ if proc_result[1] # to_other_relation
971
+ if (new_view_relation = ::Brick.relations.fetch(proc_result[1], nil))
972
+ k = proc_result[1] # Route this call over to this different relation
973
+ view_relation = new_view_relation
974
+ else
975
+ puts "::Brick.api_filter Proc warning: Unable to find new suggested relation with name #{proc_result[1]} -- sticking with #{k} instead."
970
976
  end
971
- actions &= proc_result[2] if proc_result[2] # allowed_actions
972
977
  end
973
- (view_relation[:api][api_ver_num] ||= {})[unversioned] = actions # Add to the list of API paths this resource responds to
974
-
975
- # view_ver_num = if (first_part = k.split('_').first) =~ /^v[\d_]+/
976
- # first_part[1..-1].gsub('_', '.').to_i
977
- # end
978
- controller_name = if (last = view_relation.fetch(:resource, nil)&.pluralize)
979
- "#{full_schema_prefix}#{last}"
980
- else
981
- found
982
- end.tr('.', '/')
983
-
984
- { :index => 'get', :create => 'post' }.each do |action, method|
985
- if actions.include?(action)
986
- # Normally goes to something like: /api/v1/employees
987
- send(method, "#{api_root}#{unversioned.tr('.', '/')}", { to: "#{controller_prefix}#{controller_name}##{action}" })
988
- end
978
+ if proc_result.first&.!=(k) # updated_api_name -- a different name than this relation would normally have
979
+ found = proc_result.first
989
980
  end
990
- # %%% We do not yet surface the #show action
991
- if (id_col = view_relation[:pk]&.first) # ID-dependent stuff
992
- { :update => ['put', 'patch'], :destroy => ['delete'] }.each do |action, methods|
993
- if actions.include?(action)
994
- methods.each do |method|
995
- send(method, "#{api_root}#{unversioned.tr('.', '/')}/:#{id_col}", { to: "#{controller_prefix}#{controller_name}##{action}" })
996
- end
981
+ actions &= proc_result[2] if proc_result[2] # allowed_actions
982
+ end
983
+ (view_relation[:api][api_ver_num] ||= {})[unversioned] = actions # Add to the list of API paths this resource responds to
984
+
985
+ # view_ver_num = if (first_part = k.split('_').first) =~ /^v[\d_]+/
986
+ # first_part[1..-1].gsub('_', '.').to_i
987
+ # end
988
+ controller_name = if (last = view_relation.fetch(:resource, nil)&.pluralize)
989
+ "#{full_schema_prefix}#{last}"
990
+ else
991
+ found
992
+ end.tr('.', '/')
993
+
994
+ { :index => 'get', :create => 'post' }.each do |action, method|
995
+ if actions.include?(action)
996
+ # Normally goes to something like: /api/v1/employees
997
+ send(method, "#{api_root}#{unversioned.tr('.', '/')}", { to: "#{controller_prefix}#{controller_name}##{action}" })
998
+ end
999
+ end
1000
+ # %%% We do not yet surface the #show action
1001
+ if (id_col = view_relation[:pk]&.first) # ID-dependent stuff
1002
+ { :update => ['put', 'patch'], :destroy => ['delete'] }.each do |action, methods|
1003
+ if actions.include?(action)
1004
+ methods.each do |method|
1005
+ send(method, "#{api_root}#{unversioned.tr('.', '/')}/:#{id_col}", { to: "#{controller_prefix}#{controller_name}##{action}" })
997
1006
  end
998
1007
  end
999
1008
  end
1000
1009
  end
1001
1010
  end
1011
+ end
1002
1012
 
1003
- # Trestle compatibility
1004
- if Object.const_defined?('Trestle') && ::Trestle.config.options&.key?(:site_title) &&
1005
- !Object.const_defined?("#{(res_name = resource_name.tr('/', '_')).camelize}Admin")
1006
- begin
1007
- ::Trestle.resource(res_sym = res_name.to_sym, model: class_name&.constantize) do
1008
- menu { item res_sym, icon: "fa fa-star" }
1009
- end
1010
- rescue
1013
+ # Trestle compatibility
1014
+ if Object.const_defined?('Trestle') && ::Trestle.config.options&.key?(:site_title) &&
1015
+ !Object.const_defined?("#{(res_name = resource_name.tr('/', '_')).camelize}Admin")
1016
+ begin
1017
+ ::Trestle.resource(res_sym = res_name.to_sym, model: class_name&.constantize) do
1018
+ menu { item res_sym, icon: "fa fa-star" }
1011
1019
  end
1020
+ rescue
1012
1021
  end
1013
1022
  end
1023
+ end
1014
1024
 
1015
- if (named_routes = instance_variable_get(:@set).named_routes).respond_to?(:find)
1016
- if ::Brick.config.add_status && (status_as = "#{controller_prefix.tr('/', '_')}brick_status".to_sym)
1017
- (
1018
- !(status_route = instance_variable_get(:@set).named_routes.find { |route| route.first == status_as }&.last) ||
1019
- !status_route.ast.to_s.include?("/#{controller_prefix}brick_status/")
1020
- )
1021
- get("/#{controller_prefix}brick_status", to: 'brick_gem#status', as: status_as.to_s)
1022
- end
1023
-
1024
- if ::Brick.config.add_orphans && (orphans_as = "#{controller_prefix.tr('/', '_')}brick_orphans".to_sym)
1025
- (
1026
- !(orphans_route = instance_variable_get(:@set).named_routes.find { |route| route.first == orphans_as }&.last) ||
1027
- !orphans_route.ast.to_s.include?("/#{controller_prefix}brick_orphans/")
1028
- )
1029
- get("/#{controller_prefix}brick_orphans", to: 'brick_gem#orphans', as: 'brick_orphans')
1030
- end
1025
+ if (named_routes = instance_variable_get(:@set).named_routes).respond_to?(:find)
1026
+ if ::Brick.config.add_status && (status_as = "#{controller_prefix.tr('/', '_')}brick_status".to_sym)
1027
+ (
1028
+ !(status_route = instance_variable_get(:@set).named_routes.find { |route| route.first == status_as }&.last) ||
1029
+ !status_route.ast.to_s.include?("/#{controller_prefix}brick_status/")
1030
+ )
1031
+ get("/#{controller_prefix}brick_status", to: 'brick_gem#status', as: status_as.to_s)
1031
1032
  end
1032
1033
 
1033
- if instance_variable_get(:@set).named_routes.names.exclude?(:brick_crosstab)
1034
- get("/#{controller_prefix}brick_crosstab", to: 'brick_gem#crosstab', as: 'brick_crosstab')
1035
- get("/#{controller_prefix}brick_crosstab/data", to: 'brick_gem#crosstab_data')
1034
+ if ::Brick.config.add_orphans && (orphans_as = "#{controller_prefix.tr('/', '_')}brick_orphans".to_sym)
1035
+ (
1036
+ !(orphans_route = instance_variable_get(:@set).named_routes.find { |route| route.first == orphans_as }&.last) ||
1037
+ !orphans_route.ast.to_s.include?("/#{controller_prefix}brick_orphans/")
1038
+ )
1039
+ get("/#{controller_prefix}brick_orphans", to: 'brick_gem#orphans', as: 'brick_orphans')
1036
1040
  end
1041
+ end
1037
1042
 
1038
- if Object.const_defined?('Rswag::Ui')
1039
- rswag_path = routeset_to_use.routes.find { |r| r.app.app == Rswag::Ui::Engine }&.instance_variable_get(:@path_formatter)&.instance_variable_get(:@parts)&.join
1040
- first_endpoint_parts = nil
1041
- (doc_endpoints = Rswag::Ui.config.config_object[:urls])&.each do |doc_endpoint|
1042
- puts "Mounting OpenApi 3.0 documentation endpoint for \"#{doc_endpoint[:name]}\" on #{doc_endpoint[:url]}" unless ::Brick.routes_done
1043
- send(:get, doc_endpoint[:url], { to: 'brick_openapi#index' })
1044
- endpoint_parts = doc_endpoint[:url]&.split('/')
1045
- first_endpoint_parts ||= endpoint_parts
1046
- end
1043
+ if instance_variable_get(:@set).named_routes.names.exclude?(:brick_crosstab)
1044
+ get("/#{controller_prefix}brick_crosstab", to: 'brick_gem#crosstab', as: 'brick_crosstab')
1045
+ get("/#{controller_prefix}brick_crosstab/data", to: 'brick_gem#crosstab_data')
1046
+ end
1047
+
1048
+ if Object.const_defined?('Rswag::Ui')
1049
+ rswag_path = routeset_to_use.routes.find { |r| r.app.app == Rswag::Ui::Engine }&.instance_variable_get(:@path_formatter)&.instance_variable_get(:@parts)&.join
1050
+ first_endpoint_parts = nil
1051
+ (doc_endpoints = Rswag::Ui.config.config_object[:urls])&.each do |doc_endpoint|
1052
+ puts "Mounting OpenApi 3.0 documentation endpoint for \"#{doc_endpoint[:name]}\" on #{doc_endpoint[:url]}" unless ::Brick.routes_done
1053
+ send(:get, doc_endpoint[:url], { to: 'brick_openapi#index' })
1054
+ endpoint_parts = doc_endpoint[:url]&.split('/')
1055
+ first_endpoint_parts ||= endpoint_parts
1047
1056
  end
1048
- next if ::Brick.routes_done
1057
+ end
1058
+ return if ::Brick.routes_done
1049
1059
 
1050
- if Object.const_defined?('Rswag::Ui')
1051
- if doc_endpoints.present?
1052
- if rswag_path && first_endpoint_parts
1053
- puts "API documentation now available when navigating to: /#{first_endpoint_parts&.find(&:present?)}/index.html"
1054
- else
1055
- puts "In order to make documentation available you can put this into your routes.rb:"
1056
- puts " mount Rswag::Ui::Engine => '/#{first_endpoint_parts&.find(&:present?) || 'api-docs'}'"
1057
- end
1060
+ if Object.const_defined?('Rswag::Ui')
1061
+ if doc_endpoints.present?
1062
+ if rswag_path && first_endpoint_parts
1063
+ puts "API documentation now available when navigating to: /#{first_endpoint_parts&.find(&:present?)}/index.html"
1058
1064
  else
1059
- sample_path = rswag_path || '/api-docs'
1065
+ puts "In order to make documentation available you can put this into your routes.rb:"
1066
+ puts " mount Rswag::Ui::Engine => '/#{first_endpoint_parts&.find(&:present?) || 'api-docs'}'"
1067
+ end
1068
+ else
1069
+ sample_path = rswag_path || '/api-docs'
1070
+ puts
1071
+ puts "Brick: rswag-ui gem detected -- to make OpenAPI 3.0 documentation available from a path such as '#{sample_path}/v1/swagger.json',"
1072
+ puts ' put code such as this in an initializer:'
1073
+ puts ' Rswag::Ui.configure do |config|'
1074
+ puts " config.swagger_endpoint '#{sample_path}/v1/swagger.json', 'API V1 Docs'"
1075
+ puts ' end'
1076
+ unless rswag_path
1060
1077
  puts
1061
- puts "Brick: rswag-ui gem detected -- to make OpenAPI 3.0 documentation available from a path such as '#{sample_path}/v1/swagger.json',"
1062
- puts ' put code such as this in an initializer:'
1063
- puts ' Rswag::Ui.configure do |config|'
1064
- puts " config.swagger_endpoint '#{sample_path}/v1/swagger.json', 'API V1 Docs'"
1065
- puts ' end'
1066
- unless rswag_path
1067
- puts
1068
- puts ' and put this into your routes.rb:'
1069
- puts " mount Rswag::Ui::Engine => '/api-docs'"
1070
- end
1078
+ puts ' and put this into your routes.rb:'
1079
+ puts " mount Rswag::Ui::Engine => '/api-docs'"
1071
1080
  end
1072
1081
  end
1082
+ end
1073
1083
 
1074
- puts "\n" if tables.present? || views.present?
1075
- if tables.present?
1076
- puts "Classes that can be built from tables:#{' ' * (table_class_length - 38)} Path:"
1077
- puts "======================================#{' ' * (table_class_length - 38)} ====="
1078
- ::Brick.display_classes(controller_prefix, tables, table_class_length)
1079
- end
1080
- if views.present?
1081
- puts "Classes that can be built from views:#{' ' * (view_class_length - 37)} Path:"
1082
- puts "=====================================#{' ' * (view_class_length - 37)} ====="
1083
- ::Brick.display_classes(controller_prefix, views, view_class_length)
1084
- end
1084
+ puts "\n" if tables.present? || views.present?
1085
+ if tables.present?
1086
+ puts "Classes that can be built from tables:#{' ' * (table_class_length - 38)} Path:"
1087
+ puts "======================================#{' ' * (table_class_length - 38)} ====="
1088
+ ::Brick.display_classes(controller_prefix, tables, table_class_length)
1089
+ end
1090
+ if views.present?
1091
+ puts "Classes that can be built from views:#{' ' * (view_class_length - 37)} Path:"
1092
+ puts "=====================================#{' ' * (view_class_length - 37)} ====="
1093
+ ::Brick.display_classes(controller_prefix, views, view_class_length)
1085
1094
  end
1086
- super
1087
1095
  ::Brick.routes_done = true
1088
1096
  end
1089
1097
  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.160
4
+ version: 1.0.162
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-08-08 00:00:00.000000000 Z
11
+ date: 2023-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord