jeffrafter-gemstalker 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 1
4
+ :patch: 0
data/lib/gemstalker.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'net/http'
2
+
3
+ class GemStalker
4
+ attr_accessor :username, :name, :repository, :version
5
+
6
+ def initialize(options = {})
7
+ @username = options[:username]
8
+ @repository = options[:repository]
9
+ @version = options[:version] || determine_version
10
+
11
+ end
12
+
13
+ def built?
14
+ Net::HTTP.start('gems.github.com') {|http|
15
+ response = http.head(gem_path)
16
+ response.code == "200"
17
+ }
18
+ end
19
+
20
+ def in_specfile?
21
+ fetcher = Gem::SpecFetcher.new
22
+ specs = fetcher.load_specs(URI.parse('http://gems.github.com/'), 'specs')
23
+ specs.any? do |(name, spec)|
24
+ name == gem_name && spec.version.to_s == @version
25
+ end
26
+ end
27
+
28
+ protected
29
+
30
+ def gem_path
31
+ "/gems/#{gem_name}-#{@version}.gem"
32
+ end
33
+
34
+ def gem_name
35
+ "#{@username}-#{@repository}"
36
+ end
37
+
38
+ def gemspec_path
39
+ # TODO this seems very unfuture proof, and also specific to master branch...
40
+ "/#{@username}/#{@repository}/blob/master/#{@repository}.gemspec?raw=true"
41
+ end
42
+
43
+ def determine_version
44
+ res = nil
45
+ Net::HTTP.start('github.com') {|http|
46
+ res = http.get(gemspec_path)
47
+ }
48
+
49
+ if res.code == "200"
50
+ gemspec_file = res.body
51
+ gemspec = nil
52
+ # TODO this assumes Ruby format, but GitHub is cool with YAML
53
+ Thread.new { gemspec = eval("$SAFE = 3\n#{gemspec_file}") }.join
54
+ gemspec.version.to_s
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class GemstalkerTest < Test::Unit::TestCase
4
+
5
+ context "a stalker for a specific version of a gem that has not been built" do
6
+ setup do
7
+ @stalker = GemStalker.new(:username => 'technicalpickles', :repository => 'jeweler', :version => '0.9.3')
8
+ end
9
+
10
+ should "not be built yet" do
11
+ assert ! @stalker.built?
12
+ end
13
+
14
+ should "not be in specfile yet" do
15
+ assert ! @stalker.in_specfile?
16
+ end
17
+ end
18
+
19
+ context "a stalker for a specific version of a gem that has been built and is available" do
20
+ setup do
21
+ @stalker = GemStalker.new(:username => 'technicalpickles', :repository => 'jeweler', :version => '0.8.1')
22
+ end
23
+
24
+ should "be built" do
25
+ assert @stalker.built?
26
+ end
27
+
28
+ should "be in specfile" do
29
+ assert @stalker.in_specfile?
30
+ end
31
+ end
32
+
33
+ context "a stalker without a specific version of a gem that has been built" do
34
+ setup do
35
+ @stalker = GemStalker.new(:username => 'technicalpickles', :repository => 'jeweler')
36
+ end
37
+
38
+ should "determine version" do
39
+ assert_equal '0.8.1', @stalker.version
40
+ end
41
+
42
+ should "be built" do
43
+ assert @stalker.built?
44
+ end
45
+
46
+ should "be in specfile" do
47
+ assert @stalker.in_specfile?
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'ruby-debug'
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'gemstalker')
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jeffrafter-gemstalker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Josh Nichols
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-09 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A library for determining if GitHub has built a gem yet
17
+ email: josh@technicalpickles.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - VERSION.yml
26
+ - lib/gemstalker.rb
27
+ - test/gemstalker_test.rb
28
+ - test/test_helper.rb
29
+ has_rdoc: false
30
+ homepage: http://github.com/technicalpickles/gemstalker
31
+ post_install_message:
32
+ rdoc_options: []
33
+
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: "0"
41
+ version:
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ requirements: []
49
+
50
+ rubyforge_project:
51
+ rubygems_version: 1.2.0
52
+ signing_key:
53
+ specification_version: 2
54
+ summary: GemStalker is a small library to determine if GitHub has built a gem yet.
55
+ test_files: []
56
+