<commit_before>==TooShort

TooShort is a simple short URL service for your resources. And it works without an extra database table.

---- 

==Creating a short URL

<b>To create a short URL for one resource</b>

In your model:

  class Foo < ActiveRecord::Base
    has_a_short_url :host => 'http://2sh.de'
  end

  @foo.short_url # => http://2sh.de/2n9c

---

<b>To create short URLs for multiple resources:</b>

In an initializer file (config/initializer/too_short.rb):
  TooShort.options[:host] = 'http://2sh.de'

In your models:
  
  class Foo < ActiveRecord::Base
    has_a_short_url :scope => 'f'
  end
  
  class Bar < ActiveRecord::Base
    has_as_short_url :scope => 'b'
  end
  
  @foo.short_url # => http://2sh.de/*f*/2n9c
  @bar.short_url # => http://2sh.de/*b*/2n9c    
  
---

==Expanding a short URL

Add routes:
  get '/:scope/:hash' => 'short_urls#expand' # for multiple resources
  get '/:hash' => 'short_urls#expand' # for a single resource


Create a new controller:

  class ShortUrlController < ApplicationController
    include TooShort::ControllerMethods
  end

The default behavior is
* Valid URL -> redirect_to object
* Invalid URL -> respond_to with error message

  (see TooShort::ControllerMethods for details)  

This can be overwritten by overwriting two methods
  respond_to_valid_short_url
  respond_to_invalid_short_url

The object that was looked up for the given short URL is stored in
  @expanded_object
  
---  

==How the hashing is done:

  @post = Post.create
  @post.id        # => 123456
  post.short_url  # => http://2sh.de/2n9c
  123456.to_i(36) # => "2n9c"
  "2n9c".to_s(36) # => 123456

<em>I borrowed this from http://blog.saush.com/2009/04/13/clone-tinyurl-in-40-lines-of-ruby-code/</em>

I go into more detail on the inner workings of TooShort here: http://sens3.com/posts/tooshort-rubygem

== Contributing to too_short
 
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
* Fork the project
* Start a feature/bugfix branch
* Commit and push until you are happy with your contribution
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

== Copyright

Copyright (c) 2011 <NAME>. See LICENSE.txt for
further details.

<commit_msg>modified README slogan<commit_after>==TooShort

TooShort allows you to create persistent short URLs for your resources. And it works without any additional storage.

---- 

==Creating a short URL

<b>To create a short URL for one resource</b>

In your model:

  class Foo < ActiveRecord::Base
    has_a_short_url :host => 'http://2sh.de'
  end

  @foo.short_url # => http://2sh.de/2n9c

---

<b>To create short URLs for multiple resources:</b>

In an initializer file (config/initializer/too_short.rb):
  TooShort.options[:host] = 'http://2sh.de'

In your models:
  
  class Foo < ActiveRecord::Base
    has_a_short_url :scope => 'f'
  end
  
  class Bar < ActiveRecord::Base
    has_as_short_url :scope => 'b'
  end
  
  @foo.short_url # => http://2sh.de/*f*/2n9c
  @bar.short_url # => http://2sh.de/*b*/2n9c    
  
---

==Expanding a short URL

Add routes:
  get '/:scope/:hash' => 'short_urls#expand' # for multiple resources
  get '/:hash' => 'short_urls#expand' # for a single resource


Create a new controller:

  class ShortUrlController < ApplicationController
    include TooShort::ControllerMethods
  end

The default behavior is
* Valid URL -> redirect_to object
* Invalid URL -> respond_to with error message

  (see TooShort::ControllerMethods for details)  

This can be overwritten by overwriting two methods
  respond_to_valid_short_url
  respond_to_invalid_short_url

The object that was looked up for the given short URL is stored in
  @expanded_object
  
---  

==How the hashing is done:

  @post = Post.create
  @post.id        # => 123456
  post.short_url  # => http://2sh.de/2n9c
  123456.to_i(36) # => "2n9c"
  "2n9c".to_s(36) # => 123456

<em>I borrowed this from http://blog.saush.com/2009/04/13/clone-tinyurl-in-40-lines-of-ruby-code/</em>

I go into more detail on the inner workings of TooShort here: http://sens3.com/posts/tooshort-rubygem

== Contributing to too_short
 
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
* Fork the project
* Start a feature/bugfix branch
* Commit and push until you are happy with your contribution
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

== Copyright

Copyright (c) 2011 <NAME>. See LICENSE.txt for
further details.


{'fraction_non_alphanumeric': 0.097765896505633, 'fraction_numerical': 0.02100439182738209, 'mean_word_length': 3.6068601583113455, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3650729', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1662, 'n_words': 618}