From 5cc115b001f05ca1e1f68cd1eaf2becbadf5c519 Mon Sep 17 00:00:00 2001 From: Grant Colegate Date: Wed, 18 May 2016 11:04:53 +0930 Subject: [PATCH] Accessor instance variable is now the same name as accessor --- lib/blush/has_presenter.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/blush/has_presenter.rb b/lib/blush/has_presenter.rb index a757cfe..9875a65 100644 --- a/lib/blush/has_presenter.rb +++ b/lib/blush/has_presenter.rb @@ -5,9 +5,12 @@ def has_presenter(accessor_name = {}, options = nil) options, accessor_name = accessor_name, options unless options self.blush_options = options + self.blush_options[:accessor_name] = accessor_name || Blush.config.accessor_name - define_method(accessor_name || Blush.config.accessor_name) do - @presenter ||= (self.blush_options[:class] || "#{self.model_name}Presenter").constantize.new(self) + define_method(self.blush_options[:accessor_name]) do + accessor_name = "@#{self.blush_options[:accessor_name]}" + presenter_class = (self.blush_options[:class] || "#{self.model_name}Presenter").constantize + instance_variable_get(accessor_name) || instance_variable_set(accessor_name, presenter_class.new(self)) end define_method(self.blush_options[:helper_name] || Blush.config.helper_name) do |method, *args, &block|