Class: IsItJRuby
- Inherits:
-
Object
- Object
- IsItJRuby
- Defined in:
- lib/isitjruby.rb
Overview
Utilities for determining if a Gem::Specification is JRuby ready. Based on isitjruby.com
Constant Summary collapse
- VERSION =
This version of rubygems-isitjruby
'1.0'
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
Comments for this gem.
-
#spec ⇒ Object
readonly
The gemspec.
Instance Method Summary collapse
-
#initialize(spec) ⇒ IsItJRuby
constructor
Downloads comments for
spec
from isitjruby.com. -
#jruby? ⇒ Boolean
Strict check for this version.
-
#maybe_jruby? ⇒ Boolean
Returns a comment from the latest version that worked with JRuby.
-
#percent(version = @spec.version) ⇒ Object
Returns a percentage of people saying
version
worked for them. -
#url ⇒ Object
URL of this gem on isitjruby.com.
Constructor Details
#initialize(spec) ⇒ IsItJRuby
Downloads comments for spec
from isitjruby.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/isitjruby.rb', line 29 def initialize(spec) @spec = spec url = URI.parse "http://isitjruby.com/#{@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 isitjruby.com next end end comments.compact! @comments = comments.sort_by do |comment| works = comment['works_for_me'] ? 1 : 0 [comment['version'], works, comment['name']] end.reverse end |
Instance Attribute Details
#comments ⇒ Object (readonly)
Comments for this gem
19 20 21 |
# File 'lib/isitjruby.rb', line 19 def comments @comments end |
#spec ⇒ Object (readonly)
The gemspec
24 25 26 |
# File 'lib/isitjruby.rb', line 24 def spec @spec end |
Instance Method Details
#jruby? ⇒ Boolean
Strict check for this version
58 59 60 61 62 |
# File 'lib/isitjruby.rb', line 58 def jruby? @comments.any? do |comment| comment['version'] == @spec.version and comment['works_for_me'] end end |
#maybe_jruby? ⇒ Boolean
Returns a comment from the latest version that worked with JRuby
67 68 69 70 71 |
# File 'lib/isitjruby.rb', line 67 def maybe_jruby? @comments.first do |comment| comment['works_for_me'] 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/isitjruby.rb', line 76 def percent(version = @spec.version) matching = @comments.select do |comment| comment['version'] == version end works = matching.select do |comment| comment['works_for_me'] end.length percent = (matching.length.to_f / works * 100) percent = 0 if percent.nan? percent = 100 if percent > 100 "%2.0f%%" % percent end |
#url ⇒ Object
URL of this gem on isitjruby.com
93 94 95 |
# File 'lib/isitjruby.rb', line 93 def url "http://isitjruby.com/#{spec.name}" end |