Class: Vizier::PresenterFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/vizier/presenter_factory.rb

Overview

Factory for locating and creating a presenter based on an object’s type.

Instance Method Summary collapse

Constructor Details

#initialize(presenter_map = {}, config_type: PresenterConfig, default_config: DefaultPresenterConfig.new(config_type)) ⇒ PresenterFactory

Construct a factory with a mapping of types to their default presenters and policies.

Parameters:

  • presenter_map (Hash) (defaults to: {})

    the mapping of classes of strings to a pair, where the first item is the default presenter type, and the second is the default policy type.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vizier/presenter_factory.rb', line 12

def initialize(
  presenter_map = {},
  config_type: PresenterConfig,
  default_config: DefaultPresenterConfig.new(config_type)
)

  @config_type = config_type
  @default_config = default_config

  @configs = Hash.new do |_configs, type|
    default_config.for(type)
  end

  presenter_map.each do |type, config|
    @configs[type.to_s] = config_type.new(type, config.first, config.last)
  end
end

Instance Method Details

#[](object, user, view) ⇒ Object



30
31
32
# File 'lib/vizier/presenter_factory.rb', line 30

def [](object, user, view)
  configs[object.class.to_s].present(object, user, view)
end