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
34 lines
820 B
Ruby
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
|