Class: Vizier::PresenterConfig

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

Overview

Mapping for a given type to presenter and policy types.

This configuration does not cache the constant lookups, so it supports reloading of the types in development. The CachingPresenterConfig should be used in production.

Direct Known Subclasses

CachingPresenterConfig

Instance Method Summary collapse

Constructor Details

#initialize(type, presenter, policy) ⇒ PresenterConfig

Returns a new instance of PresenterConfig.



10
11
12
13
14
# File 'lib/vizier/presenter_config.rb', line 10

def initialize(type, presenter, policy)
  @type_name = type.to_s
  @presenter_name = presenter.to_s
  @policy_name = policy.to_s
end

Instance Method Details

#policyObject



28
29
30
# File 'lib/vizier/presenter_config.rb', line 28

def policy
  Object.const_get(@policy_name)
end

#present(object, user, view) ⇒ Object



16
17
18
# File 'lib/vizier/presenter_config.rb', line 16

def present(object, user, view)
  presenter.new(policy.new(user, object), view)
end

#presenterObject



24
25
26
# File 'lib/vizier/presenter_config.rb', line 24

def presenter
  Object.const_get(@presenter_name)
end

#typeObject



20
21
22
# File 'lib/vizier/presenter_config.rb', line 20

def type
  Object.const_get(@type_name)
end