Module: Joya

Defined in:
lib/joya.rb,
lib/joya/gem.rb,
lib/joya/version.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Error, Gem

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

Class Method Summary collapse

Class Attribute Details

.authorObject

gems author



38
39
40
# File 'lib/joya.rb', line 38

def author
  @author
end

.gemsObject

author’s gems



41
42
43
# File 'lib/joya.rb', line 41

def gems
  @gems
end

Class Method Details

.base_dirObject Also known as: directory

directory where gems will be unpacked



119
120
121
# File 'lib/joya.rb', line 119

def base_dir
  "gems-#{author}"
end

.fetch_gem_namesObject

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

.helpObject

: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 author.nil?

  fetch_gem_names
  print_and_quit if (args.include?("-p") or args.include?("--print"))
  make_dir
  unpack_all
end

.make_dirObject

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_rubygemsObject

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 #{author}"
  exit
end

print user gems and exit



58
59
60
61
62
# File 'lib/joya.rb', line 58

def print_and_quit
  puts "Gems of #{author}:"
  puts gems
  exit
end

.unpack_allObject

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

.urlObject

:nodoc:



100
101
102
# File 'lib/joya.rb', line 100

def url # :nodoc:
  "https://rubygems.org/profiles/#{author}"
end

.versionObject

:nodoc:



82
83
84
85
# File 'lib/joya.rb', line 82

def version # :nodoc:
  puts "joya #{Joya::VERSION}"
  exit
end