brick 1.0.28 → 1.0.29
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/extensions.rb +10 -5
- data/lib/brick/frameworks/rails/engine.rb +11 -6
- data/lib/brick/version_number.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a312c2fd5baf0793b4bb4143167b4399c70a514991206a611d525d0784de95b
|
4
|
+
data.tar.gz: bb1af47d2d073dab2c046ff9757fb5db9447f02dd0688330ad7ac8ad678d6751
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbfabaf60608b2094e9903cb538bab00706f434f94289b9647320bb128adf0b34317a6404ace34897cf4b2f91700ebd7c028a12b4072ba1ebf9de3380f75add3
|
7
|
+
data.tar.gz: 6e5444ac763c71de71fc1aca64cdb41db6276f1df57f5b556b03bad0b743373f2720865ba7c6ce36f9887d77ffee3b091f32d233121742c4786ca21e8d512705
|
data/lib/brick/extensions.rb
CHANGED
@@ -72,7 +72,11 @@ module ActiveRecord
|
|
72
72
|
|
73
73
|
pk = primary_key.is_a?(String) ? [primary_key] : primary_key || []
|
74
74
|
# Just return [] if we're missing any part of the primary key. (PK is usually just "id")
|
75
|
-
|
75
|
+
if relation && pk.present?
|
76
|
+
@_brick_primary_key ||= pk.any? { |pk_part| !relation[:cols].key?(pk_part) } ? [] : pk
|
77
|
+
else # No definitive key yet, so return what we can without setting the instance variable
|
78
|
+
pk
|
79
|
+
end
|
76
80
|
end
|
77
81
|
|
78
82
|
# Used to show a little prettier name for an object
|
@@ -303,7 +307,7 @@ module ActiveRecord
|
|
303
307
|
# %%% Skip the metadata columns
|
304
308
|
if selects&.empty? # Default to all columns
|
305
309
|
columns.each do |col|
|
306
|
-
selects << "#{table.name}
|
310
|
+
selects << "\"#{table.name}\".\"#{col.name}\""
|
307
311
|
end
|
308
312
|
end
|
309
313
|
|
@@ -361,7 +365,7 @@ module ActiveRecord
|
|
361
365
|
v1.map { |x| [translations[x[0..-2].map(&:to_s).join('.')], x.last] }.each_with_index do |sel_col, idx|
|
362
366
|
field_tbl_name = field_tbl_names[v.first][sel_col.first] ||= shift_or_first(chains[sel_col.first])
|
363
367
|
|
364
|
-
selects << "#{"#{field_tbl_name}
|
368
|
+
selects << "#{"\"#{field_tbl_name}\".\"#{sel_col.last}\""} AS \"#{(col_alias = "_brfk_#{v.first}__#{sel_col.last}")}\""
|
365
369
|
v1[idx] << col_alias
|
366
370
|
end
|
367
371
|
|
@@ -369,7 +373,7 @@ module ActiveRecord
|
|
369
373
|
# Accommodate composite primary key by allowing id_col to come in as an array
|
370
374
|
((id_col = k1.primary_key).is_a?(Array) ? id_col : [id_col]).each do |id_part|
|
371
375
|
id_for_tables[v.first] << if id_part
|
372
|
-
selects << "#{"#{tbl_name}
|
376
|
+
selects << "#{"\"#{tbl_name}\".\"#{id_part}\""} AS \"#{(id_alias = "_brfk_#{v.first}__#{id_part}")}\""
|
373
377
|
id_alias
|
374
378
|
end
|
375
379
|
end
|
@@ -610,6 +614,7 @@ class Object
|
|
610
614
|
new_model_class.primary_key = (pk_sym = our_pks.first.to_sym)
|
611
615
|
code << " self.primary_key = #{pk_sym.inspect}\n"
|
612
616
|
end
|
617
|
+
_brick_primary_key(relation) # Set the newly-found PK in the instance variable
|
613
618
|
else
|
614
619
|
code << " # Could not identify any column(s) to use as a primary key\n" unless is_view
|
615
620
|
end
|
@@ -751,7 +756,7 @@ class Object
|
|
751
756
|
def build_controller(class_name, plural_class_name, model, relations)
|
752
757
|
table_name = ActiveSupport::Inflector.underscore(plural_class_name)
|
753
758
|
singular_table_name = ActiveSupport::Inflector.singularize(table_name)
|
754
|
-
pk = model._brick_primary_key(relations
|
759
|
+
pk = model._brick_primary_key(relations.fetch(table_name, nil))
|
755
760
|
|
756
761
|
code = +"class #{class_name} < ApplicationController\n"
|
757
762
|
built_controller = Class.new(ActionController::Base) do |new_controller_class|
|
@@ -83,7 +83,7 @@ module Brick
|
|
83
83
|
return _brick_find_template(*args, **options) unless @_brick_model
|
84
84
|
|
85
85
|
model_name = @_brick_model.name
|
86
|
-
pk = @_brick_model._brick_primary_key(::Brick.relations
|
86
|
+
pk = @_brick_model._brick_primary_key(::Brick.relations.fetch(model_name, nil))
|
87
87
|
obj_name = model_name.underscore
|
88
88
|
table_name = model_name.pluralize.underscore
|
89
89
|
template_link = nil
|
@@ -207,7 +207,13 @@ input[type=submit] {
|
|
207
207
|
val.is_a?(String) && val.length == 60 && val.start_with?('$2a$')
|
208
208
|
end
|
209
209
|
def hide_bcrypt(val)
|
210
|
-
is_bcrypt?(val)
|
210
|
+
if is_bcrypt?(val)
|
211
|
+
'(hidden)'
|
212
|
+
elsif val.is_a?(String) && val.encoding.name != 'UTF-8'
|
213
|
+
val[0..1000].force_encoding('UTF-8')
|
214
|
+
else
|
215
|
+
val
|
216
|
+
end
|
211
217
|
end %>"
|
212
218
|
|
213
219
|
if ['index', 'show', 'update'].include?(args.first)
|
@@ -388,7 +394,7 @@ function changeout(href, param, value) {
|
|
388
394
|
<table id=\"#{table_name}\">
|
389
395
|
<thead><tr>#{'<th></th>' if pk.present?}
|
390
396
|
<% @#{table_name}.columns.map(&:name).each do |col| %>
|
391
|
-
<% next if #{pk.inspect}.include?(col) || ::Brick.config.metadata_columns.include?(col) || poly_cols.include?(col) %>
|
397
|
+
<% next if #{(pk || []).inspect}.include?(col) || ::Brick.config.metadata_columns.include?(col) || poly_cols.include?(col) %>
|
392
398
|
<th>
|
393
399
|
<% if (bt = bts[col]) %>
|
394
400
|
BT <%
|
@@ -409,7 +415,7 @@ function changeout(href, param, value) {
|
|
409
415
|
<tr>#{"
|
410
416
|
<td><%= link_to '⇛', #{obj_name}_path(#{obj_pk}), { class: 'big-arrow' } %></td>" if obj_pk}
|
411
417
|
<% #{obj_name}.attributes.each do |k, val| %>
|
412
|
-
<% next if #{obj_pk.inspect}.include?(k) || ::Brick.config.metadata_columns.include?(k) || poly_cols.include?(k) || k.start_with?('_brfk_') || (k.start_with?('_br_') && (k.length == 63 || k.end_with?('_ct'))) %>
|
418
|
+
<% next if #{(obj_pk || []).inspect}.include?(k) || ::Brick.config.metadata_columns.include?(k) || poly_cols.include?(k) || k.start_with?('_brfk_') || (k.start_with?('_br_') && (k.length == 63 || k.end_with?('_ct'))) %>
|
413
419
|
<td>
|
414
420
|
<% if (bt = bts[k]) %>
|
415
421
|
<%# binding.pry # Postgres column names are limited to 63 characters %>
|
@@ -456,8 +462,7 @@ function changeout(href, param, value) {
|
|
456
462
|
<% has_fields = false
|
457
463
|
@#{obj_name}.attributes.each do |k, val| %>
|
458
464
|
<tr>
|
459
|
-
|
460
|
-
<% next if #{pk}.include?(k) || ::Brick.config.metadata_columns.include?(k) %>
|
465
|
+
<% next if #{(pk || []).inspect}.include?(k) || ::Brick.config.metadata_columns.include?(k) %>
|
461
466
|
<th class=\"show-field\">
|
462
467
|
<% has_fields = true
|
463
468
|
if (bt = bts[k])
|
data/lib/brick/version_number.rb
CHANGED