Created
February 20, 2014 11:56
-
-
Save the-undefined/9111985 to your computer and use it in GitHub Desktop.
Thinking on a further refactoring on a nice blog post regarding flog, using a Session Model came to mind to assist with the responsibilities. POST: http://cored.github.io/blog/2014/02/19/my-gpa-at-code-climate-is-3-dot-59-a-refactoring-story
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LastTracks | |
attr_accessor :session, :list | |
def initialize(session) | |
@session = session | |
@list = [] | |
yield(self) | |
end | |
def blacklist(url) | |
list << url | |
end | |
def previous_url=(came_from) | |
return unless valid_origin(came_from) | |
session[:previous_url] = came_from | |
end | |
private | |
def valid_origin(came_from) | |
!list.any? { |no_return| no_return =~ came_from } | |
end | |
end | |
# APPLICATION CONTROLLER | |
before_filter :record_tracks | |
def tracks | |
@tracks ||= LastTracks.new(session) do |tracks| | |
tracks.blacklist some_path | |
tracks.blacklist another_path | |
tracks.blacklist one_more_path | |
end | |
end | |
helper_method :tracks | |
def record_tracks | |
return if request.xhr? | |
tracks.previous_url = request.fullpath | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@cored Yeah, first got the hang of using Session Models from a railscast yonks ago: http://railscasts.com/episodes/119-session-based-model it's served me well since then.