motor-admin 0.4.38 → 0.5.0
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/app/controllers/motor/data_controller.rb +1 -0
- data/lib/motor/active_record_utils/active_record_filter.rb +40 -28
- data/lib/motor/configs/sync_from_file.rb +3 -1
- data/lib/motor/queries/run_query.rb +1 -1
- data/lib/motor/resources/fetch_configured_model.rb +36 -17
- data/lib/motor/version.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: d731a6842770c8a860df2506eefb38ba5aa71775b0b1ac8f8fc237732443a9d1
|
|
4
|
+
data.tar.gz: 8ffba29d356aafbb68067f5b0e85e2081a846a375437b54ca9e7d125797aa3fa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cf9e0ea1f7ba7bd55ccf448ebf9176d48d515fb9bbddf0f9a465f02db0b6b56e839c2e89fc66f84ce5cafaa60b811cfff922d45fef555e44959822b24944bc20
|
|
7
|
+
data.tar.gz: 7404c78cb16701a090799a9f7ff0bdc3b67ced5e3e4c675db9796ce9495cce72298f6b124bc612430f2a73e3aef6a6355c14b3b6105ee5bd3d582ad664e9f481
|
|
@@ -340,41 +340,53 @@ module ActiveRecord
|
|
|
340
340
|
if relation.polymorphic?
|
|
341
341
|
value = value.dup
|
|
342
342
|
klass = value.delete(:as).safe_constantize
|
|
343
|
+
new_trail = relation_trail + ["#{klass.table_name}_as_#{relation.name}"]
|
|
343
344
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
))
|
|
352
|
-
builder.build_from_filter_hash(value, relation_trail + ["#{klass.table_name}_as_#{relation.name}"],
|
|
353
|
-
alias_tracker)
|
|
345
|
+
arel_table = alias_tracker.aliased_table_for_relation(new_trail, klass.arel_table) do
|
|
346
|
+
klass.arel_table.name
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
metadata = build_table_metadata(klass, arel_table, relation)
|
|
350
|
+
builder = self.class.new(metadata)
|
|
351
|
+
builder.build_from_filter_hash(value, new_trail, alias_tracker)
|
|
354
352
|
else
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
builder.build_from_filter_hash(value,
|
|
353
|
+
new_trail = relation_trail + [relation.name]
|
|
354
|
+
|
|
355
|
+
arel_table = alias_tracker.aliased_table_for_relation(new_trail, relation.klass.arel_table) do
|
|
356
|
+
relation.alias_candidate(table.arel_table.name || relation.klass.arel_table)
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
metadata = build_table_metadata(relation.klass, arel_table, relation)
|
|
360
|
+
builder = self.class.new(metadata)
|
|
361
|
+
builder.build_from_filter_hash(value, new_trail, alias_tracker)
|
|
364
362
|
end
|
|
365
363
|
end
|
|
366
364
|
|
|
367
365
|
def expand_filter_for_join_table(relation, value, relation_trail, alias_tracker)
|
|
368
366
|
relation = relation.active_record._reflections[relation.active_record._reflections[relation.name.to_s].send(:delegate_reflection).options[:through].to_s]
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
builder.build_from_filter_hash(value,
|
|
367
|
+
new_trail = relation_trail + [relation.name]
|
|
368
|
+
|
|
369
|
+
arel_table = alias_tracker.aliased_table_for_relation(new_trail, relation.klass.arel_table) do
|
|
370
|
+
relation.alias_candidate(table.arel_table.name || relation.klass.arel_table)
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
metadata = build_table_metadata(relation.klass, arel_table, relation)
|
|
374
|
+
builder = self.class.new(metadata)
|
|
375
|
+
builder.build_from_filter_hash(value, new_trail, alias_tracker)
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
private
|
|
379
|
+
|
|
380
|
+
def build_table_metadata(klass, arel_table, reflection = nil)
|
|
381
|
+
if table_metadata_supports_reflection?
|
|
382
|
+
::ActiveRecord::TableMetadata.new(klass, arel_table, reflection)
|
|
383
|
+
else
|
|
384
|
+
::ActiveRecord::TableMetadata.new(klass, arel_table)
|
|
385
|
+
end
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
def table_metadata_supports_reflection?
|
|
389
|
+
@table_metadata_supports_reflection ||= ::ActiveRecord::TableMetadata.instance_method(:initialize).arity != 2
|
|
378
390
|
end
|
|
379
391
|
end
|
|
380
392
|
end
|
|
@@ -23,7 +23,9 @@ module Motor
|
|
|
23
23
|
|
|
24
24
|
next unless file_timestamp
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
cache_key = file_timestamp.to_s
|
|
27
|
+
|
|
28
|
+
unless FILE_TIMESTAMPS_STORE.exist?(cache_key)
|
|
27
29
|
Motor::Configs::SyncFromHash.call(
|
|
28
30
|
YAML.safe_load(file.read, permitted_classes: [Time, Date])
|
|
29
31
|
)
|
|
@@ -114,36 +114,55 @@ module Motor
|
|
|
114
114
|
|
|
115
115
|
columns_hash =
|
|
116
116
|
columns.each_with_object({}) do |column, acc|
|
|
117
|
-
acc[column[:name]] =
|
|
118
|
-
if Rails.version.to_f >= 7.2
|
|
119
|
-
base_column.class.new(
|
|
120
|
-
column[:name],
|
|
121
|
-
nil,
|
|
122
|
-
base_column.sql_type_metadata.class.new(
|
|
123
|
-
ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: column[:column_type],
|
|
124
|
-
type: column[:column_type].to_sym))
|
|
125
|
-
)
|
|
126
|
-
else
|
|
127
|
-
ActiveRecord::ConnectionAdapters::Column.new(
|
|
128
|
-
column[:name],
|
|
129
|
-
nil,
|
|
130
|
-
ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: column[:column_type],
|
|
131
|
-
type: column[:column_type].to_sym)
|
|
132
|
-
)
|
|
133
|
-
end
|
|
117
|
+
acc[column[:name]] = synthesize_column(base_column, column[:name], column[:column_type])
|
|
134
118
|
end
|
|
135
119
|
|
|
136
120
|
klass.instance_variable_set(:@__motor_custom_sql_columns_hash, columns_hash)
|
|
137
121
|
|
|
138
122
|
# rubocop:disable Naming/MemoizedInstanceVariableName
|
|
139
123
|
klass.instance_eval do
|
|
124
|
+
# Expose custom_sql columns for reading/type-casting, but keep persistence
|
|
125
|
+
# behavior based only on real DB columns.
|
|
140
126
|
def columns_hash
|
|
141
127
|
@__motor__columns_hash ||= @__motor_custom_sql_columns_hash.merge(super)
|
|
142
128
|
end
|
|
129
|
+
|
|
130
|
+
# Only real DB columns should be considered for persistence and strong params.
|
|
131
|
+
def column_names
|
|
132
|
+
connection.schema_cache.columns_hash(table_name).keys
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Same for the columns collection used by AR internals.
|
|
136
|
+
def columns
|
|
137
|
+
connection.schema_cache.columns(table_name)
|
|
138
|
+
end
|
|
143
139
|
end
|
|
144
140
|
# rubocop:enable Naming/MemoizedInstanceVariableName
|
|
145
141
|
end
|
|
146
142
|
|
|
143
|
+
def synthesize_column(template_column, name, sql_type)
|
|
144
|
+
column = template_column.dup
|
|
145
|
+
|
|
146
|
+
generic_meta = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(
|
|
147
|
+
sql_type: sql_type,
|
|
148
|
+
type: sql_type.to_sym
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
adapter_meta = template_column.sql_type_metadata.class.new(generic_meta)
|
|
152
|
+
|
|
153
|
+
begin
|
|
154
|
+
cast_type = ActiveRecord::Type.lookup(sql_type.to_sym)
|
|
155
|
+
rescue StandardError
|
|
156
|
+
cast_type = ActiveRecord::Type.lookup(:string)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
column.instance_variable_set(:@name, name)
|
|
160
|
+
column.instance_variable_set(:@sql_type_metadata, adapter_meta)
|
|
161
|
+
column.instance_variable_set(:@cast_type, cast_type)
|
|
162
|
+
|
|
163
|
+
column
|
|
164
|
+
end
|
|
165
|
+
|
|
147
166
|
def define_column_reflections(klass, config)
|
|
148
167
|
config.fetch(:columns, []).each do |column|
|
|
149
168
|
reference = column[:reference]
|
data/lib/motor/version.rb
CHANGED