Skip to content

Commit

Permalink
rewrite of controller_extensions method
Browse files Browse the repository at this point in the history
  • Loading branch information
yakschuss committed Mar 15, 2016
1 parent 073070a commit 9989ef7
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/merit/controller_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,24 @@ def had_errors?
target_object.respond_to?(:errors) && target_object.errors.try(:present?)
end

def warn_no_object_found
str = '[merit] No object found, you might need a ' \
"'@#{controller_name.singularize}' variable in " \
"'#{controller_path}_controller' if no reputation is applied. " \
'If you are using `model_name` option in the rule this is ok.'
Rails.logger.warn str
end

def target_object
variable_name = :"@#{controller_name.singularize}"
if instance_variable_defined?(variable_name)
target_obj = instance_variable_get(variable_name)
if target_obj = instance_variable_get(variable_name)
target_obj
else
warn_no_object_found
end
end
target_obj.nil? ? warn_no_object_found : target_obj
end

def warn_no_object_found
str = '[merit] No object found, you might need a ' \
"'@#{controller_name.singularize}' variable in " \
"'#{controller_path}_controller' if no reputation is applied. " \
'If you are using `model_name` option in the rule this is ok.'
Rails.logger.warn str
nil
end

def target_id
Expand Down

0 comments on commit 9989ef7

Please sign in to comment.