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



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

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



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

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



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

def [](key)
  send key
end

#[]=(key, value) ⇒ Object



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

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

#default_for(key) ⇒ Object



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

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


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

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