Skip to content

Commit

Permalink
Protect Presenter public methods more reliably
Browse files Browse the repository at this point in the history
  • Loading branch information
tombeynon committed Apr 17, 2016
1 parent a7625d8 commit 166906e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/mountain_view/presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -62,16 +62,17 @@ 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
Expand Down

0 comments on commit 166906e

Please sign in to comment.