Files
grecia/app/controllers/concerns/polymorphic.rb
Javi Martín db97f9d08c Add and apply rubocop rules for empty lines
We were very inconsistent regarding these rules.

Personally I prefer no empty lines around blocks, clases, etc... as
recommended by the Ruby style guide [1], and they're the default values
in rubocop, so those are the settings I'm applying.

The exception is the `private` access modifier, since we were leaving
empty lines around it most of the time. That's the default rubocop rule
as well. Personally I don't have a strong preference about this one.


[1] https://rubystyle.guide/#empty-lines-around-bodies
2019-10-24 17:11:47 +02:00

34 lines
820 B
Ruby

module Polymorphic
private
def resource
if resource_model.to_s == "Budget::Investment"
@resource ||= instance_variable_get("@investment")
elsif resource_model.to_s == "Legislation::Proposal"
@resource ||= instance_variable_get("@proposal")
else
@resource ||= instance_variable_get("@#{resource_name}")
end
end
def resource_name
@resource_name ||= resource_model.to_s.downcase
end
def resource_relation
@resource_relation ||= resource_model.all
end
def set_resource_instance
instance_variable_set("@#{resource_name}", @resource)
end
def set_resources_instance
instance_variable_set("@#{resource_name.pluralize}", @resources)
end
def strong_params
send("#{resource_name}_params")
end
end