Module: Joya
- Defined in:
- lib/joya.rb,
lib/joya/gem.rb,
lib/joya/version.rb
Overview
:nodoc:
Defined Under Namespace
Constant Summary collapse
- GEM_NAME_XPATH =
xpath pattern to scrap gem names of a rubygems user
"//a[@class='gems__gem__name']//text()[not(parent::span)]"- GEM_VERSION_PATTERN =
'-[0-9]*\.[0-9]*\.[0-9]*'- VERSION =
"0.1.12"
Class Attribute Summary collapse
-
.author ⇒ Object
gems author.
-
.gems ⇒ Object
author’s gems.
Class Method Summary collapse
-
.base_dir ⇒ Object
(also: directory)
directory where gems will be unpacked.
-
.fetch_gem_names ⇒ Object
fetch gem names from a given rubygems author.
-
.help ⇒ Object
:nodoc:.
-
.main(args) ⇒ Object
:nodoc:.
-
.make_dir ⇒ Object
makes
base_dir. -
.open_rubygems ⇒ Object
open the rubygems url.
-
.print_and_quit ⇒ Object
print user gems and exit.
-
.unpack_all ⇒ Object
install missing gems and unpack them in
base_dir. -
.url ⇒ Object
:nodoc:.
-
.version ⇒ Object
:nodoc:.
Class Attribute Details
.author ⇒ Object
gems author
38 39 40 |
# File 'lib/joya.rb', line 38 def @author end |
.gems ⇒ Object
author’s gems
41 42 43 |
# File 'lib/joya.rb', line 41 def gems @gems end |
Class Method Details
.base_dir ⇒ Object Also known as: directory
directory where gems will be unpacked
119 120 121 |
# File 'lib/joya.rb', line 119 def base_dir "gems-#{}" end |
.fetch_gem_names ⇒ Object
fetch gem names from a given rubygems author
105 106 107 108 |
# File 'lib/joya.rb', line 105 def fetch_gem_names site=Nokogiri::HTML(open_rubygems) @gems=site.xpath(GEM_NAME_XPATH).text.gsub(/\s+/," ").split end |
.help ⇒ Object
:nodoc:
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/joya.rb', line 87 def help # :nodoc: puts <<~str Usage: joya <author> [options] Options: -h, --help print this help message -p, --print print user gems without downloading -v, --version print joya version str exit end |
.main(args) ⇒ Object
:nodoc:
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/joya.rb', line 43 def main(args) # :nodoc: help if(args.include?("-h") or args.include?("--help") or args.empty?) version if (args.include?("-v") or args.include?("--version")) # take the first argument starting with '\w' as the author @author = args.find{|arg| arg.match(/^\w/)} help if .nil? fetch_gem_names print_and_quit if (args.include?("-p") or args.include?("--print")) make_dir unpack_all end |
.make_dir ⇒ Object
makes base_dir
125 126 127 128 |
# File 'lib/joya.rb', line 125 def make_dir FileUtils.mkdir base_dir rescue Errno::EEXIST end |
.open_rubygems ⇒ Object
open the rubygems url
111 112 113 114 115 116 |
# File 'lib/joya.rb', line 111 def open_rubygems URI.open(url) rescue OpenURI::HTTPError puts "HTTPError: Could not find rubygems of #{}" exit end |
.print_and_quit ⇒ Object
print user gems and exit
58 59 60 61 62 |
# File 'lib/joya.rb', line 58 def print_and_quit puts "Gems of #{}:" puts gems exit end |
.unpack_all ⇒ Object
install missing gems and unpack them in base_dir
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/joya.rb', line 65 def unpack_all Dir.chdir base_dir total=gems.size digits=total.to_s.size puts "#{total} gems found" puts "Downloading into #{base_dir}/" interrupted = false gems.each_with_index do |jem,i| printf("[%#{digits}d/%#{digits}d] Unpacking %s\n", i+1, total, jem) Joya::Gem.install(jem) unless jem.gem_installed? Joya::Gem.unpack(jem) end rescue LocalJumpError ensure Dir.chdir '..' end |
.url ⇒ Object
:nodoc:
100 101 102 |
# File 'lib/joya.rb', line 100 def url # :nodoc: "https://rubygems.org/profiles/#{}" end |