Sha256: 780bd5f65b4eded87f69240058c5962d061b44ec44629cb88174b60e0d85a2d9

Contents?: true

Size: 1.17 KB

Versions: 44

Compression:

Stored size: 1.17 KB

Contents

module Plutonium
  module Core
    module Definers
      module FieldRendererDefiner
        extend ActiveSupport::Concern
        include Plutonium::Core::Autodiscovery::RendererDiscoverer

        def defined_field_renderers_for(*names)
          (names - field_renderer_definitions.keys).each do |name|
            define_field_renderer(name, renderer: autodiscover_renderer(name))
          end
          field_renderer_definitions.slice(*names)
        end

        private

        def field_renderer_definitions = @field_renderer_definitions ||= {}

        def define_field_renderer(name, renderer: nil, type: nil, **options)
          field_renderer_definitions[name] = if renderer.present?
            renderer
          elsif type.present?
            Plutonium::Core::Fields::Renderers::Factory.build(name, type:, **options)
          elsif options.present?
            Plutonium::Core::Fields::Renderers::Factory.for_resource_attribute(resource_class, name, **options)
          else
            autodiscover_renderer(name)
          end
        end

        def field_renderer_defined?(name)
          field_renderer_definitions.key? name
        end
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
plutonium-0.16.5 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.16.4 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.16.3 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.16.1 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.16.0 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.24 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.23 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.22 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.21 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.20 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.19 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.18 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.17 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.16 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.15 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.14 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.13 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.12 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.11 lib/plutonium/core/definers/field_renderer_definer.rb
plutonium-0.15.10 lib/plutonium/core/definers/field_renderer_definer.rb