Class: IsItRubinius

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

Overview

Utilities for determining if a Gem::Specification is Rubinius ready. Based on http://isitrubinius.com

Constant Summary collapse

VERSION =

This version of rubygems-isitrubinius

'1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ IsItRubinius

Downloads comments for spec from http://isitrubinius.com



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/isitrubinius.rb', line 29

def initialize(spec)
  @spec = spec

  url = URI.parse "http://isitrubinius.com/api/v1/rubygems/#{@spec.name}/comments.json"

  json = Gem::RemoteFetcher.fetcher.fetch_path url
  comments = JSON.parse json

  comments.map! do |comment|
    begin
      comment['comment']['version'] =
        Gem::Version.new comment['comment']['version']
      comment['comment']
    rescue ArgumentError # bad data from isitrubinius.com
      next
    end
  end

  comments.compact!

  @comments = comments.sort_by do |comment|
    works = comment['working'] ? 1 : 0
    [comment['version'], works, comment['name']]
  end.reverse
end

Instance Attribute Details

#commentsObject (readonly)

Comments for this gem



19
20
21
# File 'lib/isitrubinius.rb', line 19

def comments
  @comments
end

#specObject (readonly)

The gemspec



24
25
26
# File 'lib/isitrubinius.rb', line 24

def spec
  @spec
end

Instance Method Details

#maybe_rubinius?Boolean

Returns a comment from the latest version that worked with Rubinius

Returns:

  • (Boolean)


67
68
69
70
71
# File 'lib/isitrubinius.rb', line 67

def maybe_rubinius?
  @comments.first do |comment|
    comment['working']
  end
end

#percent(version = @spec.version) ⇒ Object

Returns a percentage of people saying version worked for them



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/isitrubinius.rb', line 76

def percent(version = @spec.version)
  matching = @comments.select do |comment|
    comment['version'] == version
  end

  works = matching.select do |comment| comment['working'] end.length

  percent = (works / matching.length.to_f * 100)
  percent = 0   if percent.nan?
  percent = 100 if percent > 100

  "%2.0f%%" % percent
end

#rubinius?Boolean

Strict check for this version

Returns:

  • (Boolean)


58
59
60
61
62
# File 'lib/isitrubinius.rb', line 58

def rubinius?
  @comments.any? do |comment|
    comment['version'] == @spec.version and comment['working']
  end
end

#urlObject

URL of this gem on http://isitrubinius.com



93
94
95
# File 'lib/isitrubinius.rb', line 93

def url
  "http://isitrubinius.com/rubygems/#{spec.name}"
end