Skip to content

Commit

Permalink
rake github:data:update
Browse files Browse the repository at this point in the history
  • Loading branch information
szemek committed Nov 9, 2012
1 parent 2af8d85 commit 82b27e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion extras/github_data.rb
Expand Up @@ -27,7 +27,7 @@ def fetch!
end
end

def as_json(options = {})
def to_hash(options = {})
hash = {}

hash['gravatar'] = @gravatar
Expand All @@ -38,6 +38,10 @@ def as_json(options = {})
hash
end

def as_json(options = {})
self.to_hash
end

private
def repository_url
"https://api.github.com/repos/#{@username}/#{@repository}"
Expand Down
17 changes: 17 additions & 0 deletions lib/tasks/github.rake
@@ -0,0 +1,17 @@
namespace :github do
namespace :data do
desc "Update projects with Github data"
task :update => :environment do
Project.all.each do |project|
data = GithubData.new(project.username, project.repo)
data.fetch!
attributes = data.to_hash.reject{|k,v| v.nil?}

if attributes.present?
project.update_attributes(attributes)
puts "Project: #{project.id} has been updated."
end
end
end
end
end

0 comments on commit 82b27e6

Please sign in to comment.