Skip to content

Commit 7890882

Browse files
committedApr 9, 2013
Thor action allowing for an alternate account from which to fetch repo's source files
1 parent e12fec5 commit 7890882

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed
 

‎lib/chardinjs-rails/source_file.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ class SourceFile < Thor
77

88
desc "fetch source files", "fetch source files from GitHub"
99
def fetch
10-
filtered_tags = fetch_tags
10+
account = ask("Which GitHub account's version do you want to fetch? (leave blank for default)")
11+
account = 'heelhook' if account.empty?
12+
filtered_tags = fetch_tags(account)
1113
tag = select("Which tag do you want to fetch?", filtered_tags)
1214
self.destination_root = "app/assets"
13-
remote = "https://github.com/heelhook/chardin.js"
15+
remote = "https://github.com/#{account}/chardin.js"
1416
get "#{remote}/raw/#{tag}/chardinjs.min.js", "javascripts/chardinjs.js"
1517
get "#{remote}/raw/#{tag}/chardinjs.css", "stylesheets/chardinjs.css"
1618

@@ -26,12 +28,12 @@ def fetch
2628

2729
private
2830

29-
def fetch_tags
31+
def fetch_tags(account)
3032
http = HTTPClient.new
31-
response = JSON.parse(http.get("https://api.github.com/repos/heelhook/chardin.js/tags").body)
33+
response = JSON.parse(http.get("https://api.github.com/repos/#{account}/chardin.js/tags").body)
3234
response.map{|tag| tag["name"]}.sort
3335
end
34-
36+
3537
def select msg, elements
3638
elements.each_with_index do |element, index|
3739
say(block_given? ? yield(element, index + 1) : ("#{index + 1}. #{element.to_s}"))

0 commit comments

Comments
 (0)
Please sign in to comment.