Sha256: 0c947694c604380d9774844cf72d114c70016b23d7957f792794621d2f3c49f5

Contents?: true

Size: 1.17 KB

Versions: 7

Compression:

Stored size: 1.17 KB

Contents

require 'rails_admin/config/fields'
require 'rails_admin/config/fields/types'
require 'rails_admin/config/fields/types/file_upload'

RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
  next false unless defined?(::Shrine)

  attachment_names = parent.abstract_model.model.ancestors.select { |m| m.is_a?(Shrine::Attachment) }.map { |a| a.instance_variable_get('@name') }
  next false if attachment_names.blank?

  attachment_name = attachment_names.detect { |a| a == properties.name.to_s.chomp('_data').to_sym }
  next false unless attachment_name

  field = RailsAdmin::Config::Fields::Types.load(:shrine).new(parent, attachment_name, properties)
  fields << field

  data_field_name = "#{attachment_name}_data".to_sym
  child_properties = parent.abstract_model.properties.detect { |p| p.name == data_field_name }
  next true unless child_properties

  children_field = fields.detect { |f| f.name == data_field_name } || RailsAdmin::Config::Fields.default_factory.call(parent, child_properties, fields)
  children_field.hide unless field == children_field
  children_field.filterable(false) unless field == children_field

  field.children_fields([data_field_name])
  true
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails_admin-3.0.0 lib/rails_admin/config/fields/factories/shrine.rb
rails_admin-3.0.0.rc4 lib/rails_admin/config/fields/factories/shrine.rb
rails_admin-3.0.0.rc3 lib/rails_admin/config/fields/factories/shrine.rb
rails_admin-3.0.0.rc2 lib/rails_admin/config/fields/factories/shrine.rb
rails_admin-3.0.0.rc lib/rails_admin/config/fields/factories/shrine.rb
rails_admin-3.0.0.beta2 lib/rails_admin/config/fields/factories/shrine.rb
rails_admin-3.0.0.beta lib/rails_admin/config/fields/factories/shrine.rb