Class: Redirect
- Inherits:
-
Object
- Object
- Redirect
- Includes:
- Mongoid::Document
- Defined in:
- lib/model/redirect.rb
Constant Summary collapse
- @@host =
'http://localhost:3000/'
- @@path =
'a/'
- @@append_tracking_info =
false
- @@append_google_analytics =
false
Class Method Summary collapse
-
.append_google_analytics ⇒ Object
Gets the value of the flag to determine if google analytics info should be sent with the url.
-
.append_google_analytics=(google_analytics_flag) ⇒ Object
Sets the value of the flag to determine if google analytics info should be sent with the url appends utm_source=<@@host>&utm_campaign=<Redirect._id>__<RedirectLog._id>.
-
.append_tracking_info ⇒ Object
Gets the value of the flag to determine if tracking info should be sent with the url.
-
.append_tracking_info=(tracking_info_flag) ⇒ Object
Sets the value of the flag to determine if tracking info should be sent with the url adds the following to the url being redirected to redirect_mongo_id=<Redirect._id>&redirect_log_mongo_id=<RedirectLog._id>.
-
.create_shortened_url(original_url) ⇒ Redirect
Creates a shortened url id of 8 characters, creates and saves a redirect object with the new shortened url id.
-
.host ⇒ String
Gets the host for the shortened url.
-
.host=(host) ⇒ Object
Sets the host to use in the shortened url.
-
.path ⇒ String
Gets the path for the shortened url.
-
.path=(path) ⇒ Object
Sets the path to use in the shortened url.
Instance Method Summary collapse
-
#shortened_path ⇒ String
Returns the shortened url path consisting of the path and shortened id.
-
#shortened_url ⇒ String
Returns the entire shortened url which consists of the host, path and shortened id.
Class Method Details
.append_google_analytics ⇒ Object
Gets the value of the flag to determine if google analytics info should be sent with the url
21 22 23 |
# File 'lib/model/redirect.rb', line 21 def self.append_google_analytics @@append_google_analytics end |
.append_google_analytics=(google_analytics_flag) ⇒ Object
Sets the value of the flag to determine if google analytics info should be sent with the url appends utm_source=<@@host>&utm_campaign=<Redirect._id>__<RedirectLog._id>
15 16 17 |
# File 'lib/model/redirect.rb', line 15 def self.append_google_analytics= google_analytics_flag @@append_google_analytics = google_analytics_flag end |
.append_tracking_info ⇒ Object
Gets the value of the flag to determine if tracking info should be sent with the url
35 36 37 |
# File 'lib/model/redirect.rb', line 35 def self.append_tracking_info @@append_tracking_info end |
.append_tracking_info=(tracking_info_flag) ⇒ Object
Sets the value of the flag to determine if tracking info should be sent with the url adds the following to the url being redirected to redirect_mongo_id=<Redirect._id>&redirect_log_mongo_id=<RedirectLog._id>
29 30 31 |
# File 'lib/model/redirect.rb', line 29 def self.append_tracking_info= tracking_info_flag @@append_tracking_info = tracking_info_flag end |
.create_shortened_url(original_url) ⇒ Redirect
Creates a shortened url id of 8 characters, creates and saves a redirect object with the
new shortened url id.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/model/redirect.rb', line 68 def self.create_shortened_url(original_url) redir = self.new :original_url => original_url shortened_id = SecureRandom.urlsafe_base64(6) duplicate_find = Redirect.where(:shortened_id => shortened_id) if duplicate_find and duplicate_find.last and (shortened_id == duplicate_find.last.shortened_id) shortened_id = SecureRandom.urlsafe_base64(6) end redir.shortened_id = shortened_id redir.save! redir end |
.host ⇒ String
Gets the host for the shortened url
60 61 62 |
# File 'lib/model/redirect.rb', line 60 def self.host @@host.end_with?('/') ? @@host : "#{@@host}/" end |
.host=(host) ⇒ Object
Sets the host to use in the shortened url
54 55 56 |
# File 'lib/model/redirect.rb', line 54 def self.host= host @@host = host end |
.path ⇒ String
Gets the path for the shortened url
47 48 49 50 |
# File 'lib/model/redirect.rb', line 47 def self.path path = @@path.end_with?('/') ? @@path : "#{@@path}/" path.start_with?('/') ? path[1..path.length] : path end |
.path=(path) ⇒ Object
Sets the path to use in the shortened url
41 42 43 |
# File 'lib/model/redirect.rb', line 41 def self.path= path @@path = path end |
Instance Method Details
#shortened_path ⇒ String
Returns the shortened url path consisting of the path and shortened id
88 89 90 |
# File 'lib/model/redirect.rb', line 88 def shortened_path "#{self.class.path}#{shortened_id}" end |
#shortened_url ⇒ String
Returns the entire shortened url which consists of the host, path and shortened id
82 83 84 |
# File 'lib/model/redirect.rb', line 82 def shortened_url "#{self.class.host}#{self.class.path}#{shortened_id}" end |