Sha256: 8c79ad33fc580fd29c7b8bd95779e37a855589c76bc81ebda953fb7f4071911a

Contents?: true

Size: 1.03 KB

Versions: 17

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true
module ActiveAdmin
  class AbstractViewFactory < SettingsNode

    def self.register(view_hash)
      view_hash.each do |view_key, view_class|
        super view_key, view_class
        add_writer(view_key)
        send "#{view_key}=", view_class
      end
    end

    def self.add_writer(name)
      define_singleton_method("#{name}=") do |value|
        value.builder_method name
        instance_variable_set :"@#{name}", value
      end
    end

    # Register a new view key with the view factory
    #
    # eg:
    #
    #   factory = AbstractViewFactory.new
    #   factory.register my_view: SomeViewClass
    #
    # You can setup many at the same time:
    #
    #   factory.register  my_view: SomeClass,
    #                     another_view: OtherViewClass
    #
    def register(view_hash)
      self.class.register view_hash
    end

    def default_for(key)
      self.class.send key
    end

    def [](key)
      send key
    end

    def []=(key, value)
      send "#{key}=", value
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
activeadmin-3.2.5 lib/active_admin/abstract_view_factory.rb
activeadmin-3.2.4 lib/active_admin/abstract_view_factory.rb
activeadmin-3.2.3 lib/active_admin/abstract_view_factory.rb
activeadmin-3.2.2 lib/active_admin/abstract_view_factory.rb
activeadmin-3.2.1 lib/active_admin/abstract_view_factory.rb
activeadmin-3.2.0 lib/active_admin/abstract_view_factory.rb
activeadmin-3.1.0 lib/active_admin/abstract_view_factory.rb
activeadmin-3.0.0 lib/active_admin/abstract_view_factory.rb
activeadmin-2.14.0 lib/active_admin/abstract_view_factory.rb
activeadmin-2.13.1 lib/active_admin/abstract_view_factory.rb
activeadmin-2.13.0 lib/active_admin/abstract_view_factory.rb
activeadmin-2.12.0 lib/active_admin/abstract_view_factory.rb
activeadmin-2.11.2 lib/active_admin/abstract_view_factory.rb
activeadmin-2.11.1 lib/active_admin/abstract_view_factory.rb
activeadmin-2.11.0 lib/active_admin/abstract_view_factory.rb
activeadmin-2.10.1 lib/active_admin/abstract_view_factory.rb
activeadmin-2.10.0 lib/active_admin/abstract_view_factory.rb