Module: SneakPeek
- Defined in:
- lib/sneak_peek.rb,
lib/sneak_peek/version.rb
Defined Under Namespace
Modules: Utils
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
Class Method Details
.show_readme(gem_name:) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sneak_peek.rb', line 14 def self.show_readme(gem_name:) tmp_dir = Dir.mktmpdir begin FileUtils.chdir tmp_dir `gem fetch #{gem_name}` gem_file = Dir["*.gem"].first if !gem_file puts "Can't find a gem with the name `#{gem_name}`" exit 1 end `gem unpack #{gem_file}` gem_directory = Dir["*"].find do |file| File.directory?(file) end gem_files = Dir["#{gem_directory}/*"] readme_file = gem_files.find do |file| file.downcase.match /readme/ end if !readme_file puts "Can't find a readme." puts "This is the content of the gem:\n\t\n- #{gem_files.join("\n\t- ")}" exit 1 end puts File.read(readme_file) ensure FileUtils.remove_entry tmp_dir end end |