motor-admin 0.2.28 → 0.2.29

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: 890e9157c807073892957ebdab77377f9cf36b91f5e00f04fd128f5591764fd2
4
- data.tar.gz: 41aa043a58ec68f713bf2a75e21464eb8bad07f000cabacd9fa364e821329414
3
+ metadata.gz: df2bbffc1e4cccc31af216322ef484259e7acc71741bf721dc2359bbd9267c4e
4
+ data.tar.gz: 8f8f8cfa03ab51e5f3ac697aaa3caf04803523689e8c240df130f2e59696b021
5
5
  SHA512:
6
- metadata.gz: d5ea14f4ecd4d9deaadac11b12da0d5d689bf8256505a17b632a30a6758fb61e84650f6b997e352f77ccf91a139242aa04f81661d352cfb72087112304383756
7
- data.tar.gz: a4ea641247486ee81239eda91e209e421082d8d45fe0dfffde355749f7e273b1f02964f3e668904a493610b38885da87928dbcee151a5c647c60675d84eb6e6a
6
+ metadata.gz: aaa0388d363a6d3a0116a6f78e6d212027152226cd89faabdcb832f622395426d7487d27a2dd3268d97d6112fb2df6175113183dd689940a9f6748ad306ca134
7
+ data.tar.gz: b8837f8486c38a10e86f11415ceac1ace48f5bcb113db9a97cf2f0a3cd11cc798f8b401e03015b62594d5f75e1decb7e54c1be51001c60aa0d18e8540859ec97
@@ -9,8 +9,8 @@ module Motor
9
9
  load_and_authorize_resource :attachment, class: 'ActiveStorage::Attachment', parent: false
10
10
 
11
11
  def create
12
- if attachable?(@attachment.record)
13
- @attachment.record.public_send(@attachment.name).attach(file_params)
12
+ if attachable?(record)
13
+ record.public_send(@attachment.name).attach(file_params)
14
14
 
15
15
  head :ok
16
16
  else
@@ -20,6 +20,15 @@ module Motor
20
20
 
21
21
  private
22
22
 
23
+ def record
24
+ record_pk = @attachment.record.class.primary_key
25
+
26
+ Motor::Resources::FetchConfiguredModel.call(
27
+ @attachment.record.class,
28
+ cache_key: Motor::Resource.maximum(:updated_at)
29
+ ).find_by(record_pk => @attachment.record[record_pk])
30
+ end
31
+
23
32
  def attachable?(record)
24
33
  record.respond_to?("#{@attachment.name}_attachment=") ||
25
34
  record.respond_to?("#{@attachment.name}_attachments=")
@@ -23,7 +23,8 @@ module Motor
23
23
  'citext' => 'string',
24
24
  'jsonb' => 'json',
25
25
  'bool' => 'boolean',
26
- 'timestamp' => 'datetime'
26
+ 'timestamp' => 'datetime',
27
+ 'timestamptz' => 'datetime'
27
28
  }.freeze
28
29
 
29
30
  module_function
@@ -12,6 +12,7 @@ module Motor
12
12
  def call(model, cache_key:)
13
13
  configs = Motor::Configs::LoadFromCache.load_resources(cache_key: cache_key)
14
14
 
15
+ return model if model.name == 'ActiveStorage::Attachment'
15
16
  return model if configs.blank? || sti_model?(model)
16
17
 
17
18
  maybe_fetch_from_cache(
@@ -128,7 +129,11 @@ module Motor
128
129
 
129
130
  options = options.merge(config[:options] || {})
130
131
 
131
- klass.has_one(config[:name].to_sym, **options.symbolize_keys)
132
+ if config[:model_name] == 'active_storage/attachment'
133
+ klass.has_one_attached config[:name].delete_suffix('_attachment').to_sym
134
+ else
135
+ klass.has_one(config[:name].to_sym, **options.symbolize_keys)
136
+ end
132
137
  end
133
138
 
134
139
  def configure_reflection_classes(klass, cache_key)
@@ -159,11 +164,17 @@ module Motor
159
164
 
160
165
  filters = options.delete(:filters)
161
166
 
162
- if filters.present?
163
- klass.has_many(association[:name].to_sym, -> { filter(filters).tap(&:arel) }, **options.symbolize_keys)
164
- else
165
- klass.has_many(association[:name].to_sym, **options.symbolize_keys)
166
- end
167
+ define_association(klass, association[:name], options, filters)
168
+ end
169
+ end
170
+
171
+ def define_association(klass, name, options, filters)
172
+ if options[:class_name] == 'ActiveStorage::Attachment'
173
+ klass.has_many_attached name.delete_suffix('_attachments').to_sym
174
+ elsif filters.present?
175
+ klass.has_many(name.to_sym, -> { filter(filters).tap(&:arel) }, **options.symbolize_keys)
176
+ else
177
+ klass.has_many(name.to_sym, **options.symbolize_keys)
167
178
  end
168
179
  end
169
180
 
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.28'
4
+ VERSION = '0.2.29'
5
5
  end
@@ -2601,9 +2601,9 @@
2601
2601
  "icons/zoom-out.svg.gz": "icons/zoom-out.svg.gz",
2602
2602
  "icons/zoom-question.svg": "icons/zoom-question.svg",
2603
2603
  "icons/zoom-question.svg.gz": "icons/zoom-question.svg.gz",
2604
- "main-9f6b19ff999e209e9d33.css.gz": "main-9f6b19ff999e209e9d33.css.gz",
2605
- "main-9f6b19ff999e209e9d33.js.LICENSE.txt": "main-9f6b19ff999e209e9d33.js.LICENSE.txt",
2606
- "main-9f6b19ff999e209e9d33.js.gz": "main-9f6b19ff999e209e9d33.js.gz",
2607
- "main.css": "main-9f6b19ff999e209e9d33.css",
2608
- "main.js": "main-9f6b19ff999e209e9d33.js"
2604
+ "main-67a3a033614f741d7e27.css.gz": "main-67a3a033614f741d7e27.css.gz",
2605
+ "main-67a3a033614f741d7e27.js.LICENSE.txt": "main-67a3a033614f741d7e27.js.LICENSE.txt",
2606
+ "main-67a3a033614f741d7e27.js.gz": "main-67a3a033614f741d7e27.js.gz",
2607
+ "main.css": "main-67a3a033614f741d7e27.css",
2608
+ "main.js": "main-67a3a033614f741d7e27.js"
2609
2609
  }
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.28
4
+ version: 0.2.29
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-20 00:00:00.000000000 Z
11
+ date: 2021-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-filter
@@ -1525,8 +1525,8 @@ files:
1525
1525
  - ui/dist/icons/zoom-money.svg.gz
1526
1526
  - ui/dist/icons/zoom-out.svg.gz
1527
1527
  - ui/dist/icons/zoom-question.svg.gz
1528
- - ui/dist/main-9f6b19ff999e209e9d33.css.gz
1529
- - ui/dist/main-9f6b19ff999e209e9d33.js.gz
1528
+ - ui/dist/main-67a3a033614f741d7e27.css.gz
1529
+ - ui/dist/main-67a3a033614f741d7e27.js.gz
1530
1530
  - ui/dist/manifest.json
1531
1531
  homepage:
1532
1532
  licenses: