Sha256: c5987d50ea375ff3de26d1776d49f998ab04b7df4c0f57126f30d255e73df40d
Contents?: true
Size: 1.2 KB
Versions: 33
Compression:
Stored size: 1.2 KB
Contents
require "simple_form/map_type" module Plutonium module Core module Fields module Renderers class Factory extend ::SimpleForm::MapType map_type :belongs_to, :has_one, :has_many, to: Plutonium::Core::Fields::Renderers::AssociationRenderer map_type :attachment, to: Plutonium::Core::Fields::Renderers::AttachmentRenderer def self.build(name, type:, **) mapping = mappings[type] || Plutonium::Core::Fields::Renderers::BasicRenderer mapping.new(name, **) end def self.for_resource_attribute(resource_class, attr_name, **options) type = nil if (attachment = resource_class.try(:reflect_on_attachment, attr_name)) type = :attachment options[:reflection] = attachment elsif (association = resource_class.try(:reflect_on_association, attr_name)) type = association.macro options[:reflection] = association elsif (column = resource_class.try(:column_for_attribute, attr_name)) type = column.type end build(attr_name, type:, **options) end end end end end end
Version data entries
33 entries across 33 versions & 1 rubygems