Class: GemStats::GemInfo
- Inherits:
-
Object
- Object
- GemStats::GemInfo
- Defined in:
- lib/gem_stats/gem_info.rb
Constant Summary collapse
- API_URL =
"https://rubygems.org/api/v1/gems/"
- REQUEST_FORMAT =
'json'
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #clients(env = 'runtime') ⇒ Object
- #dependencies(env = 'runtime') ⇒ Object
- #info ⇒ Object
-
#initialize(name) ⇒ GemInfo
constructor
A new instance of GemInfo.
- #save ⇒ Object
Constructor Details
#initialize(name) ⇒ GemInfo
Returns a new instance of GemInfo.
11 12 13 |
# File 'lib/gem_stats/gem_info.rb', line 11 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/gem_stats/gem_info.rb', line 9 def name @name end |
Instance Method Details
#clients(env = 'runtime') ⇒ Object
29 30 31 |
# File 'lib/gem_stats/gem_info.rb', line 29 def clients(env = 'runtime') Gem.where("dependencies.#{env}.name" => @name).all end |
#dependencies(env = 'runtime') ⇒ Object
24 25 26 27 |
# File 'lib/gem_stats/gem_info.rb', line 24 def dependencies(env = 'runtime') @dependencies ||= {} @dependencies[env.to_s] ||= info['dependencies'][env.to_s].inject([]) { |list, gem| list << gem['name'] } end |
#info ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/gem_stats/gem_info.rb', line 15 def info return @info if defined?(@info) begin @info ||= JSON.load open("#{API_URL}#{@name}.#{REQUEST_FORMAT}").read rescue OpenURI::HTTPError => e @info = nil end end |