From b9cf6243df91c77df3380c60b7c125e9591fcca8 Mon Sep 17 00:00:00 2001 From: Herb Miller Jr Date: Tue, 29 Nov 2016 19:17:47 -0500 Subject: [PATCH 1/2] shows.json can now contain a "limit" member that specifies a character limit for the specific show's title. Changed hard limit in DataMapper class in suggestion.rb from 40 to the value of live show's limit. Not sure of workflow. May be a problem there is no live show in data.json? Also bumped setting LIVE_URL to immediately after call to Dotenv.load, otherwise it gets set too late to initialize the Suggestion class. shows.json example: { "shows": [ { "rss":"http://feeds.feedburner.com/BsdNowHd", "url": "bn", "title": "BSD Now" }, { "rss":"http://feeds.feedburner.com/coderradiovideo", "url": "cr", "title": "Coder Radio", "limit": 10 } ] } --- environment.rb | 2 +- lib/models/show.rb | 3 ++- lib/models/suggestion.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/environment.rb b/environment.rb index 32a7672..cbecc78 100644 --- a/environment.rb +++ b/environment.rb @@ -14,6 +14,7 @@ configure do Dotenv.load + LIVE_URL = ENV['DATA_JSON_URL'] Dir[File.join(Dir.pwd, 'locales', '*.yml')].each {|file| I18n.load_path << file } # Make sure only available locales are used. This will be the default in the # future but we need this to silence a deprecation warning @@ -47,4 +48,3 @@ def t(*args) DataMapper.finalize end -LIVE_URL = ENV['DATA_JSON_URL'] diff --git a/lib/models/show.rb b/lib/models/show.rb index 91064fd..668bd49 100644 --- a/lib/models/show.rb +++ b/lib/models/show.rb @@ -8,7 +8,7 @@ # aliases: (array[string]) An array of aliases that can additionally match # the show class Show - attr_reader :title, :url, :rss, :aliases + attr_reader :title, :url, :rss, :aliases, :limit # param json_hash: (hash) A hash of show data with the following keys: # title: (string) The show's title @@ -22,6 +22,7 @@ def initialize(json_hash) @title = json_hash["title"] @url = json_hash["url"] @rss = json_hash["rss"] + @limit = json_hash.key?("limit") ? json_hash["limit"] : 40 @aliases = (json_hash["aliases"] || []).map do |show_alias| show_alias.downcase end diff --git a/lib/models/suggestion.rb b/lib/models/suggestion.rb index 527654c..8188a3c 100644 --- a/lib/models/suggestion.rb +++ b/lib/models/suggestion.rb @@ -15,7 +15,7 @@ class Suggestion include DataMapper::Resource property :id, Serial - property :title, String, :length => 40, + property :title, String, :length => Shows.fetch_live_show.limit, :message => I18n.t('messages.models.suggestion') property :user, String property :show, String From dabe9bce9ca85c667b5fe423e58b539c96626ece Mon Sep 17 00:00:00 2001 From: Herb Miller Jr Date: Sat, 3 Dec 2016 16:18:46 -0500 Subject: [PATCH 2/2] Additional testing revealed that if data.json exists but contains invalid slug, suggestions.rb crashes. Added a condition for when the live show cannot be found so limit defaults to 40. --- lib/models/suggestion.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/models/suggestion.rb b/lib/models/suggestion.rb index 8188a3c..e308021 100644 --- a/lib/models/suggestion.rb +++ b/lib/models/suggestion.rb @@ -15,7 +15,7 @@ class Suggestion include DataMapper::Resource property :id, Serial - property :title, String, :length => Shows.fetch_live_show.limit, + property :title, String, :length => Shows.fetch_live_show.nil? ? 40 : Shows.fetch_live_show.limit, :message => I18n.t('messages.models.suggestion') property :user, String property :show, String