trestle-active_storage 0.0.1.pre.12 → 0.0.1

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: c3196bd3489dd19c5c1b7753367428a3327ecda806183e86320c4a7cea6ca929
4
- data.tar.gz: f3c1b13efe20904fed18e2dd760f2029144cd5aabe524c4552eb57542267e3b4
3
+ metadata.gz: 50cc7a1ff90ab38d8f8abc8b2586447a41431f537d87686e1f21ca0f2bd7e44c
4
+ data.tar.gz: a44acd224be364941ea78a69ba53288ab24e5e0b2bd838f6c55becab2ff3592d
5
5
  SHA512:
6
- metadata.gz: c1f2e41ba552bedc9b728dbd092dd4ca9a7178a27801f9a56c79673fe1721c9a943e8113ec8c969d6a62a07a61a58e45a9db2d070e8c86f38ab5c5a6b20a301c
7
- data.tar.gz: 7a8970337bcaf20f6b54789a2b51fec542927a21c5fa2ce9e2b105b8887e031a112da2318352c3cea98a08984d21e6d38006d61164551f318b0fa97246dceac6
6
+ metadata.gz: 170ed9f8a485d885cc1fa4c7682e7865e18cfc8ee4cfcf26b4a9417c8773436deb52012ad0079e54f68fa501eb304da8e148a3131fdde3777c3ac433d4b6d643
7
+ data.tar.gz: 7020a30b055329ed3ff6ee3cc963b3edb6d458defc49f6e538312332d2bb79be8a1872095064ce4fc3e9d1b0ae61c35bb7be0cca13ffbadfb6b663427e6ae815
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Trestle ActiveStorage Integration (trestle-active_storage)
2
2
 
3
- > [ActiveStorage](https://github.com/rails/rails/tree/master/activestorage) integration plugin for the Trestle admin framework
3
+ > [ActiveStorage](https://github.com/rails/rails/tree/master/activestorage#active-storage) integration plugin for the [Trestle admin framework](https://trestle.io)
4
4
 
5
5
  ## Usage
6
6
 
@@ -31,6 +31,12 @@ gem 'trestle-active_storage'
31
31
 
32
32
  Run `bundle install`, and then restart your Rails server.
33
33
 
34
+ ## Wishlist
35
+
36
+ - [ ] Support for `has_many_attached` attachments
37
+ - [ ] Support for [ActiveStorage previews](https://api.rubyonrails.org/v5.2/classes/ActiveStorage/Previewer.html)
38
+ - [ ] Integration tests
39
+
34
40
  ## License
35
41
 
36
42
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -2,7 +2,7 @@ module Trestle
2
2
  module ActiveStorage
3
3
  module Builder
4
4
  def active_storage_fields(&block)
5
- admin.active_storage_fields = block || []
5
+ admin.define_adapter_method(:active_storage_fields, &block)
6
6
  end
7
7
  end
8
8
  end
@@ -5,41 +5,23 @@ module Trestle
5
5
 
6
6
  included do
7
7
  before_action :define_attachment_accessors, only: [:show, :edit, :update, :destroy]
8
- before_action :delete_attachment_params, only: [:create, :update]
9
- before_action :attach_attachments, only: [:create, :update]
10
8
  after_action :purge_attachments, only: [:update]
11
9
  end
12
10
 
13
- protected
11
+ private
12
+ def define_attachment_accessors
13
+ self.instance = admin.find_instance(params)
14
14
 
15
- def define_attachment_accessors
16
- self.instance = admin.find_instance(params)
17
-
18
- admin.active_storage_fields.each do |field|
19
- instance.class.send(:attr_accessor, "delete_#{field}")
20
- end
21
- end
22
-
23
- def delete_attachment_params
24
- admin.active_storage_fields.each { |field| params.delete(field) }
25
- end
26
-
27
- def attach_attachments
28
- instance = admin.build_instance(permitted_params, params)
29
- instance_params = admin.permitted_params(params)
30
-
31
- admin.active_storage_fields.each do |field|
32
- if instance_params[field].present?
33
- instance.send(field).attach instance_params[field]
15
+ admin.active_storage_fields.each do |field|
16
+ instance.class.send(:attr_accessor, "delete_#{field}")
34
17
  end
35
18
  end
36
- end
37
19
 
38
- def purge_attachments
39
- admin.active_storage_fields.each do |field|
40
- instance.send(field).purge if instance.try("delete_#{field}") == '1'
20
+ def purge_attachments
21
+ admin.active_storage_fields.each do |field|
22
+ instance.send(field).purge if instance.try("delete_#{field}") == '1'
23
+ end
41
24
  end
42
- end
43
25
  end
44
26
  end
45
27
  end
@@ -4,7 +4,7 @@ module Trestle
4
4
  config.assets.precompile << 'activestorage.js' << 'trestle/active_storage_fields.js'
5
5
 
6
6
  initializer :extensions do
7
- Trestle::Resource.singleton_class.send(:prepend, Trestle::ActiveStorage::Resource)
7
+ Trestle::Resource.send(:include, Trestle::ActiveStorage::Resource)
8
8
  Trestle::Resource::Builder.send(:include, Trestle::ActiveStorage::Builder)
9
9
  Trestle::Resource::Controller.send(:include, Trestle::ActiveStorage::ControllerConcern)
10
10
  end
@@ -1,13 +1,25 @@
1
1
  module Trestle
2
2
  module ActiveStorage
3
3
  module Resource
4
- attr_writer :active_storage_fields
4
+ extend ActiveSupport::Concern
5
5
 
6
- def active_storage_fields
7
- if @active_storage_fields.nil?
8
- []
9
- else
10
- instance_exec(&@active_storage_fields)
6
+ included do
7
+ singleton_class.send(:prepend, Collection)
8
+ end
9
+
10
+ module Collection
11
+ def active_storage_fields
12
+ if active_storage_attachable?
13
+ adapter.active_storage_fields
14
+ else
15
+ []
16
+ end
17
+ end
18
+ end
19
+
20
+ module ClassMethods
21
+ def active_storage_attachable?
22
+ adapter.respond_to?(:active_storage_fields)
11
23
  end
12
24
  end
13
25
  end
@@ -1,5 +1,5 @@
1
1
  module Trestle
2
2
  module ActiveStorage
3
- VERSION = '0.0.1.pre.12'
3
+ VERSION = '0.0.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trestle-active_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre.12
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Venneman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-18 00:00:00.000000000 Z
11
+ date: 2018-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -81,9 +81,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
81
  version: '0'
82
82
  required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - ">"
84
+ - - ">="
85
85
  - !ruby/object:Gem::Version
86
- version: 1.3.1
86
+ version: '0'
87
87
  requirements: []
88
88
  rubyforge_project:
89
89
  rubygems_version: 2.7.3