diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-10-27 20:22:38 +0000 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-10-29 13:01:44 +0000 |
commit | 4c125f0e49ec89c794839051fd762a17d7e82007 (patch) | |
tree | f5e235b1df47b3be7e42e498de50e34337480eea | |
parent | a2fdf908b411da33dc80722fc15dda95c6d866fd (diff) |
Dynamically call params hash for TrackThing#params
Easier to add params now; just add TRACK_TYPE_params method which
returns the hash you want.
Uses more idiomatic ||= instead of if @params.nil?
-rw-r--r-- | app/models/track_thing.rb | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index 1a81d1fba..d93742dcd 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -164,31 +164,22 @@ class TrackThing < ActiveRecord::Base end end - # Return hash of text parameters describing the request etc. + # Return hash of text parameters based on the track_type describing the + # request etc. def params - if @params.nil? - if track_type == 'request_updates' - @params = request_updates_params - elsif track_type == 'all_new_requests' - @params = all_new_requests_params - elsif track_type == 'all_successful_requests' - @params = all_successful_requests_params - elsif track_type == 'public_body_updates' - @params = public_body_updates_params - elsif track_type == 'user_updates' - @params = user_updates_params - elsif track_type == 'search_query' - @params = search_query_params - else - raise "unknown tracking type #{ track_type }" - end - end - - @params + @params ||= params_for(track_type) end private + def params_for(track_type) + if respond_to?("#{ track_type }_params", true) + send("#{ track_type }_params") + else + raise "unknown tracking type #{ track_type }" + end + end + def request_updates_params { # Website :verb_on_page => _("Follow this request"), |