lib/guillotine/adapters/active_record_adapter.rb
# Public: Stores the shortened version of a URL.
#
# url     - The String URL to shorten and store.
# code    - Optional String code for the URL.
# options - Optional Guillotine::Service::Options
#
# Returns the unique String code for the URL.  If the URL is added
# multiple times, this should return the same code.
Stores the shortened version of a URL.
url     - The String URL to shorten and store.
code    - Optional String code for the URL.
options - Optional Guillotine::Service::Options

Returns the unique String code for the URL.  If the URL is added
multiple times, this should return the same code.
Stores the shortened version of a URL . url - The String URL to shorten and store . code - Optional String code for the URL . options - Optional Guillotine :: Service :: Options Returns the unique String code for the URL . If the URL is added multiple times this should return the same code .
def add(url, code = nil, options = nil)
      if row = Url.select(:code).where(:url => url).first
        row[:code]
      else
        code = get_code(url, code, options)
        begin
          Url.create :url => url, :code => code
        rescue ActiveRecord::RecordNotUnique, ActiveRecord::StatementInvalid
          row = Url.select(:url).where(:code => code).first
          existing_url = row && row[:url]
          raise DuplicateCodeError.new(existing_url, url, code)
        end
        code
      end
    end
def add ( url , code = nil , options = nil ) if row = Url . select ( :code ) . where ( :url => url ) . first row [ :code ] else code = get_code ( url , code , options ) begin Url . create :url => url , :code => code rescue ActiveRecord :: RecordNotUnique , ActiveRecord :: StatementInvalid row = Url . select ( :url ) . where ( :code => code ) . first existing_url = row && row [ :url ] raise DuplicateCodeError . new ( existing_url , url , code ) end code end end
Public: Stores the shortened version of a URL.
Public : Stores the shortened version of a URL .
url
<not_specific>
code
<not_specific>
options
<not_specific>