DEV: Fix ruby warnings and whitespace issues (#470)

DEV: Fix ruby warnings and whitespace issues (#470)

Included:

  • DEV: Disable unusual rspec settings
  • DEV: Fix some ruby warnings and whitespace
  • DEV: Remove stray puts
  • DEV: Use File.exist? over File.exists?
  • DEV: Fix the remaining warnings
diff --git a/.rspec b/.rspec
index 0e1ecbf..4e1e0d2 100644
--- a/.rspec
+++ b/.rspec
@@ -1,5 +1 @@
 --color
---format documentation
---fail-fast
---backtrace
-
diff --git a/lib/onebox/engine.rb b/lib/onebox/engine.rb
index 0678215..4986b32 100644
--- a/lib/onebox/engine.rb
+++ b/lib/onebox/engine.rb
@@ -136,7 +136,7 @@ module Onebox
       end
 
       def always_https?
-        @https
+        defined?(@https) ? @https : false
       end
     end
   end
diff --git a/lib/onebox/engine/allowlisted_generic_onebox.rb b/lib/onebox/engine/allowlisted_generic_onebox.rb
index 7e45f7f..0397296 100644
--- a/lib/onebox/engine/allowlisted_generic_onebox.rb
+++ b/lib/onebox/engine/allowlisted_generic_onebox.rb
@@ -374,15 +374,17 @@ module Onebox
         escaped_image_src = ::Onebox::Helpers.normalize_url_for_output(data[:image])
 
         <<-HTML
-            <video title='#{data[:title]}'
-                   width='#{data[:video_width]}'
-                   height='#{data[:video_height]}'
-                   style='max-width:100%'
-                   poster='#{escaped_image_src}'
-                   controls=''>
-              <source src='#{escaped_video_src}'>
-            </video>
-          HTML
+          <video
+            title='#{data[:title]}'
+            width='#{data[:video_width]}'
+            height='#{data[:video_height]}'
+            style='max-width:100%'
+            poster='#{escaped_image_src}'
+            controls=''
+          >
+            <source src='#{escaped_video_src}'>
+          </video>
+        HTML
       end
 
       def embedded_html
diff --git a/lib/onebox/engine/amazon_onebox.rb b/lib/onebox/engine/amazon_onebox.rb
index ae15da0..eb5463c 100644
--- a/lib/onebox/engine/amazon_onebox.rb
+++ b/lib/onebox/engine/amazon_onebox.rb
@@ -14,6 +14,8 @@ module Onebox
       matches_regexp(/^https?:\/\/(?:www\.)?(?:smile\.)?(amazon|amzn)\.(?<tld>com|ca|de|it|es|fr|co\.jp|co\.uk|cn|in|com\.br|com\.mx|nl|pl|sa|sg|se|com\.tr|ae)\//)
 
       def url
+        @raw ||= nil
+
         # If possible, fetch the cached HTML body immediately so we can
         # try to grab the canonical URL from that document,
         # rather than guess at the best URL structure to use
@@ -36,7 +38,7 @@ module Onebox
       end
 
       def tld
-        @tld || @@matcher.match(@url)["tld"]
+        @tld ||= @@matcher.match(@url)["tld"]
       end
 
       def http_params
diff --git a/lib/onebox/engine/asciinema_onebox.rb b/lib/onebox/engine/asciinema_onebox.rb
index a1fc1db..f6c2710 100644
--- a/lib/onebox/engine/asciinema_onebox.rb
+++ b/lib/onebox/engine/asciinema_onebox.rb
@@ -7,7 +7,6 @@ module Onebox
       include StandardEmbed
 
       always_https
-
       matches_regexp(/^https?:\/\/asciinema\.org\/a\/[\p{Alnum}_\-]+$/)
 
       def to_html
diff --git a/lib/onebox/engine/audioboom_onebox.rb b/lib/onebox/engine/audioboom_onebox.rb
index f15b6b2..89986f4 100644
--- a/lib/onebox/engine/audioboom_onebox.rb
+++ b/lib/onebox/engine/audioboom_onebox.rb
@@ -13,14 +13,17 @@ module Onebox
         oembed = get_oembed
 
         <<-HTML
-          <img src="#{oembed.thumbnail_url}" style="max-width: #{oembed.width}px; max-height: #{oembed.height}px;" #{oembed.title_attr}>
+          <img
+            src="#{oembed.thumbnail_url}"
+            style="max-width: #{oembed.width}px; max-height: #{oembed.height}px;"
+            #{oembed.title_attr}
+          >
         HTML
       end
 
       def to_html
         get_oembed.html
       end
-
     end
   end
 end
diff --git a/lib/onebox/engine/bandcamp_onebox.rb b/lib/onebox/engine/bandcamp_onebox.rb
index 83ff790..a31e589 100644
--- a/lib/onebox/engine/bandcamp_onebox.rb
+++ b/lib/onebox/engine/bandcamp_onebox.rb
@@ -20,16 +20,16 @@ module Onebox
         escaped_src = og.video_secure_url || og.video
 
         <<-HTML
-          <iframe src="#{escaped_src}"
-                  width="#{og.video_width}"
-                  height="#{og.video_height}"
-                  scrolling="no"
-                  frameborder="0"
-                  allowfullscreen>
-          </iframe>
+          <iframe
+            src="#{escaped_src}"
+            width="#{og.video_width}"
+            height="#{og.video_height}"
+            scrolling="no"
+            frameborder="0"
+            allowfullscreen
+          ></iframe>
         HTML
       end
-
     end
   end
 end
diff --git a/lib/onebox/engine/cloudapp_onebox.rb b/lib/onebox/engine/cloudapp_onebox.rb
index 93a4199..f1b985e 100644
--- a/lib/onebox/engine/cloudapp_onebox.rb
+++ b/lib/onebox/engine/cloudapp_onebox.rb
@@ -25,28 +25,28 @@ module Onebox
 
       def link_html(og)
         <<-HTML
-            <a href='#{og.url}' target='_blank' rel='noopener'>
-              #{og.title}
-            </a>
-          HTML
+          <a href='#{og.url}' target='_blank' rel='noopener'>
+            #{og.title}
+          </a>
+        HTML
       end
 
       def video_html(og)
         direct_src = ::Onebox::Helpers.normalize_url_for_output("#{og.get(:url)}/#{og.title}")
 
         <<-HTML
-            <video width='480' height='360' #{og.title_attr} controls loop>
-              <source src='#{direct_src}' type='video/mp4'>
-            </video>
-          HTML
+          <video width='480' height='360' #{og.title_attr} controls loop>
+            <source src='#{direct_src}' type='video/mp4'>
+          </video>
+        HTML
       end
 
       def image_html(og)
         <<-HTML
-            <a href='#{og.url}' target='_blank' class='onebox' rel='noopener'>
-              <img src='#{og.image}' #{og.title_attr} alt='CloudApp' width='480'>
-            </a>
-          HTML
+          <a href='#{og.url}' target='_blank' class='onebox' rel='noopener'>
+            <img src='#{og.image}' #{og.title_attr} alt='CloudApp' width='480'>
+          </a>
+        HTML
       end
     end
   end
diff --git a/lib/onebox/engine/coub_onebox.rb b/lib/onebox/engine/coub_onebox.rb
index 2562fe8..7e57e45 100644
--- a/lib/onebox/engine/coub_onebox.rb
+++ b/lib/onebox/engine/coub_onebox.rb
@@ -17,7 +17,6 @@ module Onebox
       def to_html
         get_oembed.html
       end
-
     end
   end
 end
diff --git a/lib/onebox/engine/facebook_media_onebox.rb b/lib/onebox/engine/facebook_media_onebox.rb
index d676be3..903eccb 100644
--- a/lib/onebox/engine/facebook_media_onebox.rb
+++ b/lib/onebox/engine/facebook_media_onebox.rb
@@ -14,13 +14,14 @@ module Onebox
         metadata = get_twitter
         if metadata.present? && metadata[:card] == "player" && metadata[:player].present?
           <<-HTML
-            <iframe src="#{metadata[:player]}"
-                    width="#{metadata[:player_width]}"
-                    height="#{metadata[:player_height]}"
-                    scrolling="no"
-                    frameborder="0"
-                    allowfullscreen>
-            </iframe>
+            <iframe
+              src="#{metadata[:player]}"
+              width="#{metadata[:player_width]}"
+              height="#{metadata[:player_height]}"
+              scrolling="no"
+              frameborder="0"
+              allowfullscreen
+            ></iframe>
           HTML
         else
           html = Onebox::Engine::AllowlistedGenericOnebox.new(@url, @timeout).to_html
diff --git a/lib/onebox/engine/five_hundred_px_onebox.rb b/lib/onebox/engine/five_hundred_px_onebox.rb
index 9311812..806b5f9 100644
--- a/lib/onebox/engine/five_hundred_px_onebox.rb
+++ b/lib/onebox/engine/five_hundred_px_onebox.rb
@@ -13,7 +13,6 @@ module Onebox
         og = get_opengraph
         "<img src='#{og.image}' width='#{og.image_width}' height='#{og.image_height}' class='onebox' #{og.title_attr}>"
       end
-
     end
   end
 end
diff --git a/lib/onebox/engine/flickr_onebox.rb b/lib/onebox/engine/flickr_onebox.rb
index dd22b48..8819d6b 100644
--- a/lib/onebox/engine/flickr_onebox.rb
+++ b/lib/onebox/engine/flickr_onebox.rb
@@ -25,29 +25,28 @@ module Onebox
         album_title = "[Album] #{og.title}"
 

[... diff too long, it was truncated ...]

GitHub sha: 099cb0ba

This commit appears in #470 which was approved by eviltrout. It was merged by CvX.