docbrown/app/controllers/stories
Jeremy Friesen fa093b0a92
Refactoring instance variable usage in tagged articles controller (#15687)
* Refactoring away from instance variables

Having both `@tag` and `@tag_model` as variable names can be confusing.

Given that in the prior implementation `@tag_model.name == @tag`, I
figured I would refactor the controller to remove an instance variable.

In addition, this refactor addresses the temporal coupling of methods;
that is to say we call a method which sets an instance variable then
call another dependent on that instance variable.

Yes, ivars are useful to allow for implicit state.  However, by favoring
parameters its easier to notice temporal dependencies in method calls.

This helps ensure that we're calling methods in the right order.

Futher, we have a guard clause in place, so let's avoid setting any
additional instance variables that aren't needed if the guard clause
executes.

Related to #15359

* Update app/controllers/stories/tagged_articles_controller.rb

Co-authored-by: Michael Kohl <citizen428@forem.com>

* Favoring constants and Rails where constructs

Prior to this commit, we had a magic array.  That magic array was a
duplicate of the Timeframe constant.  Likewise, we had a magic string.

This change removes that duplication.

Furthermore, this change favors the `where(key: range..)` construct
instead of "raw" SQL and parameter substition.

Co-authored-by: Michael Kohl <citizen428@forem.com>
2021-12-15 10:49:50 -05:00
..
articles_search_controller.rb Fix search param cache leak (#14848) 2021-09-30 10:43:23 +07:00
feeds_controller.rb Fixing weighted query hotness grab logic (#15528) 2021-11-30 12:55:48 -05:00
pinned_articles_controller.rb Pin posts to feed (#13807) 2021-06-04 10:54:53 +02:00
tagged_articles_controller.rb Refactoring instance variable usage in tagged articles controller (#15687) 2021-12-15 10:49:50 -05:00