motor-admin 0.2.26 → 0.2.27

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04b8a3962312d6df6ee3d75c0ad988f5b3e2011fcc4eacaedc2263739c4b8478
4
- data.tar.gz: c034290e1752bff06ea29a2ca2be696576dd46bcbb6f97a22917173e9911c5c0
3
+ metadata.gz: acd8302f343dd0ce3ccad39dd408dc90e7582fb63133cf0abfb3fa1112899cb8
4
+ data.tar.gz: 21dc6ca6b743b0499e8bf3b314465be503cfcc6ce789bd2653f8e278e72b38dc
5
5
  SHA512:
6
- metadata.gz: 56e2836e3a8723e313a0af989ccb5aa7d8577f6c5982cdc05825ed1ec4061db90a35776e329c4bdcdf4c736405ffeb4d2268131b857bbbd1cab19bdcff34a88f
7
- data.tar.gz: a05ce55494fc28825dba93861888aca1c563df270670af2e048828f35db51a0296a263d2211f772d12e5905da7da60458756ef554a1cd1fe83084f938bc6d9c7
6
+ metadata.gz: c277ba2eee535baf91c0959d42187e76b0aff57cb24129c1d79917fca6259c2ed2a0b5f59b9fe289dbad1877fc17d7ea3bde2678cf686b5f98ecf558fbe0b0e6
7
+ data.tar.gz: 3ff35c6aa910c27771f108dd9a6fbedb73efd57f5a16890ef8589fcce4d733f41b584a1a4f6e79faa9554e964e17eb2aa1ff1bc38655ed9c5acb2f9a3520e6ef
@@ -116,13 +116,20 @@ module Motor
116
116
  end
117
117
 
118
118
  def build_table_column(column, model, default_attrs)
119
+ access_type =
120
+ if model.primary_key == column.name
121
+ ColumnAccessTypes::READ_ONLY
122
+ else
123
+ COLUMN_NAME_ACCESS_TYPES.fetch(column.name, ColumnAccessTypes::READ_WRITE)
124
+ end
125
+
119
126
  {
120
127
  name: column.name,
121
128
  display_name: Utils.humanize_column_name(model.human_attribute_name(column.name)),
122
129
  column_type: fetch_column_type(column, model),
123
130
  column_source: ColumnSources::TABLE,
124
131
  is_array: column.array?,
125
- access_type: COLUMN_NAME_ACCESS_TYPES.fetch(column.name, ColumnAccessTypes::READ_WRITE),
132
+ access_type: access_type,
126
133
  default_value: default_attrs[column.name],
127
134
  validators: fetch_validators(model, column.name),
128
135
  reference: nil,
@@ -5,6 +5,8 @@ module Motor
5
5
  module FetchConfiguredModel
6
6
  CACHE_HASH = HashWithIndifferentAccess.new
7
7
 
8
+ HAS_AND_BELONGS_TO_MANY_JOIN_MODEL_PREFIX = 'HABTM_'
9
+
8
10
  module_function
9
11
 
10
12
  def call(model, cache_key:)
@@ -130,13 +132,8 @@ module Motor
130
132
  end
131
133
 
132
134
  def configure_reflection_classes(klass, cache_key)
133
- klass.reflections.each do |key, ref|
134
- begin
135
- next unless ref.klass
136
- next if ref.klass.anonymous?
137
- rescue StandardError
138
- next
139
- end
135
+ klass._reflections.each do |key, ref|
136
+ next unless configure_reflection_class?(ref)
140
137
 
141
138
  ref_dup = ref.dup
142
139
 
@@ -146,11 +143,9 @@ module Motor
146
143
  ref_dup.instance_variable_set(:@klass, call(ref.klass, cache_key: cache_key))
147
144
  end
148
145
 
149
- klass.reflections[key] = ref_dup
146
+ klass._reflections[key] = ref_dup
150
147
  end
151
148
 
152
- klass._reflections = klass.reflections
153
-
154
149
  klass
155
150
  end
156
151
 
@@ -203,6 +198,19 @@ module Motor
203
198
  end
204
199
  end
205
200
 
201
+ def configure_reflection_class?(ref)
202
+ begin
203
+ return false unless ref.klass
204
+ rescue StandardError
205
+ return false
206
+ end
207
+
208
+ return false if ref.klass.anonymous?
209
+ return false if ref.klass.name.demodulize.starts_with?(HAS_AND_BELONGS_TO_MANY_JOIN_MODEL_PREFIX)
210
+
211
+ true
212
+ end
213
+
206
214
  def sti_model?(model)
207
215
  !model.superclass.abstract_class && model.columns_hash[model.inheritance_column.to_s]
208
216
  end
data/lib/motor/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Motor
4
- VERSION = '0.2.26'
4
+ VERSION = '0.2.27'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motor-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.26
4
+ version: 0.2.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Matsyburka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-16 00:00:00.000000000 Z
11
+ date: 2021-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-filter