Class: ActiveAdmin::AbstractViewFactory

Inherits:
SettingsNode show all
Defined in:
lib/active_admin/abstract_view_factory.rb

Direct Known Subclasses

ViewFactory

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SettingsNode

build

Class Method Details

.add_writer(name) ⇒ Object


12
13
14
15
16
17
# File 'lib/active_admin/abstract_view_factory.rb', line 12

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

.register(view_hash) ⇒ Object


4
5
6
7
8
9
10
# File 'lib/active_admin/abstract_view_factory.rb', line 4

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

Instance Method Details

#[](key) ⇒ Object


39
40
41
# File 'lib/active_admin/abstract_view_factory.rb', line 39

def [](key)
  send key
end

#[]=(key, value) ⇒ Object


43
44
45
# File 'lib/active_admin/abstract_view_factory.rb', line 43

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

#default_for(key) ⇒ Object


35
36
37
# File 'lib/active_admin/abstract_view_factory.rb', line 35

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

#register(view_hash) ⇒ Object

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

31
32
33
# File 'lib/active_admin/abstract_view_factory.rb', line 31

def register(view_hash)
  self.class.register view_hash
end