Class: Puppet::Module::Tool::Applications::Searcher
- Inherits:
-
Application
- Object
- Application
- Puppet::Module::Tool::Applications::Searcher
- Defined in:
- lib/puppet/module/tool/applications/searcher.rb
Instance Attribute Summary
Attributes inherited from Application
Instance Method Summary collapse
-
#initialize(term, options = {}) ⇒ Searcher
constructor
A new instance of Searcher.
- #run ⇒ Object
Methods inherited from Application
#discuss, #load_modulefile!, #metadata, #parse_filename!, #repository, run
Methods included from Utils::Interrogation
#confirms?, #header, #prompt, #say, #subheader
Constructor Details
#initialize(term, options = {}) ⇒ Searcher
Returns a new instance of Searcher.
7 8 9 10 |
# File 'lib/puppet/module/tool/applications/searcher.rb', line 7 def initialize(term, = {}) @term = term super() end |
Instance Method Details
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/puppet/module/tool/applications/searcher.rb', line 12 def run header "Searching #{repository}" request = Net::HTTP::Get.new("/modules.json?q=#{URI.escape(@term)}") response = repository.contact(request) case response when Net::HTTPOK matches = PSON.parse(response.body) if matches.empty? subheader "0 found." else subheader "#{matches.size} found." end matches.each do |match| puts "#{match['full_name']} (#{match['version']})" end else say "Could not execute search (HTTP #{response.code})" end end |