Skip to content

Commit

Permalink
Accessor instance variable is now the same name as accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
blaknite committed May 18, 2016
1 parent 723ba67 commit 5cc115b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/blush/has_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down

0 comments on commit 5cc115b

Please sign in to comment.