Class: Vizier::PresenterFactory
- Inherits:
-
Object
- Object
- Vizier::PresenterFactory
- 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
- #[](object, user, view) ⇒ Object
-
#initialize(presenter_map = {}, config_type: PresenterConfig, default_config: DefaultPresenterConfig.new(config_type)) ⇒ PresenterFactory
constructor
Construct a factory with a mapping of types to their default presenters and policies.
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.
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 |