Class: GemStalker
- Inherits:
-
Object
- Object
- GemStalker
- 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
-
#name ⇒ Object
Returns the value of attribute name.
-
#repository ⇒ Object
Returns the value of attribute repository.
-
#username ⇒ Object
Returns the value of attribute username.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#built? ⇒ Boolean
Is it built yet?.
-
#edit_repo_url ⇒ Object
Path to edit the repository.
-
#gem? ⇒ Boolean
Is RubyGem building enabled for the repository?.
- #gem_path ⇒ Object
-
#in_specfile? ⇒ Boolean
Is it in the specs yet? ie is it installable yet?.
-
#initialize(options = {}) ⇒ GemStalker
constructor
Accepts the following options:.
- #install ⇒ Object
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( = {}) @username = [:username] @repository = [:repository] unless @username && @repository @username, @repository = determine_username_and_repository end @version = [:version] || determine_version end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/gem_stalker.rb', line 7 def name @name end |
#repository ⇒ Object
Returns the value of attribute repository.
7 8 9 |
# File 'lib/gem_stalker.rb', line 7 def repository @repository end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/gem_stalker.rb', line 7 def username @username end |
#version ⇒ Object
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?
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_url ⇒ Object
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?
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_path ⇒ Object
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?
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 |
#install ⇒ Object
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 |