Class: GemStalker

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_stalker.rb

Overview

Small class for determining if a gem has been built on GitHub and if it’s installable.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GemStalker

Accepts the following options:

username

GitHub username

repository

repository name

version

version to stalk. Defaults to checking the repository for a

gemspec to determine the latest version.


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gem_stalker.rb', line 15

def initialize(options = {})
  @username   = options[:username]
  @repository = options[:repository]
  unless @username && @repository
    @username, @repository = determine_username_and_repository
  end

  @version    = options[:version] || determine_version


end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/gem_stalker.rb', line 7

def name
  @name
end

#repositoryObject

Returns the value of attribute repository.



7
8
9
# File 'lib/gem_stalker.rb', line 7

def repository
  @repository
end

#usernameObject

Returns the value of attribute username.



7
8
9
# File 'lib/gem_stalker.rb', line 7

def username
  @username
end

#versionObject

Returns the value of attribute version.



7
8
9
# File 'lib/gem_stalker.rb', line 7

def version
  @version
end

Instance Method Details

#built?Boolean

Is it built yet?

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/gem_stalker.rb', line 28

def built?
  Net::HTTP.start('gems.github.com') {|http|
    response = http.head(gem_path)
    response.code == "200"
  }
end

#edit_repo_urlObject

Path to edit the repository



61
62
63
# File 'lib/gem_stalker.rb', line 61

def edit_repo_url
  "http://github.com/#{@username}/#{@repository}/edit"
end

#gem?Boolean

Is RubyGem building enabled for the repository?

Returns:

  • (Boolean)


36
37
38
39
40
41
42
# File 'lib/gem_stalker.rb', line 36

def gem?
  Net::HTTP.start('github.com') {|http|
    res = http.get(master_path)
    return res.body =~ /alt\=.Rubygem./ if res.code == "200"
  }
  false
end

#gem_pathObject



65
66
67
# File 'lib/gem_stalker.rb', line 65

def gem_path
  "/gems/#{gem_name}-#{@version}.gem"
end

#in_specfile?Boolean

Is it in the specs yet? ie is it installable yet?

Returns:

  • (Boolean)


45
46
47
48
49
50
51
# File 'lib/gem_stalker.rb', line 45

def in_specfile?
  fetcher = Gem::SpecFetcher.new
  specs = fetcher.load_specs(URI.parse('http://gems.github.com/'), 'specs')
  specs.any? do |(name, spec)|
    name == gem_name && spec.version.to_s == @version
  end
end

#installObject



53
54
55
56
57
58
# File 'lib/gem_stalker.rb', line 53

def install
  sudo = RUBY_PLATFORM =~ /mswin32/ ? '' : 'sudo'
  wget = "wget http://gems.github.com/#{gem_path}"
  install = "#{sudo} gem install #{gem_name}-#{@version}.gem"
  system "#{wget}; #{install}"
end