brick 1.0.84 → 1.0.85

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: 07b4deda161c3a94822dd4c953d1c3983eb7c4eeed3106c7037a5f6b5c006f9d
4
- data.tar.gz: bd5bcd1255bd5e3c13da8abca6bc9b73b5cd17880f90bbbb6b3b6e01c7f9331d
3
+ metadata.gz: 9b174d2fbdbef5d71921aa28da8fe7f943eb095fc3dd3c95efb7ac752681917e
4
+ data.tar.gz: daf09d491031d7f30171b85e25f68ceb36e73df5b183b86ab8269474651fb4b6
5
5
  SHA512:
6
- metadata.gz: 0da12600c16ad515c1be1129940eba12e99754afebb206784384084dfee66c657ee2e6c9319f3b8f5d3a57c42f0f501ae55d967dd51b3f12b608579f98b5141d
7
- data.tar.gz: 75a9e6de7852fb5aab7c6b7a4a72e2e2af733ad18432fe91f04207138e6192dcbc716e5a38e18819d22cfe2370acdd55c87d25e54b49f86493e52b1f3625dfa3
6
+ metadata.gz: 697528d1c7445130ab1cae24b76ad154f72e1a770c26f50ab6bf6f40fe98045c775311c32460e4bfca0869567873166733f0b488eb3e67d9f1a11eb271407032
7
+ data.tar.gz: ba9004f32e27f8104eb3547bec82682011a2f328e6081774e6afd4485ff14ec10cc5992bcf539fbc328131a5bd5dbde5804b18bcf73f26108ab9a1f9f48b49b7
data/lib/brick/config.rb CHANGED
@@ -20,6 +20,23 @@ module Brick
20
20
  @serializer = Brick::Serializers::YAML
21
21
  end
22
22
 
23
+ def mode
24
+ @mutex.synchronize do
25
+ case @brick_mode
26
+ when nil, :development
27
+ (::Rails.env == 'development' || ENV.key?('BRICK')) ? :on : nil
28
+ when :diag_env
29
+ ENV.key?('BRICK') ? :on : nil
30
+ else
31
+ @brick_mode
32
+ end
33
+ end
34
+ end
35
+
36
+ def mode=(setting)
37
+ @mutex.synchronize { @brick_mode = setting unless @brick_mode == :on }
38
+ end
39
+
23
40
  # Any path prefixing to apply to all auto-generated Brick routes
24
41
  def path_prefix
25
42
  @mutex.synchronize { @path_prefix }
@@ -31,7 +48,8 @@ module Brick
31
48
 
32
49
  # Indicates whether Brick models are on or off. Default: true.
33
50
  def enable_models
34
- @mutex.synchronize { !!@enable_models }
51
+ brick_mode = mode
52
+ @mutex.synchronize { brick_mode == :on && (@enable_models.nil? || @enable_models) }
35
53
  end
36
54
 
37
55
  def enable_models=(enable)
@@ -40,7 +58,8 @@ module Brick
40
58
 
41
59
  # Indicates whether Brick controllers are on or off. Default: true.
42
60
  def enable_controllers
43
- @mutex.synchronize { !!@enable_controllers }
61
+ brick_mode = mode
62
+ @mutex.synchronize { brick_mode == :on && (@enable_controllers.nil? || @enable_controllers) }
44
63
  end
45
64
 
46
65
  def enable_controllers=(enable)
@@ -49,7 +68,8 @@ module Brick
49
68
 
50
69
  # Indicates whether Brick views are on or off. Default: true.
51
70
  def enable_views
52
- @mutex.synchronize { !!@enable_views }
71
+ brick_mode = mode
72
+ @mutex.synchronize { brick_mode == :on && (@enable_views.nil? || @enable_views) }
53
73
  end
54
74
 
55
75
  def enable_views=(enable)
@@ -58,7 +78,8 @@ module Brick
58
78
 
59
79
  # Indicates whether Brick routes are on or off. Default: true.
60
80
  def enable_routes
61
- @mutex.synchronize { !!@enable_routes }
81
+ brick_mode = mode
82
+ @mutex.synchronize { brick_mode == :on && (@enable_routes.nil? || @enable_routes) }
62
83
  end
63
84
 
64
85
  def enable_routes=(enable)
@@ -766,7 +766,7 @@ JOIN (SELECT #{hm_selects.map { |s| "#{'br_t0.' if from_clause}#{s}" }.join(', '
766
766
 
767
767
  alias _brick_find_sti_class find_sti_class
768
768
  def find_sti_class(type_name)
769
- if ::Brick.sti_models.key?(type_name)
769
+ if ::Brick.sti_models.key?(type_name ||= name)
770
770
  _brick_find_sti_class(type_name)
771
771
  else
772
772
  # This auto-STI is more of a brute-force approach, building modules where needed
@@ -816,6 +816,8 @@ end
816
816
  if Object.const_defined?('ActionView')
817
817
  module ActionView::Helpers::FormTagHelper
818
818
  def link_to_brick(*args, **kwargs)
819
+ return unless ::Brick.config.mode == :on
820
+
819
821
  text = (args.first.is_a?(String) && args.first) || args[1]
820
822
  klass_or_obj = ((args.first.is_a?(ActiveRecord::Relation) ||
821
823
  args.first.is_a?(ActiveRecord::Base) ||
@@ -860,7 +862,7 @@ if Object.const_defined?('ActionView')
860
862
  pk = (klass.primary_key || ActiveRecord::Base.primary_key).to_sym
861
863
  # Used to also have this but it's a bit too permissive to identify a primary key: (path_params.length == 1 && path_params.values.first) ||
862
864
  if ((id = (path_params[pk] || path_params[:id] || path_params["#{klass.name.underscore}_id".to_sym])) && (obj = klass.find_by(pk => id))) ||
863
- (['show', 'edit'].include?(action_name) && (obj = klass.first))
865
+ (['show', 'edit', 'update', 'destroy'].include?(action_name) && (obj = klass.first))
864
866
  obj
865
867
  else
866
868
  # %%% If there is a HMT that refers to some ___id then try to identify an appropriate filter
@@ -1633,7 +1635,11 @@ class Object
1633
1635
  code << " end\n"
1634
1636
  self.define_method :destroy do
1635
1637
  ::Brick.set_db_schema(params)
1636
- instance_variable_set("@#{singular_table_name}".to_sym, find_obj.send(:destroy))
1638
+ if (obj = find_obj).send(:destroy)
1639
+ redirect_to send("#{model._brick_index}_path".to_sym)
1640
+ else
1641
+ redirect_to send("#{model._brick_index(:singular)}_path".to_sym, obj)
1642
+ end
1637
1643
  end
1638
1644
  end
1639
1645
 
@@ -1732,10 +1738,16 @@ end
1732
1738
  # Get info on all relations during first database connection
1733
1739
  # ==========================================================
1734
1740
 
1735
- module ActiveRecord::ConnectionHandling
1741
+ if ActiveRecord.const_defined?('ConnectionHandling')
1742
+ ActiveRecord::ConnectionHandling
1743
+ else
1744
+ ActiveRecord::ConnectionAdapters::ConnectionHandler
1745
+ end.class_exec do
1736
1746
  alias _brick_establish_connection establish_connection
1737
1747
  def establish_connection(*args)
1738
1748
  conn = _brick_establish_connection(*args)
1749
+ return conn unless ::Brick.config.mode == :on
1750
+
1739
1751
  begin
1740
1752
  # Overwrite SQLite's #begin_db_transaction so it opens in IMMEDIATE mode instead of
1741
1753
  # the default DEFERRED mode.
@@ -1866,7 +1878,7 @@ module ActiveRecord::ConnectionHandling
1866
1878
  case ActiveRecord::Base.connection.adapter_name
1867
1879
  when 'PostgreSQL', 'SQLite' # These bring back a hash for each row because the query uses column aliases
1868
1880
  # schema ||= 'public' if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
1869
- ActiveRecord::Base.retrieve_schema_and_tables(sql, is_postgres, is_mssql, schema).each do |r|
1881
+ retrieve_schema_and_tables(sql, is_postgres, is_mssql, schema).each do |r|
1870
1882
  # If Apartment gem lists the table as being associated with a non-tenanted model then use whatever it thinks
1871
1883
  # is the default schema, usually 'public'.
1872
1884
  schema_name = if ::Brick.config.schema_behavior[:multitenant]
@@ -1915,7 +1927,7 @@ WHERE c.owner IN (#{::Brick.db_schemas.keys.map { |s| "'#{s}'" }.join(', ')})
1915
1927
  ORDER BY 1, 2, c.internal_column_id, acc.position"
1916
1928
  ActiveRecord::Base.execute_sql(sql, *ar_tables)
1917
1929
  else
1918
- ActiveRecord::Base.retrieve_schema_and_tables(sql)
1930
+ retrieve_schema_and_tables(sql)
1919
1931
  end
1920
1932
 
1921
1933
  schema_and_tables.each do |r|
@@ -2113,7 +2125,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
2113
2125
  else
2114
2126
  'schema_migrations'
2115
2127
  end
2116
- ar_imtn = ActiveRecord.version >= ::Gem::Version.new('5.0') ? ActiveRecord::Base.internal_metadata_table_name : ''
2128
+ ar_imtn = ActiveRecord.version >= ::Gem::Version.new('5.0') ? ActiveRecord::Base.internal_metadata_table_name : 'ar_internal_metadata'
2117
2129
  [ar_smtn, ar_imtn]
2118
2130
  end
2119
2131
 
@@ -8,10 +8,16 @@ module Brick
8
8
  # `brick_enabled_for_controller`.
9
9
  module Controller
10
10
  def self.included(controller)
11
- controller.before_action(
12
- :set_brick_enabled_for_controller,
13
- :set_brick_controller_info
14
- )
11
+ if controller.respond_to?(:before_action)
12
+ controller.before_action(
13
+ :set_brick_enabled_for_controller,
14
+ :set_brick_controller_info
15
+ )
16
+ else
17
+ controller.before_filter(
18
+ :set_brick_enabled_for_controller,
19
+ :set_brick_controller_info
20
+ )
15
21
  end
16
22
 
17
23
  protected
@@ -181,10 +181,15 @@ module Brick
181
181
  end
182
182
  end
183
183
 
184
- schema_options = ::Brick.db_schemas.keys.each_with_object(+'') { |v, s| s << "<option value=\"#{v}\">#{v}</option>" }.html_safe
184
+ apartment_default_schema = ::Brick.apartment_multitenant && Apartment.default_schema
185
+ schema_options = if ::Brick.apartment_multitenant &&
186
+ (cur_schema = Apartment::Tenant.current) != apartment_default_schema
187
+ "<option selected value=\"#{cur_schema}\">#{cur_schema}</option>"
188
+ else
189
+ ::Brick.db_schemas.keys.each_with_object(+'') { |v, s| s << "<option value=\"#{v}\">#{v}</option>" }
190
+ end.html_safe
185
191
  # %%% If we are not auto-creating controllers (or routes) then omit by default, and if enabled anyway, such as in a development
186
192
  # environment or whatever, then get either the controllers or routes list instead
187
- apartment_default_schema = ::Brick.apartment_multitenant && Apartment.default_schema
188
193
  prefix = "#{::Brick.config.path_prefix}/" if ::Brick.config.path_prefix
189
194
  table_options = (::Brick.relations.keys - ::Brick.config.exclude_tables).each_with_object({}) do |tbl, s|
190
195
  binding.pry if tbl.is_a?(Symbol)
@@ -329,6 +334,10 @@ a.big-arrow {
329
334
  color: red;
330
335
  white-space: nowrap;
331
336
  }
337
+ .danger {
338
+ background-color: red;
339
+ color: white;
340
+ }
332
341
 
333
342
  #revertTemplate {
334
343
  display: none;
@@ -446,7 +455,7 @@ var #{table_name}HtColumns;
446
455
  // This PageTransitionEvent fires when the page first loads, as well as after any other history
447
456
  // transition such as when using the browser's Back and Forward buttons.
448
457
  window.addEventListener(\"pageshow\", function() {
449
- if (schemaSelect) { // First drop-down is only present if multitenant
458
+ if (schemaSelect && schemaSelect.options.length > 1) { // First drop-down is only present if multitenant
450
459
  brickSchema = changeout(location.href, \"_brick_schema\");
451
460
  if (brickSchema) {
452
461
  [... document.getElementsByTagName(\"A\")].forEach(function (a) { a.href = changeout(a.href, \"_brick_schema\", brickSchema); });
@@ -1163,6 +1172,7 @@ end
1163
1172
  <% end %>
1164
1173
 
1165
1174
  #{unless args.first == 'new'
1175
+ confirm_are_you_sure = ActionView.version < ::Gem::Version.new('7.0') ? "data: { confirm: 'Are you sure?' }" : "form: { data: { turbo_confirm: 'Are you sure?' } }"
1166
1176
  hms_headers.each_with_object(+'') do |hm, s|
1167
1177
  # %%% Would be able to remove this when multiple foreign keys to same destination becomes bulletproof
1168
1178
  next if hm.first.options[:through] && !hm.first.through_reflection
@@ -1185,7 +1195,8 @@ end
1185
1195
  else
1186
1196
  s
1187
1197
  end
1188
- end
1198
+ end +
1199
+ "<%= button_to(\"Delete #\{@#{obj_name}.brick_descrip}\", send(\"#\{#{model_name}._brick_index(:singular)}_path\".to_sym, @#{obj_name}), { method: 'delete', class: 'danger', #{confirm_are_you_sure} }) %>"
1189
1200
  end}
1190
1201
  <% end %>
1191
1202
  #{script}"
@@ -1193,7 +1204,7 @@ end}
1193
1204
  end
1194
1205
  inline << "
1195
1206
  <% if is_includes_dates %>
1196
- <link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css\">
1207
+ <link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css\">
1197
1208
  <style>
1198
1209
  .flatpickr-calendar {
1199
1210
  background: #A0FFA0;
@@ -1207,6 +1218,11 @@ flatpickr(\".timepicker\", {enableTime: true, noCalendar: true});
1207
1218
  </script>
1208
1219
  <% end %>
1209
1220
 
1221
+ <% if false # is_includes_dropdowns %>
1222
+ <script src=\"https://cdnjs.cloudflare.com/ajax/libs/slim-select/1.27.1/slimselect.min.js\"></script>
1223
+ <link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdnjs.cloudflare.com/ajax/libs/slim-select/1.27.1/slimselect.min.css\">
1224
+ <% end %>
1225
+
1210
1226
  <% if true # @_brick_erd
1211
1227
  %>
1212
1228
  <script>
data/lib/brick/util.rb CHANGED
@@ -84,6 +84,7 @@ module Brick
84
84
 
85
85
  def self._custom_require_dir
86
86
  unless (custom_require_dir = ::Brick::Util.instance_variable_get(:@_custom_require_dir))
87
+ require 'tmpdir'
87
88
  ::Brick::Util.instance_variable_set(:@_custom_require_dir, (custom_require_dir = Dir.mktmpdir))
88
89
  # So normal Ruby require will now pick this one up
89
90
  $LOAD_PATH.unshift(custom_require_dir)
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 84
8
+ TINY = 85
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
@@ -26,27 +26,38 @@ end
26
26
  require 'brick/util'
27
27
 
28
28
  # Allow ActiveRecord < 3.2 to work with Ruby 2.7 and later
29
- if (ruby_version = ::Gem::Version.new(RUBY_VERSION)) >= ::Gem::Version.new('2.7') &&
30
- ActiveRecord.version < ::Gem::Version.new('3.2')
31
- # Remove circular reference for "now"
32
- ::Brick::Util._patch_require(
33
- 'active_support/values/time_zone.rb', '/activesupport',
34
- [' def parse(str, now=now)',
35
- ' def parse(str, now=now())']
36
- )
37
- # Remove circular reference for "reflection" for ActiveRecord 3.1
38
- if ActiveRecord.version >= ::Gem::Version.new('3.1')
29
+ if (ruby_version = ::Gem::Version.new(RUBY_VERSION)) >= ::Gem::Version.new('2.7')
30
+ if ActiveRecord.version < ::Gem::Version.new('3.2')
31
+ # Remove circular reference for "now"
39
32
  ::Brick::Util._patch_require(
40
- 'active_record/associations/has_many_association.rb', '/activerecord',
41
- ['reflection = reflection)',
42
- 'reflection = reflection())'],
43
- :HasManyAssociation # Make sure the path for this guy is available to be autoloaded
33
+ 'active_support/values/time_zone.rb', '/activesupport',
34
+ [' def parse(str, now=now)',
35
+ ' def parse(str, now=now())']
44
36
  )
37
+ # Remove circular reference for "reflection" for ActiveRecord 3.1
38
+ if ActiveRecord.version >= ::Gem::Version.new('3.1')
39
+ ::Brick::Util._patch_require(
40
+ 'active_record/associations/has_many_association.rb', '/activerecord',
41
+ ['reflection = reflection)',
42
+ 'reflection = reflection())'],
43
+ :HasManyAssociation # Make sure the path for this guy is available to be autoloaded
44
+ )
45
+ end
45
46
  end
47
+
48
+ # # Create unfrozen route path in Rails 3.2
49
+ # if ActiveRecord.version < ::Gem::Version.new('4')
50
+ # ::Brick::Util._patch_require(
51
+ # 'action_dispatch/routing/route_set.rb', '/actiondispatch',
52
+ # ["script_name.chomp('/')).to_s",
53
+ # "script_name.chomp('/')).to_s.dup"],
54
+ # :RouteSet # Make sure the path for this guy is available to be autoloaded
55
+ # )
56
+ # end
46
57
  end
47
58
 
48
59
  # Add left_outer_join! to Associations::JoinDependency and Relation::QueryMethods
49
- if ActiveRecord.version < ::Gem::Version.new('5')
60
+ if ActiveRecord.version >= ::Gem::Version.new('4') && ActiveRecord.version < ::Gem::Version.new('5')
50
61
  ::Brick::Util._patch_require(
51
62
  'active_record/associations/join_dependency.rb', '/activerecord', # /associations
52
63
  ["def join_constraints(outer_joins)
@@ -226,6 +237,11 @@ module Brick
226
237
  true
227
238
  end
228
239
 
240
+ # @api public
241
+ def mode=(setting)
242
+ Brick.config.mode = setting
243
+ end
244
+
229
245
  # Any path prefixing to apply to all auto-generated Brick routes
230
246
  # @api public
231
247
  def path_prefix=(path)
@@ -433,7 +449,7 @@ module Brick
433
449
  # This is attempted early if a brick initialiser file is found, and then again as a failsafe at the end of our engine's initialisation
434
450
  # %%% Maybe look for differences the second time 'round and just add new stuff instead of entirely deferring
435
451
  def load_additional_references
436
- return if @_additional_references_loaded
452
+ return if @_additional_references_loaded || ::Brick.config.mode != :on
437
453
 
438
454
  relations = ::Brick.relations
439
455
  if (ars = ::Brick.config.additional_references) || ::Brick.config.polymorphics
@@ -136,10 +136,16 @@ module Brick
136
136
 
137
137
  create_file(filename, "# frozen_string_literal: true
138
138
 
139
- # # Settings for the Brick gem
140
- # # (By default this auto-creates models, controllers, views, and routes on-the-fly.)
139
+ # Settings for the Brick gem
140
+ # (By default this auto-creates models, controllers, views, and routes on-the-fly.)
141
141
 
142
142
  if Object.const_defined?('Brick')
143
+ # Mode -- generally :on or :off, or only in :development. Also available is :diag_env which enables only
144
+ # when the environment variable BRICK is set.
145
+ Brick.mode = :development
146
+ # Can be further overridden by placing this line in development.rb / test.rb / production.rb:
147
+ # # Brick.mode = :on # (or :off to entirely disable)
148
+
143
149
  # # Custom path prefix to apply to all auto-generated Brick routes. Also causes auto-generated controllers
144
150
  # # to be created inside a module with the same name.
145
151
  # ::Brick.path_prefix = 'admin'
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.84
4
+ version: 1.0.85
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-24 00:00:00.000000000 Z
11
+ date: 2022-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord