jakimowicz-longurl 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 2
2
+ :patch: 3
3
3
  :major: 0
4
4
  :minor: 0
@@ -6,7 +6,7 @@ module LongURL
6
6
  # First, expand will try to expand url using longurl.org service.
7
7
  # Then, it will try to direct follow redirections on the given url and returns final one.
8
8
  # === Options
9
- # * <tt>:cache</tt> : cache object to use, must implement get and set functions. See LongURL::Cache.
9
+ # * <tt>:cache</tt> : cache object to use, must implement [] and []= functions.
10
10
  # === Types
11
11
  # <tt>url</tt> is expected to be a String and returns a String with the url.
12
12
  # === Examples
@@ -29,9 +29,9 @@ module LongURL
29
29
  class Expander
30
30
  # Initialize a new Expander.
31
31
  # === Options
32
- # * <tt>:cache</tt>: define a cache which Expander can use. It must implements set and get methods like LongURL::Cache.
32
+ # * <tt>:cache</tt>: define a cache which Expander can use. It must implements [] and []= methods.
33
33
  def initialize(options = {})
34
- @@cache = options[:cache] || LongURL::Cache.new
34
+ @@cache = options[:cache] || Hash.new
35
35
  @@service = Service.new(:cache => @@cache)
36
36
  end
37
37
 
@@ -45,7 +45,7 @@ module LongURL
45
45
  # Try to directly resolve url using LongURL::Direct to get final redirection.
46
46
  # This call is cached.
47
47
  def direct_resolution(url)
48
- @@cache.get(url) || @@cache.set(url, Direct.follow_redirections(url))
48
+ @@cache[url] ||= Direct.follow_redirections(url)
49
49
  end
50
50
 
51
51
  # Expand given url using LongURL::Service only. If given url is not a expandable url, it will still be given to Service.
@@ -11,10 +11,8 @@ module LongURL
11
11
  class Service
12
12
 
13
13
  def initialize(params = {})
14
- @@cache = params[:cache]
15
-
16
- @@supported_services = @@cache.get('supported_services')
17
- @@supported_services ||= @@cache.set('supported_services', fetch_supported_services)
14
+ @@cache = params[:cache] || Hash.new
15
+ @@supported_services = cached_or_fetch_supported_services
18
16
  end
19
17
 
20
18
  def query_supported_service_only(url)
@@ -46,6 +44,10 @@ module LongURL
46
44
 
47
45
  protected
48
46
 
47
+ def cached_or_fetch_supported_services
48
+ @@cache['supported_services'] ||= fetch_supported_services
49
+ end
50
+
49
51
  def check_and_escape(url)
50
52
  check url
51
53
  CGI.escape url
data/lib/longurl.rb CHANGED
@@ -6,6 +6,5 @@ require 'longurl/constants'
6
6
  require 'longurl/exceptions'
7
7
  require 'longurl/service'
8
8
  require 'longurl/direct'
9
- require 'longurl/cache'
10
9
  require 'longurl/expander'
11
10
  require 'longurl/expand'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jakimowicz-longurl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabien Jakimowicz