too_short 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  ==TooShort
2
2
 
3
- TooShort is a simple short URL service for your resources. And it works without an extra database table.
3
+ TooShort allows you to create persistent short URLs for your resources. And it works without any additional storage.
4
4
 
5
5
  ----
6
6
 
@@ -33,19 +33,14 @@ In your models:
33
33
  has_as_short_url :scope => 'b'
34
34
  end
35
35
 
36
- @foo.short_url # => http://2sh.de/*f*/2n9c
37
- @bar.short_url # => http://2sh.de/*b*/2n9c
36
+ @foo.short_url # => http://2sh.de/f/2n9c
37
+ @bar.short_url # => http://2sh.de/b/2n9c
38
38
 
39
39
  ---
40
40
 
41
41
  ==Expanding a short URL
42
42
 
43
43
  Add routes:
44
- (Rails 2)
45
- map.connect '/:scope/:hash', :controller => :short_urls, :action => :expand # for multiple resources
46
- map.connect '/:hash', :controller => :short_urls, :action => :expand # for a single resource
47
-
48
- (Rails 3)
49
44
  get '/:scope/:hash' => 'short_urls#expand' # for multiple resources
50
45
  get '/:hash' => 'short_urls#expand' # for a single resource
51
46
 
@@ -67,7 +62,7 @@ This can be overwritten by overwriting two methods
67
62
  respond_to_invalid_short_url
68
63
 
69
64
  The object that was looked up for the given short URL is stored in
70
- @expanded_object
65
+ @object_from_short_url
71
66
 
72
67
  ---
73
68
 
@@ -75,12 +70,13 @@ The object that was looked up for the given short URL is stored in
75
70
 
76
71
  @post = Post.create
77
72
  @post.id # => 123456
78
- post.short_url # => http://2sh.de/*2n9c*
73
+ post.short_url # => http://2sh.de/2n9c
79
74
  123456.to_i(36) # => "2n9c"
80
75
  "2n9c".to_s(36) # => 123456
81
76
 
82
- <em>I borrowed this from http://blog.saush.com/2009/04/13/clone-tinyurl-in-40-lines-of-ruby-code/
77
+ <em>I borrowed this from http://blog.saush.com/2009/04/13/clone-tinyurl-in-40-lines-of-ruby-code/</em>
83
78
 
79
+ I go into more detail on the inner workings of TooShort here: http://sens3.com/posts/tooshort-rubygem
84
80
 
85
81
  == Contributing to too_short
86
82
 
data/Rakefile CHANGED
@@ -15,8 +15,8 @@ Jeweler::Tasks.new do |gem|
15
15
  gem.name = "too_short"
16
16
  gem.homepage = "http://github.com/sens3/too_short"
17
17
  gem.license = "MIT"
18
- gem.summary = %Q{A simple short URL service for your resources}
19
- gem.description = %Q{A simple short URL service for your resources, no extra database table necessary}
18
+ gem.summary = %Q{A URL shortener for your resources}
19
+ gem.description = %Q{TooShort allows you to create persistent short URLs for your resources, without any additional storage.}
20
20
  gem.email = "makesens3@gmail.com"
21
21
  gem.authors = ["Simon Baumgartner"]
22
22
  # Include your dependencies below. Runtime dependencies are required when using your gem,
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -1,6 +1,16 @@
1
1
  module TooShort
2
2
  module ARBaseExtensions
3
3
 
4
+
5
+ # To be included in your model, i.e
6
+ # class Post
7
+ # has_a_short_url
8
+ # end
9
+ #
10
+ # Takes the following options:
11
+ # host: short URL host to use (alternatively to be defined in an initializer file)
12
+ # scope: the scope for this model, necessary when short URLs are used in multiple models
13
+ #
4
14
  def has_a_short_url(options={})
5
15
  short_url_options = TooShort.options.merge(options)
6
16
  short_url_options.symbolize_keys!
@@ -1,16 +1,27 @@
1
1
  module TooShort
2
+
3
+ # To be included in the controller that should handle short URLs, i.e
4
+ # class ShortUrlsController < ApplicationController
5
+ # include TooShort::ControllerMethods
6
+ # end
7
+ #
8
+ # response handling can be customized by overwriting these methods
9
+ # respond_to_valid_short_url
10
+ # respond_to_invalid_short_url
11
+ #
12
+ # the object that was looked up can be accessed via @object_from_short_url
2
13
  module ControllerMethods
3
14
  def expand
4
15
  require_all_model_classes
5
- if @expanded_object = TooShort.expand_to_object(params[:scope], params[:hash])
16
+ if @object_from_short_url = TooShort.expand_to_object(params[:scope], params[:hash])
6
17
  respond_to_valid_short_url
7
18
  else
8
19
  respond_to_invalid_short_url
9
20
  end
10
21
  end
11
-
22
+
12
23
  def respond_to_valid_short_url
13
- redirect_to @expanded_object
24
+ redirect_to @object_from_short_url
14
25
  end
15
26
 
16
27
  def respond_to_invalid_short_url
data/too_short.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{too_short}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Simon Baumgartner"]
12
- s.date = %q{2011-01-30}
13
- s.description = %q{A simple short URL service for your resources, no extra database table necessary}
12
+ s.date = %q{2011-01-31}
13
+ s.description = %q{TooShort allows you to create persistent short URLs for your resources, without any additional storage.}
14
14
  s.email = %q{makesens3@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
@@ -37,7 +37,7 @@ Gem::Specification.new do |s|
37
37
  s.licenses = ["MIT"]
38
38
  s.require_paths = ["lib"]
39
39
  s.rubygems_version = %q{1.3.7}
40
- s.summary = %q{A simple short URL service for your resources}
40
+ s.summary = %q{A URL shortener for your resources}
41
41
  s.test_files = [
42
42
  "spec/ar_base_extensions_spec.rb",
43
43
  "spec/controller_methods_spec.rb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: too_short
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Simon Baumgartner
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-30 00:00:00 +01:00
18
+ date: 2011-01-31 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -112,7 +112,7 @@ dependencies:
112
112
  - 0
113
113
  version: "0"
114
114
  requirement: *id006
115
- description: A simple short URL service for your resources, no extra database table necessary
115
+ description: TooShort allows you to create persistent short URLs for your resources, without any additional storage.
116
116
  email: makesens3@gmail.com
117
117
  executables: []
118
118
 
@@ -170,7 +170,7 @@ rubyforge_project:
170
170
  rubygems_version: 1.3.7
171
171
  signing_key:
172
172
  specification_version: 3
173
- summary: A simple short URL service for your resources
173
+ summary: A URL shortener for your resources
174
174
  test_files:
175
175
  - spec/ar_base_extensions_spec.rb
176
176
  - spec/controller_methods_spec.rb