Module: ViewObject
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/view_object.rb,
lib/view_object/engin.rb,
lib/view_object/config.rb,
lib/view_object/version.rb,
lib/view_object/dispatcher.rb
Defined Under Namespace
Classes: Configuration, Dispatcher, Engine
Constant Summary
collapse
- VERSION =
"0.2.0"
- @@view_object_ignore =
nil
- @@view_object_only =
nil
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.config ⇒ Object
Global settings for ViewObject
10
11
12
|
# File 'lib/view_object/config.rb', line 10
def self.config
@config
end
|
5
6
7
|
# File 'lib/view_object/config.rb', line 5
def self.configure(&block)
yield @config ||= ViewObject::Configuration.new
end
|
Instance Method Details
#dispatch_view_object(controller) ⇒ Object
12
13
14
15
16
17
|
# File 'lib/view_object.rb', line 12
def dispatch_view_object(controller)
return unless is_view_object_only_action(@@view_object_only, controller)
return if is_view_object_ignore_action(@@view_object_ignore, controller)
Dispatcher.dispatch_view_object(controller)
end
|
#is_view_object_ignore_action(actions, controller) ⇒ Object
24
25
26
27
|
# File 'lib/view_object.rb', line 24
def is_view_object_ignore_action(actions, controller)
ignore_actions = actions.is_a?(Array) ? actions.map{ |action| action.to_s } : actions.to_s
return (ignore_actions.present? && ignore_actions.include?(controller.params[:action].to_s))
end
|
#is_view_object_only_action(actions, controller) ⇒ Object
19
20
21
22
|
# File 'lib/view_object.rb', line 19
def is_view_object_only_action(actions, controller)
only_actions = actions.is_a?(Array) ? actions.map{ |action| action.to_s } : actions.to_s
return (only_actions.blank? || only_actions.include?(controller.params[:action].to_s))
end
|
#render(*options, &block) ⇒ Object
36
37
38
39
40
|
# File 'lib/view_object.rb', line 36
def render(*options, &block)
run_callbacks(:render) do
super
end
end
|
#view_object_before_render(controller) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/view_object.rb', line 29
def view_object_before_render(controller)
vo = controller.instance_variable_get(:@view_object)
return if vo.blank?
return unless vo.respond_to?(:before_render)
vo.send(:before_render)
end
|