Permalink
Browse files

Display gist owner and star state in search results

  • Loading branch information...
1 parent 743a1e2 commit 4f304e683de56fe972c5ea41767aa178ff5feaac @rwdaigle committed Nov 21, 2012
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -3,7 +3,7 @@ class Gist < ActiveRecord::Base
include Tire::Model::Search
attr_accessible :gh_id, :user_id, :owner_gh_id, :owner_gh_username, :owner_gh_avatar_url, :description, :url, :git_pull_url, :git_push_url, :public,
- :comment_count, :gh_created_at, :gh_updated_at, :starred
+ :comment_count, :gh_created_at, :gh_updated_at, :starred, :owned
belongs_to :user
has_many :files, :class_name => 'GistFile', :dependent => :delete_all
@@ -31,12 +31,13 @@ class << self
def import(user_id, gh_gist, overrides = {})
user = User.find(user_id)
+ owned = (user.gh_id == gh_gist.user['id'])
gh_id = gh_gist['id']
attributes = {
gh_id: gh_id, user_id: user.id, owner_gh_id: gh_gist.user['id'], owner_gh_username: gh_gist.user.login, owner_gh_avatar_url: gh_gist.user.avatar_url,
description: gh_gist.description, url: gh_gist.html_url, git_push_url: gh_gist.git_push_url,
- git_pull_url: gh_gist.git_pull_url, public: gh_gist.public, comment_count: gh_gist.comments,
+ git_pull_url: gh_gist.git_pull_url, public: gh_gist.public, comment_count: gh_gist.comments, owned: owned,
gh_created_at: gh_gist.created_at, gh_updated_at: gh_gist.updated_at
}.merge(overrides)
@@ -7,7 +7,8 @@
%span.meta
- if result.starred?
= image_tag("star.png")
- %img(src="#{result.owner_gh_avatar_url}&s=13" title="#{result.owner_gh_username}" alt="#{result.owner_gh_username}")
+ - if !result.owned?
+ %img(src="#{result.owner_gh_avatar_url}&s=13" title="#{result.owner_gh_username}" alt="#{result.owner_gh_username}")
.hints
%em keyboard:
↑ = up, ↓ = down, enter = follow link, / = search
@@ -3,7 +3,7 @@ class AddStarredGistSupport < ActiveRecord::Migration
def up
change_table :gists do |t|
t.string :owner_gh_id, :owner_gh_username, :owner_gh_avatar_url
- t.boolean :starred
+ t.boolean :starred, :owned
end
end
@@ -12,5 +12,6 @@ def down
remove_column :gists, :owner_gh_username
remove_column :gists, :owner_gh_avatar_url
remove_column :gists, :starred
+ remove_column :gists, :owned
end
end
View
@@ -45,6 +45,7 @@
t.string "owner_gh_username"
t.string "owner_gh_avatar_url"
t.boolean "starred"
+ t.boolean "owned"
end
add_index "gists", ["gh_id"], :name => "index_gists_on_gh_id"

0 comments on commit 4f304e6

Please sign in to comment.