brick 1.0.10 → 1.0.13
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/config.rb +1 -1
- data/lib/brick/extensions.rb +27 -6
- data/lib/brick/frameworks/rails/engine.rb +11 -7
- data/lib/brick/version_number.rb +1 -1
- data/lib/generators/brick/install_generator.rb +7 -5
- 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: 2c22e9b6dcc1ca819d7cdc6852def21d10e5c5c23f6fc7489b1fe5ae52b6c68e
|
4
|
+
data.tar.gz: 2242f7c0045e294fc505a479054a43d7d4355a0f7b6bf8407122f6f426eea541
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b42dcae433ac8c0fbc91dbf9952451548af6e72eadb466f98c8c6d084be7217df192aa6fc141a18d1e76bd25a551746cf155799045d66f88f41ede99b36b39e
|
7
|
+
data.tar.gz: 7ab155441e2868af3fe0b2a5339ec6614c18ff9d641a076f678ef6baa7b943cad88c97443db3c70506206c54f2b754a1892490d977f3e714fb66c889fe107fa5
|
data/lib/brick/config.rb
CHANGED
data/lib/brick/extensions.rb
CHANGED
@@ -137,7 +137,26 @@ module ActiveRecord
|
|
137
137
|
alias _brick_find_sti_class find_sti_class
|
138
138
|
def find_sti_class(type_name)
|
139
139
|
::Brick.sti_models[type_name] = { base: self } unless type_name.blank?
|
140
|
-
|
140
|
+
module_prefixes = type_name.split('::')
|
141
|
+
module_prefixes.unshift('') unless module_prefixes.first.blank?
|
142
|
+
candidate_file = Rails.root.join('app/models' + module_prefixes.map(&:underscore).join('/') + '.rb')
|
143
|
+
if File.exists?(candidate_file)
|
144
|
+
# Find this STI class normally
|
145
|
+
_brick_find_sti_class(type_name)
|
146
|
+
else
|
147
|
+
# Build missing prefix modules if they don't yet exist
|
148
|
+
this_module = Object
|
149
|
+
module_prefixes[1..-2].each do |module_name|
|
150
|
+
mod = if this_module.const_defined?(module_name)
|
151
|
+
this_module.const_get(module_name)
|
152
|
+
else
|
153
|
+
this_module.const_set(module_name.to_sym, Module.new)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
# Build missing prefix modules if they don't yet exist
|
157
|
+
this_module.const_set(module_prefixes.last.to_sym, klass = Class.new(self))
|
158
|
+
klass
|
159
|
+
end
|
141
160
|
end
|
142
161
|
end
|
143
162
|
end
|
@@ -161,7 +180,8 @@ class Object
|
|
161
180
|
return Object._brick_const_missing(*args) if ActiveSupport::Dependencies.search_for_file(class_name.underscore)
|
162
181
|
|
163
182
|
relations = ::Brick.instance_variable_get(:@relations)[ActiveRecord::Base.connection_pool.object_id] || {}
|
164
|
-
|
183
|
+
is_controllers_enabled = ::Brick.enable_controllers? || (ENV['RAILS_ENV'] || ENV['RACK_ENV']) == 'development'
|
184
|
+
result = if is_controllers_enabled && class_name.end_with?('Controller') && (plural_class_name = class_name[0..-11]).length.positive?
|
165
185
|
# Otherwise now it's up to us to fill in the gaps
|
166
186
|
if (model = ActiveSupport::Inflector.singularize(plural_class_name).constantize)
|
167
187
|
# if it's a controller and no match or a model doesn't really use the same table name, eager load all models and try to find a model class of the right name.
|
@@ -382,7 +402,6 @@ class Object
|
|
382
402
|
end
|
383
403
|
|
384
404
|
def _brick_get_hm_assoc_name(relation, hm_assoc)
|
385
|
-
binding.pry if hm_assoc.nil?
|
386
405
|
if relation[:hm_counts][hm_assoc[:assoc_name]]&.> 1
|
387
406
|
[ActiveSupport::Inflector.pluralize(hm_assoc[:alternate_name]), true]
|
388
407
|
else
|
@@ -532,10 +551,12 @@ module ActiveRecord::ConnectionHandling
|
|
532
551
|
end
|
533
552
|
end
|
534
553
|
|
535
|
-
puts "
|
554
|
+
puts "\nClasses that can be built from tables:"
|
536
555
|
relations.select { |_k, v| !v.key?(:isView) }.keys.each { |k| puts ActiveSupport::Inflector.singularize(k).camelize }
|
537
|
-
|
538
|
-
|
556
|
+
unless (views = relations.select { |_k, v| v.key?(:isView) }).empty?
|
557
|
+
puts "\nClasses that can be built from views:"
|
558
|
+
views.keys.each { |k| puts ActiveSupport::Inflector.singularize(k).camelize }
|
559
|
+
end
|
539
560
|
# pp relations; nil
|
540
561
|
|
541
562
|
# relations.keys.each { |k| ActiveSupport::Inflector.singularize(k).camelize.constantize }
|
@@ -8,9 +8,9 @@ module Brick
|
|
8
8
|
config.brick = ActiveSupport::OrderedOptions.new
|
9
9
|
ActiveSupport.on_load(:before_initialize) do |app|
|
10
10
|
::Brick.enable_models = app.config.brick.fetch(:enable_models, true)
|
11
|
-
::Brick.enable_controllers = app.config.brick.fetch(:enable_controllers,
|
12
|
-
::Brick.enable_views = app.config.brick.fetch(:enable_views,
|
13
|
-
::Brick.enable_routes = app.config.brick.fetch(:enable_routes,
|
11
|
+
::Brick.enable_controllers = app.config.brick.fetch(:enable_controllers, false)
|
12
|
+
::Brick.enable_views = app.config.brick.fetch(:enable_views, false)
|
13
|
+
::Brick.enable_routes = app.config.brick.fetch(:enable_routes, false)
|
14
14
|
::Brick.skip_database_views = app.config.brick.fetch(:skip_database_views, false)
|
15
15
|
|
16
16
|
# Specific database tables and views to omit when auto-creating models
|
@@ -37,7 +37,7 @@ module Brick
|
|
37
37
|
# ====================================
|
38
38
|
# Dynamically create generic templates
|
39
39
|
# ====================================
|
40
|
-
if ::Brick.enable_views?
|
40
|
+
if ::Brick.enable_views? || (ENV['RAILS_ENV'] || ENV['RACK_ENV']) == 'development'
|
41
41
|
ActionView::LookupContext.class_exec do
|
42
42
|
alias :_brick_template_exists? :template_exists?
|
43
43
|
def template_exists?(*args, **options)
|
@@ -209,7 +209,11 @@ function changeout(href, param, value) {
|
|
209
209
|
<% next if k == '#{pk}' || ::Brick.config.metadata_columns.include?(k) %>
|
210
210
|
<td>
|
211
211
|
<% if (bt = bts[k]) %>
|
212
|
-
|
212
|
+
<%# Instead of just 'bt_obj we have to put in all of this junk:
|
213
|
+
# send(\"#\{bt_obj_class = bt[1].name.underscore\}_path\".to_sym, bt_obj.send(bt[1].primary_key.to_sym))
|
214
|
+
# Otherwise we get stuff like:
|
215
|
+
# ActionView::Template::Error (undefined method `vehicle_path' for #<ActionView::Base:0x0000000033a888>) %>
|
216
|
+
<%= bt_obj = bt[1].find_by(bt.last => val); link_to(bt_obj.brick_descrip, send(\"#\{bt_obj_class = bt[1].name.underscore\}_path\".to_sym, bt_obj.send(bt[1].primary_key.to_sym))) if bt_obj %>
|
213
217
|
<% else %>
|
214
218
|
<%= val %>
|
215
219
|
<% end %>
|
@@ -244,7 +248,7 @@ function changeout(href, param, value) {
|
|
244
248
|
</th>
|
245
249
|
<td>
|
246
250
|
<% if (bt = bts[k]) %>
|
247
|
-
<%= bt_obj = bt[1].find_by(bt.last => val); link_to(bt_obj.brick_descrip, bt_obj) if bt_obj %>
|
251
|
+
<%= bt_obj = bt[1].find_by(bt.last => val); link_to(bt_obj.brick_descrip, send(\"#\{bt_obj_class = bt[1].name.underscore\}_path\".to_sym, bt_obj.send(bt[1].primary_key.to_sym))) if bt_obj %>
|
248
252
|
<% else %>
|
249
253
|
<%= val %>
|
250
254
|
<% end %>
|
@@ -279,7 +283,7 @@ function changeout(href, param, value) {
|
|
279
283
|
end
|
280
284
|
end
|
281
285
|
|
282
|
-
if ::Brick.enable_routes?
|
286
|
+
if ::Brick.enable_routes? || (ENV['RAILS_ENV'] || ENV['RACK_ENV']) == 'development'
|
283
287
|
ActionDispatch::Routing::RouteSet.class_exec do
|
284
288
|
alias _brick_finalize_routeset! finalize!
|
285
289
|
def finalize!(*args, **options)
|
data/lib/brick/version_number.rb
CHANGED
@@ -80,11 +80,13 @@ module Brick
|
|
80
80
|
# # Settings for the Brick gem
|
81
81
|
# # (By default this auto-creates models, controllers, views, and routes on-the-fly.)
|
82
82
|
|
83
|
-
# # Normally
|
84
|
-
#
|
83
|
+
# # Normally all are enabled in development mode, and for security reasons only models are enabled in production
|
84
|
+
# # and test. This allows you to either (a) turn off models entirely, or (b) enable controllers, views, and routes
|
85
|
+
# # in production.
|
86
|
+
# Brick.enable_routes = true # Setting this to \"false\" will disable routes in development
|
85
87
|
# Brick.enable_models = false
|
86
|
-
# Brick.enable_controllers = false
|
87
|
-
# Brick.enable_views = false
|
88
|
+
# Brick.enable_controllers = true # Setting this to \"false\" will disable controllers in development
|
89
|
+
# Brick.enable_views = true # Setting this to \"false\" will disable views in development
|
88
90
|
|
89
91
|
# # By default models are auto-created for database views, and set to be read-only. This can be skipped.
|
90
92
|
# Brick.skip_database_views = true
|
@@ -124,7 +126,7 @@ module Brick
|
|
124
126
|
# # part of a has_many :through association.) If you want to use different exclusion columns than our defaults
|
125
127
|
# # then this setting resets that list. For instance, here is an override that is useful in the Sakila sample
|
126
128
|
# # database:
|
127
|
-
# Brick.metadata_columns = ['
|
129
|
+
# Brick.metadata_columns = ['last_update']
|
128
130
|
|
129
131
|
# # A simple DSL is available to allow more user-friendly display of objects. Normally a user object might be shown
|
130
132
|
# # as its first non-metadata column, or if that is not available then something like \"User #45\" where 45 is that
|
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.13
|
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-03-
|
11
|
+
date: 2022-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|