From b071927ced9f47be8a090501a688fcce3abae830 Mon Sep 17 00:00:00 2001 From: Zvika Rap Date: Sat, 14 Sep 2013 22:40:11 +0300 Subject: [PATCH] HandlebarsOneboxes: avoid constants multiple declarations --- lib/oneboxer/stack_exchange_onebox.rb | 22 +++++++++++++--------- lib/oneboxer/twitter_onebox.rb | 10 +++++++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/oneboxer/stack_exchange_onebox.rb b/lib/oneboxer/stack_exchange_onebox.rb index 07e60cecad6..b06e108bd2c 100644 --- a/lib/oneboxer/stack_exchange_onebox.rb +++ b/lib/oneboxer/stack_exchange_onebox.rb @@ -2,17 +2,21 @@ require_dependency 'oneboxer/handlebars_onebox' module Oneboxer class StackExchangeOnebox < HandlebarsOnebox - DOMAINS = [ - 'stackexchange', - 'stackoverflow', - 'superuser', - 'serverfault', - 'askubuntu' - ] + + unless defined? DOMAINS + DOMAINS = [ + 'stackexchange', + 'stackoverflow', + 'superuser', + 'serverfault', + 'askubuntu' + ] + end # http://rubular.com/r/V3T0I1VTPn - REGEX = - /^http:\/\/(?:(?:(?\w*)\.)?(?\w*)\.)?(?#{DOMAINS.join('|')})\.com\/(?:questions|q)\/(?\d*)/ + unless defined? REGEX + REGEX = /^http:\/\/(?:(?:(?\w*)\.)?(?\w*)\.)?(?#{DOMAINS.join('|')})\.com\/(?:questions|q)\/(?\d*)/ + end matcher REGEX favicon 'stackexchange.png' diff --git a/lib/oneboxer/twitter_onebox.rb b/lib/oneboxer/twitter_onebox.rb index 6da44703585..a0a292e6af2 100644 --- a/lib/oneboxer/twitter_onebox.rb +++ b/lib/oneboxer/twitter_onebox.rb @@ -2,10 +2,14 @@ require_dependency 'oneboxer/handlebars_onebox' module Oneboxer class TwitterOnebox < HandlebarsOnebox - BASE_URL = 'https://api.twitter.com'.freeze - REGEX = - /^https?:\/\/(?:www\.)?twitter.com\/(?[^\/]+)\/status\/(?\d+)$/ + unless defined? BASE_URL + BASE_URL = 'https://api.twitter.com'.freeze + end + + unless defined? REGEX + REGEX = /^https?:\/\/(?:www\.)?twitter.com\/(?[^\/]+)\/status\/(?\d+)$/ + end matcher REGEX