Class: PryGem::GemSearch
- Inherits:
-
Pry::ClassCommand
- Object
- Pry::ClassCommand
- PryGem::GemSearch
- Defined in:
- lib/pry-gem/gem_search.rb
Overview
Constant Summary collapse
- API_ENDPOINT =
'https://rubygems.org/api/v1/search.json'.freeze
Instance Method Summary collapse
Instance Method Details
#options(opt) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/pry-gem/gem_search.rb', line 21 def (opt) opt.on :l, :limit, 'Limit the number of results (max: 30)', default: 10, as: Integer, argument: true end |
#process(str) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/pry-gem/gem_search.rb', line 28 def process(str) uri = URI.parse(API_ENDPOINT) uri.query = URI.encode_www_form(query: str) gems = JSON.parse(Net::HTTP.get(uri)) _pry_.pager.page list_as_string(gems, opts[:limit]) end |
#setup ⇒ Object
16 17 18 19 |
# File 'lib/pry-gem/gem_search.rb', line 16 def setup require 'json' unless defined?(JSON) require 'net/http' unless defined?(Net::HTTP) end |