Class: Firefly::Url
- Inherits:
-
Object
- Object
- Firefly::Url
- Includes:
- DataMapper::Resource
- Defined in:
- lib/tmin/url.rb
Class Method Summary collapse
-
.shorten(long_url, code = nil) ⇒ Object
Shorten a long_url and return a new FireFly::Url.
Instance Method Summary collapse
-
#register_click! ⇒ Object
Increase the visits counter by 1.
Class Method Details
.shorten(long_url, code = nil) ⇒ Object
Shorten a long_url and return a new FireFly::Url
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tmin/url.rb', line 19 def self.shorten(long_url, code = nil) code = nil if code !~ /\S/ the_url = Firefly::Url.first(:url => long_url) || Firefly::Url.create(:url => long_url) return the_url unless the_url.code.nil? code ||= get_me_a_code the_url.update(:code => code) the_url end |
Instance Method Details
#register_click! ⇒ Object
Increase the visits counter by 1
14 15 16 |
# File 'lib/tmin/url.rb', line 14 def register_click! self.update(:clicks => self.clicks + 1) end |