Permalink
Browse files

The search is over. All bugs gone. Forever. All of them.

  • Loading branch information...
1 parent 6b77554 commit 7ddfc5d37f6e7ccf13629e54638d0c1af54ea490 @sudara committed Feb 13, 2013
@@ -294,7 +294,7 @@ def register_listen
def bot?
ip = request.remote_ip
- return true unless present? request.user_agent
+ return true unless request.user_agent.present?
return true if @@bad_ip_ranges.any?{|cloaked_ip| ip.match /^#{cloaked_ip}/ } # check bad ips that fake user agent
not browser? or @@bots.any?{|bot_agent| @agent.include? bot_agent} # check user agent agaisnt both white and black lists
end
@@ -110,7 +110,7 @@ def index
) if moderator? or admin?
end
format.json do
- if present?(params[:start]) && present?(params[:end])
+ if params[:start].present? && params[:end].present?
@comments = Comment.count_by_user(params[:start].to_date, params[:end].to_date, params[:limit].to_i)
else
@comments = Comment.count_by_user(30.days.ago, Date.today)
@@ -16,7 +16,7 @@ def index
@user.playlists.include_private :
@user.playlists.public
- if present?(@all_playlists)
+ if @all_playlists.present?
middle = (@all_playlists.size + 1) / 2
@playlists_left = @all_playlists[ 0 ... middle ]
@@ -12,7 +12,7 @@ def index
protected
def deliver_results
- if present?(params[:query])
+ if params[:query].present?
@query = session[:last_search] = params[:query]
@users = User.paginate(:all, :conditions => User.conditions_by_like(@query,['users.display_name','users.login','users.bio','users.city','users.country']), :include => :pic, :per_page => 15, :page => params[:page])
@assets = Asset.paginate(:all, :conditions => Asset.conditions_by_like(@query,['assets.title', 'assets.description', 'assets.filename']), :include => [:user => :pic], :per_page => 15, :page => params[:page])
@@ -161,14 +161,14 @@ def attach_pic
def update
# fix to not care about password stuff unless both fields are set
- (params[:user][:password] = params[:user][:password_confirmation] = nil) unless present?(params[:user][:password]) and present?(params[:user][:password_confirmation])
+ (params[:user][:password] = params[:user][:password_confirmation] = nil) unless params[:user][:password].present? and params[:user][:password_confirmation].present?
# If the user changes the :block_guest_comments setting then it requires
# that the cache for all their tracks be invalidated or else the cached
# tabs will not change
flush_asset_caches = false
if params[:user] && params[:user][:settings] && params[:user][:settings][:block_guest_comments]
- currently_blocking_guest_comments = @user.settings && @user.settings.present?('block_guest_comments') && @user.settings['block_guest_comments'] == 'true'
+ currently_blocking_guest_comments = @user.settings.present? && @user.settings['block_guest_comments'] && @user.settings['block_guest_comments'] == 'true'
flush_asset_caches = params[:user][:settings][:block_guest_comments] == ( currently_blocking_guest_comments ? "false" : "true" )
end
@@ -21,9 +21,9 @@ def avatar(user, size=nil)
end
def user_location(user)
- if (user.present?(:city) && user.present?(:country))
+ if user.city.present? && user.country.present?
"from #{[user.city.strip, user.country.strip].compact.join(', ')}"
- elsif (user.present?(:city) || user.present?(:country))
+ elsif user.city.present? || user.country.present?
"from #{[user.city.strip, user.country.strip].compact.to_s}"
end
end
@@ -40,7 +40,7 @@ def user_image_link(user, size = :large)
end
def notice_hidden?(notice)
- logged_in? && current_user.present?(:settings) && current_user.settings.present?('hide_notice') && current_user.settings['hide_notice'].present?(notice)
+ logged_in? && current_user.settings.present? && current_user.settings['hide_notice'].present? && current_user.settings['hide_notice'][notice].present?
end
def setting(symbol_or_string, user=current_user)
View
@@ -153,7 +153,7 @@ def type
end
def guest_can_comment?
- if user.settings && user.settings.present?( 'block_guest_comments' )
+ if user.settings && user.settings['block_guest_comments'].present?
user.settings['block_guest_comments'] == "false"
else
true
@@ -1,4 +1,4 @@
-<% if present?(@listeners)%>
+<% if @listeners.present? %>
<h2 class="box">Recent Listeners</h2>
<div id="recent_listeners" class="box static_content">
@@ -54,10 +54,10 @@
<% end %>
<% content_for :right do %>
- <%= render :partial => 'favoriters' if present?(@favoriters)%>
+ <%= render :partial => 'favoriters' if @favoriters.present?%>
<%= render :partial => 'users'%>
<div class="clear"> </div>
- <%= render :partial => 'shared/comments' if present?(@comments) %>
+ <%= render :partial => 'shared/comments' if @comments.present? %>
<% end %>
@@ -1,4 +1,4 @@
-<% if present? @featured_tracks %>
+<% if @featured_tracks.present? %>
<div id="featured_tracks" class="box">
<h2 class="box">Featured Tracks</h2>
<%= link_to "view all", user_tracks_path(@feature.featured_user), :class=> 'view_all' if @feature.featured_user.has_tracks?%>
@@ -44,7 +44,7 @@
<%= link_to "#{@user.playlists.public.count} albums/mixes", user_playlists_path(@user) if @user.playlists.public.count > 0 %><br/>
<%= link_to @user.assets_count, user_tracks_path(@user) %> tracks on alonetone<br/>
tracks listened to: <%= link_to @user.number_of_tracks_listened_to, listens_path(@user) %><br/>
- <%= itunes_link_for(@user) if present? @user.itunes %><br/>
+ <%= itunes_link_for(@user) if @user.itunes.present? %><br/>
<%= "This feature viewed #{@feature.views_count} times" if authorized? %>
</div>
<%= link_to " ", user_home_path(@user), :class => 'view_more'%>
@@ -51,7 +51,7 @@
<% end %>
</table>
- <% if present? @online %>
+ <% if @online.present? %>
<div class="static_content" id="currently_online">
alonetoners online:
<% @online.each do |user| %>
@@ -66,7 +66,7 @@
<%= link_to('view all recent posts &rArr;', posts_path, :class=>'view_all', :title => 'view all recent posts') if Post.first %>
</div>
- <% if logged_in? && present?(@user_topics) %>
+ <% if logged_in? && @user_topics.present? %>
<h2>Conversations you are a part of</h2>
<table border="0" cellspacing="0" cellpadding="0" class="wide topics">
<tr>
@@ -2,7 +2,7 @@
<% div_for @playlist, :class => "box #{(@playlist.has_tracks? ? '' : 'empty')} #{@playlist.type}" do %>
<div class="playlist_title box">
- <h2><%= h(@playlist.title)+(@playlist.present?(:year) ? " (#{@playlist.year})" : '') %></h2>
+ <h2><%= h(@playlist.title)+@playlist.year.present? ? " (#{@playlist.year})" : '') %></h2>
<h3><%= pluralize @playlist.tracks_count, 'track'%> by <%= (@playlist.is_mix? ? 'various alonetone artists' : @playlist.user.name )%></h3>
<% if authorized_for(@playlist) %>
<%= link_to "edit", edit_user_playlist_path(@user, @playlist), :class => 'edit right' %>
@@ -22,7 +22,7 @@
<%= pagination @posts %>
</div>
-<% if present? @posts %>
+<% if @posts.present? %>
<%= render :partial => 'posts/posts' %>
<% else %>
<h2>:( Sorry, nobody has bothered to talk about '<%=h params[:forum_q]%>' before</h2>
@@ -2,19 +2,19 @@
<div class="search_results clearfix">
<div class="column results">
<div class="suggestion clearfix" style="text-align:left;">
- <% if !present?(@users, @assets) %>
+ <% if !@users.present? && !@assets.present? %>
Hm, didn't find any users or tracks named "<%=h @query %>"
<% else %>
Results for "<%=h @query %>"
<% end %>
</div>
- <% if present?(@users) %>
+ <% if @users.present? %>
<h2>Alonetone Artists and Listeners</h2>
<div id="user_search_results">
<%= render :partial => 'shared/user.html.erb', :collection => @users %>
</div>
<% end %>
- <% if present?(@assets) %>
+ <% if @assets.present? %>
<h2>Uploaded Music</h2>
<%= render :partial => 'shared/asset', :collection => @assets %>
<% end %>
@@ -1,10 +1,10 @@
-<% if !present?(@users, @assets) %>
+<% if !@users.present? && !@assets.present? %>
<h2>Hm, didn't find any users or tracks named "<%=h @query %>"</h2>
<% else %>
<h1>Results for "<%= h @query %>"</h1>
<% end %>
-<% if present?(@users) %>
+<% if @users.present? %>
<% content_for :left do %>
<h2>Artists and Listeners</h2>
<div id="user_search_results">
@@ -14,7 +14,7 @@
<% end %>
-<% if present?(@assets) %>
+<% if @assets.present? %>
<% content_for :right do %>
<h2>Tracks that match "<%=h @query %>"</h2>
<%= render :partial => 'assets/asset', :collection => @assets if @assets %>
@@ -4,5 +4,5 @@
<%= image_tag(playlist.cover(:large), :class => 'cover_125', :alt => "#{h(playlist.title)} by #{h(playlist.user.name)}") %>
- <%= link_to(h(playlist.title)+(playlist.present?(:year) ? " (#{playlist.year})" : ''), user_playlist_path(playlist.user.login, playlist), :class => 'small_playlist_title',:title => "#{h(playlist.title)} by #{h(playlist.user.name)}" ) %>
+ <%= link_to(h(playlist.title)+(playlist.year.present?) ? " (#{playlist.year})" : ''), user_playlist_path(playlist.user.login, playlist), :class => 'small_playlist_title',:title => "#{h(playlist.title)} by #{h(playlist.user.name)}" ) %>
<% end %>
@@ -1,4 +1,4 @@
-<% if present?(@follows) %>
+<% if @follows.present? %>
<% cache(cache_digest(@follows)) do %>
<h2 class="box">Follows</h2>
<div id="follows" class="box static_content clearfix">
@@ -10,9 +10,9 @@
<strong><%= link_to h(track_play.asset.name), user_track_path(track_play.asset.user, track_play.asset) %></strong><br/>
<%= time_ago_in_words(track_play.created_at) %> ago
by <%= track_play.listener ? (link_to (h track_play.listener.name), user_home_path(track_play.listener)) :
- "Guest #{present?(track_play.ip) ? '('+track_play.ip+')': ''}" %>
+ "Guest #{track_play.ip.present?) ? '('+track_play.ip+')': ''}" %>
<br/>via <%= link_source(track_play.source) %>
</div>
- <%= present?(track_play.ip) ? image_tag('http://api.hostip.info/flag.php?ip='+track_play.ip, :size => '80x40', :style => 'float:right; clear:none;opacity:0.4;') : ''%>
+ <%= (track_play.ip.present?) ? image_tag('http://api.hostip.info/flag.php?ip='+track_play.ip, :size => '80x40', :style => 'float:right; clear:none;opacity:0.4;') : ''%>
<% end %>
<div class="clear"> </div>
@@ -23,8 +23,8 @@
<%= user_nav_item "Profile", profile_path(@user), :title => "#{h @user.name}'s profile on alonetone" if @user.bio %>
<%= user_nav_item "Email", "mailto:#{@user.email}",:added_class => "contact" if admin? %>
- <%= user_nav_item "iTunes", "http://#{@user.itunes}",:added_class => "contact" if @user.present?(:itunes) %>
- <%= user_nav_item "Twitter", "http://twitter.com/#{@user.twitter}", :added_class => 'contact' if @user.present?(:twitter) %>
+ <%= user_nav_item "iTunes", "http://#{@user.itunes}",:added_class => "contact" if @user.itunes.present? %>
+ <%= user_nav_item "Twitter", "http://twitter.com/#{@user.twitter}", :added_class => 'contact' if @user.twitter.present? %>
<%= user_nav_item "Sudo", sudo_user_path(@user),:added_class => "contact" if (admin? || @sudo)%>
</ul>
</div>
@@ -7,7 +7,7 @@
<div class="bio static_content">
<p>
- <% if @user.present?(:bio) %>
+ <% if @user.bio.present?) %>
<%= @user.printable_bio %>
<% else %>
<%=h @user.name %> doesn't have anything to say, unfortunately...
@@ -16,28 +16,28 @@
</p>
</div>
- <% if @user.present?(:website) %>
+ <% if @user.website.present? %>
<div class="bio static_content">
<%= website_for(@user) %>
</div>
<% end %>
- <% if @user.present?(:myspace) %>
+ <% if @user.myspace.present? %>
<div class="bio static_content">
<%= myspace_for(@user) %>
</div>
<% end %>
<div class="bio static_content">
- <% if @user.has_tracks? && authorized? && @user.present?(:itunes) %>
+ <% if @user.has_tracks? && authorized? && @user.itunes.present? %>
Podcast feed: <%= user_feeds_url(@user, :rss) %><br/>
<%= itunes_link_for(@user) %>
<% elsif @user.has_tracks? && authorized? %>
Your Podcast feed: <%= user_feeds_url(@user, :rss) %><br/>
<%= link_to 'Submit this feed to iTunes', 'https://phobos.apple.com/WebObjects/MZFinance.woa/wa/publishPodcast'%>
to get your music indexed and listed in iTunes under Podcasts > Music. Then come back to update your profile when you have your iTunes feed URL.
- <% elsif @user.present?(:itunes) %>
+ <% elsif @user.itunes.present? %>
<%= itunes_link_for(@user) %>
<% end %>
</div>
@@ -25,9 +25,9 @@
<% content_for :left do %>
<%= render :partial => 'latest' if @user.assets_count > 0 %>
- <%= render :partial => 'favorites' if present?(@favorites) %>
+ <%= render :partial => 'favorites' if @favorites.present? %>
- <%= render :partial => 'follows' if present?(@mostly_listens_to) or present?(@follows) %>
+ <%= render :partial => 'follows' if @mostly_listens_to.present? or @follows.present? %>
<%= render :partial => 'listens' if @listens.size > 0 %>
@@ -37,7 +37,7 @@
<% end %>
<% content_for :right do %>
- <%= render :partial => 'popular' if present?(@popular_tracks) && (setting('most_popular', @user) == 'true')%>
+ <%= render :partial => 'popular' if @popular_tracks.present? && (setting('most_popular', @user) == 'true')%>
<% #cache(cache_digest(@comments)) do # doesn't work if new private comments show, also date/times are off %>
<%= render :partial => 'shared/comments' if @comments.size > 0 %>
@@ -1,7 +1,7 @@
xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
xml.rss "xmlns:itunes"=> "http://www.itunes.com/dtds/podcast-1.0.dtd", "version"=>"2.0" do
xml.channel do
- xml.itunes :block, 'yes' if @user.settings && @user.settings.present?('block_itunes') && @user.settings['block_itunes'] == 'true'
+ xml.itunes :block, 'yes' if @user.settings && @user.settings['block_itunes'].present? && @user.settings['block_itunes'] == 'true'
xml.title "#{@user.name} on alonetone.com"
xml.link user_home_url(@user)
@@ -30,6 +30,6 @@ xml.rss "xmlns:itunes"=> "http://www.itunes.com/dtds/podcast-1.0.dtd", "version"
xml.itunes :category,:text=>'Music'
- xml.<< render(:partial => 'shared/asset', :collection => @assets) if present?(@assets)
+ xml.<< render(:partial => 'shared/asset', :collection => @assets) if @assets.present?
end
end
View
@@ -1,53 +1,5 @@
# Goodies to make development more enjoyable
-
-class Object
-
- # The classic shortcut from http://ozmm.org/
- #
- # @person ? @person.name : nil
- # vs
- # @person.try(:name)
- #
- def try(method)
- send method if respond_to? method
- end
-
- # With conditional and possibly empty love from Sudara
- #
- # if params.present? :search
- # vs
- # if params[:search] && !params[:search].empty?
- #
- #
- # if params.present? :search, :filter
- # vs
- # if (params[:search] && !params[:search].empty?) && (params[:filter] && !params[:filter].empty?)
- #
- #
- # <% if @person.present? :name %>
- # vs
- # <% if @person.name && !@person.name.empty? %>
- #
- #
- # Bonus points for:
- # present? @query, @results
- #
- def present?(*methods_variables_or_attributes)
- methods_variables_or_attributes.detect do |monkey|
- if (monkey.is_a? Symbol)
- result = try(monkey)
- result && !result.empty?
- elsif self.is_a? Hash # hashes with string keys
- result = self[monkey]
- result && !result.empty?
- else # allow plain jane variables to be tested
- monkey && !monkey.empty?
- end
- end
- end
-end
-
class Array
# If +number+ is greater than the size of the array, the method
# will simply return the array itself sorted randomly

0 comments on commit 7ddfc5d

Please sign in to comment.