brick 1.0.11 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brick/extensions.rb +22 -2
- data/lib/brick/frameworks/rails/engine.rb +11 -7
- data/lib/brick/version_number.rb +1 -1
- data/lib/generators/brick/install_generator.rb +6 -4
- 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: f7c3e4032e5e9f111839b7ff6e6378e4937edeabeb0edcf480cf6c50e79e599a
|
4
|
+
data.tar.gz: 1a1e5b096a3f6fff0f2c49c6be6abcfbe012f3e24fccf0ea6b307b58d9cbc076
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dbd885a2c4dc9666378a69423179ca2085c89b6b6120d21ef8d3274f229a88306f54868b8a18aad8e55a37a71bc9b78dff073263bb86fd89d5b982acf8d5210
|
7
|
+
data.tar.gz: 952f94f89445170f26fad10357ede0df7c9053d034ddb552b1e9cba884cbdf0325325cb29a2248fac4e9de3bd8c41619fc9612d44435e6ccb808a16fd018d8dc
|
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 = Rails.development? || ::Brick.enable_controllers?
|
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.
|
@@ -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 Rails.development? || ::Brick.enable_views?
|
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 Rails.development? || ::Brick.enable_routes?
|
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
|
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.12
|
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
|