Class: RedmineExtensions::BasePresenter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- RedmineExtensions::BasePresenter
show all
- Defined in:
- app/presenters/redmine_extensions/base_presenter.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(model, view, options = {}) ⇒ BasePresenter
Returns a new instance of BasePresenter.
28
29
30
31
|
# File 'app/presenters/redmine_extensions/base_presenter.rb', line 28
def initialize(model, view, options={})
@model, @view, @options = model, view, options
super(@model)
end
|
Instance Attribute Details
Returns the value of attribute model.
3
4
5
|
# File 'app/presenters/redmine_extensions/base_presenter.rb', line 3
def model
@model
end
|
Returns the value of attribute options.
3
4
5
|
# File 'app/presenters/redmine_extensions/base_presenter.rb', line 3
def options
@options
end
|
Class Method Details
.present(model, view, options = {}) ⇒ Object
24
25
26
|
# File 'app/presenters/redmine_extensions/base_presenter.rb', line 24
def self.present(model, view, options={})
presenter_for(model).new(model, view, options)
end
|
.presenter_for(model) ⇒ Object
16
17
18
19
20
21
22
|
# File 'app/presenters/redmine_extensions/base_presenter.rb', line 16
def self.presenter_for(model)
klasses = model.hiearchy.map do |klass|
(registered_presenters[klass] || "#{klass}Presenter").constantize rescue nil
end.compact
raise NameError, 'presenter for ' + model.class.name + ' is not registered' unless klasses.any?
klasses.first
end
|
.register(klass_name, *for_classes) ⇒ Object
9
10
11
12
13
14
|
# File 'app/presenters/redmine_extensions/base_presenter.rb', line 9
def self.register(klass_name, *for_classes)
for_classes = [klass_name.sub(/Presenter$/, '')] unless for_classes.any?
for_classes.each do |name|
registered_presenters[name] = klass_name
end
end
|
.registered_presenters ⇒ Object
5
6
7
|
# File 'app/presenters/redmine_extensions/base_presenter.rb', line 5
def self.registered_presenters
@registered_presenters ||= {}
end
|
Instance Method Details
43
44
45
|
# File 'app/presenters/redmine_extensions/base_presenter.rb', line 43
def h
@view
end
|
39
40
41
|
# File 'app/presenters/redmine_extensions/base_presenter.rb', line 39
def to_model
@model || self
end
|
#update_options(options = {}) ⇒ Object
33
34
35
36
37
|
# File 'app/presenters/redmine_extensions/base_presenter.rb', line 33
def update_options(options={})
@view = options.delete(:view_context) if options.key?(:view_context)
@options.merge!(options)
self
end
|