From feaf5dfc14704639f6eedf54997f13a334ae65bb Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Sun, 17 Apr 2016 12:03:01 -0400 Subject: [PATCH] Protect Presenter public methods more reliably --- lib/mountain_view/presenter.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/mountain_view/presenter.rb b/lib/mountain_view/presenter.rb index 43e6bc0..ea1d758 100644 --- a/lib/mountain_view/presenter.rb +++ b/lib/mountain_view/presenter.rb @@ -12,7 +12,7 @@ def initialize(slug, properties = {}) def render(context) context.extend ViewContext - context.inject_component_context(self) + context.inject_component_context self context.render self end @@ -48,7 +48,7 @@ def properties(*args) alias_method :property, :properties private - + def define_property_methods(names=[]) names.each do |name| next if method_defined?(name) @@ -62,19 +62,20 @@ def define_property_methods(names=[]) module ViewContext attr_reader :_component delegate :properties, to: :_component - + def inject_component_context(component) @_component = component - methods = component.public_methods(false) - [:slug, :properties, :render, :partial] + protected_methods = MountainView::Presenter.public_methods(false) + methods = component.public_methods(false) - protected_methods methods.each do |meth| next if self.class.method_defined?(meth) self.class.delegate meth, to: :_component end end - + def prefix_partial_path_with_controller_namespace false end end end -end +end \ No newline at end of file