Skip to content

Commit

Permalink
Use 1.9-style hashrockets
Browse files Browse the repository at this point in the history
  • Loading branch information
veezus committed May 7, 2011
1 parent a245be4 commit 3c90b6e
Show file tree
Hide file tree
Showing 61 changed files with 264 additions and 264 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -38,7 +38,7 @@ def load_user_from_cookie

def create_user
user = User.create!
cookies[:user_id] = {:value => user.id, :expires => 5.years.from_now}
cookies[:user_id] = {value: user.id, expires: 5.years.from_now}
user
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/twitter_controller.rb
@@ -1,7 +1,7 @@
class TwitterController < ApplicationController
def index
tweets
render :index, :layout => false
render :index, layout: false
end

def tweets
Expand All @@ -13,7 +13,7 @@ def tweets
search
end
rescue Timeout::Error, Crack::ParseError, EOFError, SocketError, SystemCallError
render :nothing => true
render nothing: true
end
helper_method :tweets
hide_action :tweets
Expand Down
50 changes: 25 additions & 25 deletions app/controllers/vurls_controller.rb
Expand Up @@ -2,10 +2,10 @@ class VurlsController < ApplicationController

expose(:current_vurls) { current_user.vurls }
expose(:new_vurl) do
vurl_params = (params[:vurl] || {}).reverse_merge!(:url => params[:url])
vurl_params = (params[:vurl] || {}).reverse_merge!(url: params[:url])
Vurl.new vurl_params
end
expose(:recent_popular_vurls) { Vurl.popular_since current_period_ago, :limit => 8 }
expose(:recent_popular_vurls) { Vurl.popular_since current_period_ago, limit: 8 }
expose(:most_popular_vurls) { Vurl.most_popular.not_spam }

skip_before_filter :verify_authenticity_token, :only => :create
Expand All @@ -18,7 +18,7 @@ def show

def real_time_clicks
respond_to do |format|
format.html { render :nothing => true }
format.html { render nothing: true }
format.xml
end
end
Expand All @@ -34,33 +34,33 @@ def flag_as_spam
end

def image_screenshot
render :layout => false
render layout: false
end

def screenshot
render :partial => 'screenshot', :locals => {:vurl => current_vurl}
render partial: 'screenshot', locals: {vurl: current_vurl}
end

def title
render :partial => 'title', :locals => {:vurl => current_vurl}
render partial: 'title', locals: {vurl: current_vurl}
end

def description
render :partial => 'description', :locals => {:vurl => current_vurl}
render partial: 'description', locals: {vurl: current_vurl}
end

def stats
if current_vurl.nil?
render :template => 'vurls/not_found' and return
render template: 'vurls/not_found' and return
end
respond_to do |format|
format.html { render :show }
format.xml { render :xml => current_vurl }
format.xml { render xml: current_vurl }
end
end

def preview
redirect_to :action => :stats, :slug => params[:slug]
redirect_to action: :stats, slug: params[:slug]
end

def new
Expand All @@ -69,7 +69,7 @@ def new
else
respond_to do |format|
format.html
format.xml { render :xml => new_vurl }
format.xml { render xml: new_vurl }
end
end
end
Expand All @@ -83,21 +83,21 @@ def api
new_vurl.user = if api_token && user = User.find_by_api_token(api_token)
user
else
User.create!(:name => 'API')
User.create!(name: 'API')
end

respond_to do |format|
if suspected_spam_user?
format.html { render :text => "Get thee behind me, spammer" and return }
format.json { render :json => {:errors => "Get thee behind me, spammer"} and return }
format.html { render text: "Get thee behind me, spammer" and return }
format.json { render json: {errors: "Get thee behind me, spammer"} and return }
end

if new_vurl.save
format.html { render :text => redirect_url(new_vurl.slug) }
format.json { render :json => {:shortUrl => redirect_url(new_vurl.slug)} }
format.html { render text: redirect_url(new_vurl.slug) }
format.json { render json: {shortUrl: redirect_url(new_vurl.slug)} }
else
format.html { render :text => new_vurl.errors.full_messages }
format.json { render :json => {:errors => new_vurl.errors.full_messages.first} }
format.html { render text: new_vurl.errors.full_messages }
format.json { render json: {errors: new_vurl.errors.full_messages.first} }
end
end
end
Expand All @@ -115,10 +115,10 @@ def create
if new_vurl.save
flash[:notice] = 'Vurl was successfully created.'
format.html { redirect_to stats_path(new_vurl.slug) }
format.xml { render :xml => new_vurl, :status => :created, :location => new_vurl }
format.xml { render xml: new_vurl, status: :created, location: new_vurl }
else
format.html { render :action => "new" }
format.xml { render :xml => new_vurl.errors, :status => :unprocessable_entity }
format.html { render action: "new" }
format.xml { render xml: new_vurl.errors, status: :unprocessable_entity }
end
end
end
Expand All @@ -135,13 +135,13 @@ def destroy

def redirect
if current_vurl
click = Click.new(:vurl => current_vurl, :ip_address => request.env["REMOTE_ADDR"], :user_agent => request.user_agent, :referer => request.referer)
click = Click.new(vurl: current_vurl, ip_address: request.env["REMOTE_ADDR"], user_agent: request.user_agent, referer: request.referer)
unless click.save
logger.warn "Couldn't create Click for Vurl (#{current_vurl.inspect}) because it had the following errors: #{click.errors}"
end
redirect_to safe_url_for(current_vurl), :status => :moved_permanently
redirect_to safe_url_for(current_vurl), status: :moved_permanently
else
render :template => 'vurls/not_found'
render template: 'vurls/not_found'
end
end

Expand All @@ -150,7 +150,7 @@ def random
end

def safe_url_for(vurl)
vurl.flagged_as_spam? ? spam_url(:slug => vurl.slug) : vurl.url
vurl.flagged_as_spam? ? spam_url(slug: vurl.slug) : vurl.url
end
hide_action :safe_url_for

Expand Down
8 changes: 4 additions & 4 deletions app/helpers/application_helper.rb
Expand Up @@ -31,14 +31,14 @@ def clippy(text, bgcolor='#FFFFFF')
/>
</object>
EOF
content_tag(:span, html, :class => 'clippy')
content_tag(:span, html, class: 'clippy')
end

def link_to_period period
if period == current_period
content_tag :span, period.titleize, :class => 'selected_period period_link'
content_tag :span, period.titleize, class: 'selected_period period_link'
else
link_to period.titleize, "?period=#{period}", :class => 'deselected_period period_link'
link_to period.titleize, "?period=#{period}", class: 'deselected_period period_link'
end
end

Expand All @@ -47,7 +47,7 @@ def popular_period_links
end

def period_link period
current_period == period ? period : link_to(period, root_path(:period => period))
current_period == period ? period : link_to(period, root_path(period: period))
end

def tab_class_for(link_name)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/vurls_helper.rb
Expand Up @@ -12,7 +12,7 @@ def display_stats_link?
end

def title_or_truncated_url(vurl)
vurl.title.present? ? vurl.title : truncate(vurl.url, :length => 50)
vurl.title.present? ? vurl.title : truncate(vurl.url, length: 50)
end

def absolute_url_for(url)
Expand Down
4 changes: 2 additions & 2 deletions app/models/click.rb
@@ -1,6 +1,6 @@
class Click < ActiveRecord::Base
belongs_to :vurl, :counter_cache => true
belongs_to :vurl, counter_cache: true
validates_presence_of :vurl_id, :ip_address, :user_agent

named_scope :since, lambda {|date| { :conditions => ["created_at >= ?", date] } }
named_scope :since, lambda {|date| { conditions: ["created_at >= ?", date] } }
end
20 changes: 10 additions & 10 deletions app/models/user.rb
Expand Up @@ -7,20 +7,20 @@ class User < ActiveRecord::Base
config.logged_in_timeout 5.years
end

validates_format_of :email, :with => /^.+@.+\..+$/, :allow_blank => true
validates_format_of :email, with: /^.+@.+\..+$/, allow_blank: true
validates_format_of :website,
:with => /^((http|https):\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.?[a-z]{2,5}((:[0-9]{1,5})?\/.*)?$/ix,
:allow_blank => true
with: /^((http|https):\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.?[a-z]{2,5}((:[0-9]{1,5})?\/.*)?$/ix,
allow_blank: true
validates_format_of :blog,
:with => /^((http|https):\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.?[a-z]{2,5}((:[0-9]{1,5})?\/.*)?$/ix,
:allow_blank => true
with: /^((http|https):\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.?[a-z]{2,5}((:[0-9]{1,5})?\/.*)?$/ix,
allow_blank: true

validates_presence_of :password, :on => :update, :if => :claim_code_changed?
validates_presence_of :password, on: :update, if: :claim_code_changed?

validates_presence_of :email, :on => :update
validates_uniqueness_of :email, :allow_blank => true
validates_presence_of :email, on: :update
validates_uniqueness_of :email, allow_blank: true

has_many :vurls, :order => 'created_at DESC', :include => :clicks
has_many :vurls, order: 'created_at DESC', include: :clicks

before_validation_on_create :set_default_password
before_create :generate_api_token,
Expand All @@ -32,7 +32,7 @@ def claimed?
end

def claim(attrs)
update_attributes(attrs.merge(:claim_code => nil))
update_attributes(attrs.merge(claim_code: nil))
end

def unclaimed?
Expand Down
40 changes: 20 additions & 20 deletions app/models/vurl.rb
Expand Up @@ -2,35 +2,35 @@ class Vurl < ActiveRecord::Base
require 'nokogiri'

has_attached_file :screenshot,
:styles => {
styles: {
:original => "512x384",
:thumb => "102x77"
},
:default_style => :thumb,
:convert_options => {:all => '-quality 70'},
:url => "/screenshots/:slug-:style.png",
:default_url => "/images/missing-:style.png"
default_style: :thumb,
convert_options: {:all => '-quality 70'},
url: "/screenshots/:slug-:style.png",
default_url: "/images/missing-:style.png"

state_machine :status, :initial => :nominal do
state_machine :status, initial: :nominal do
event :flag_as_spam do
transition :nominal => :flagged_as_spam
transition nominal: :flagged_as_spam
end
end

belongs_to :user
has_many :clicks

validates_presence_of :url, :user
validates_format_of :url, :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.?[a-z]{2,5}((:[0-9]{1,5})?\/.*)?$/ix
validates_format_of :url, with: /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.?[a-z]{2,5}((:[0-9]{1,5})?\/.*)?$/ix
validate :appropriateness_of_url
validate :not_a_spam_site

before_validation :format_url
before_create :set_slug
after_create :add_to_queues

named_scope :most_popular, lambda {|*args| { :order => 'clicks_count desc', :limit => args.first || 5 } }
named_scope :not_spam, { :conditions => "status <> 'flagged_as_spam'" }
named_scope :most_popular, lambda {|*args| { order: 'clicks_count desc', limit: args.first || 5 } }
named_scope :not_spam, { conditions: "status <> 'flagged_as_spam'" }

class << self
def popular_since(period_ago, options={})
Expand All @@ -52,13 +52,13 @@ def popular_since(period_ago, options={})
end

def random
find(:first, :offset => (Vurl.count * rand).to_i)
find(:first, offset: (Vurl.count * rand).to_i)
end

def tweet_most_popular_of_the_day
require 'twitter'

vurl = Vurl.popular_since(1.day.ago, :limit => 1).first
vurl = Vurl.popular_since(1.day.ago, limit: 1).first
return if vurl.nil?

intro = 'Most popular vurl today? '
Expand All @@ -74,7 +74,7 @@ def tweet_most_popular_of_the_day
end

def take_screenshot!
self.screenshot = Screenshot.new(:vurl => self).snap!
self.screenshot = Screenshot.new(vurl: self).snap!
self.screenshot_taken = true
self.screenshot_queued = false
save
Expand Down Expand Up @@ -103,7 +103,7 @@ def last_sixty_minutes(start_time=Time.now)
minutes = []
60.times do |i|
new_time = i.minutes.ago(start_time)
minutes << new_time.change(:hour => new_time.hour, :min => new_time.min)
minutes << new_time.change(hour: new_time.hour, min: new_time.min)
end
minutes.reverse
end
Expand All @@ -112,7 +112,7 @@ def last_twenty_four_hours(start_time=Time.now)
hours = []
24.times do |i|
new_time = i.hours.ago(start_time)
hours << new_time.change(:hour => new_time.hour)
hours << new_time.change(hour: new_time.hour)
end
hours.reverse
end
Expand All @@ -121,19 +121,19 @@ def last_seven_days(start_date=Time.now)
dates = []
7.times do |i|
new_date = i.days.ago(start_date)
dates << new_date.change(:hour => 0)
dates << new_date.change(hour: 0)
end
dates.reverse
end

def clicks_for_last period
case period
when 'hour'
clicks.since(1.hour.ago).all(:select => 'clicks.*, MINUTE(clicks.created_at) AS minute').group_by(&:minute)
clicks.since(1.hour.ago).all(select: 'clicks.*, MINUTE(clicks.created_at) AS minute').group_by(&:minute)
when 'day'
clicks.since(1.day.ago).all(:select => 'clicks.*, HOUR(clicks.created_at) AS hour').group_by(&:hour)
clicks.since(1.day.ago).all(select: 'clicks.*, HOUR(clicks.created_at) AS hour').group_by(&:hour)
when 'week'
clicks.since(1.week.ago).all(:select => 'clicks.*, DAY(clicks.created_at) AS day').group_by(&:day)
clicks.since(1.week.ago).all(select: 'clicks.*, DAY(clicks.created_at) AS day').group_by(&:day)
end
end

Expand Down Expand Up @@ -196,7 +196,7 @@ def construct_url
end

def set_slug
if vurl = Vurl.find(:first, :order => 'id DESC')
if vurl = Vurl.find(:first, order: 'id DESC')
self.slug = vurl.slug.succ
else
self.slug = 'AA'
Expand Down

0 comments on commit 3c90b6e

Please sign in to comment.