joya 0.1.0 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2265ed2b2e87706a7a910cef208edfd549b20849b5c09a3ebf26b1c6caa1caf2
4
- data.tar.gz: 9191f4e361df10680d4e47a35784af4c8c21c54e946131ec7f3abf0040aa7362
3
+ metadata.gz: 28ff93e326df0d6398e7167a1f31c19db5f8b963e9959fad330aa99e833ed0d4
4
+ data.tar.gz: 5fa0f4233df5efb76aa6802af6ad7f5a0dc790b261f60da233eef46c69a22b9a
5
5
  SHA512:
6
- metadata.gz: d88c91b17cb7f5fff0130e598e311802e909651a330680f28f12be569e10a4e87c33de20930d85add3b3c7ff335e46a6b3e88c20e891ee0bd1f0c739299ed282
7
- data.tar.gz: 566a79d062db2e6d2d0ef9bc85daa7e3a7b130d46e550d030197f111b55741bb4d934abadbb5759097d26e64cf01a4ebe245fe6014adafbb894ff723737240de
6
+ metadata.gz: 9ca5aa73a627d5f2af4023c856dd04369158b5eeb68d961ceafed838a74469b113ca9f75f61eca93e7b483ad98cfdc9adb4fd526f0b03fa1bc72817f85ea77a9
7
+ data.tar.gz: 7d36f3d3e964440f36dfc55c16a49827247fff37c828f6a68849e06463a1e7dcf1f4025db8c9b1e2a1887af12024021417000ba354c7f70fc3093b4d9d7dfebf
data/.gitignore CHANGED
@@ -5,6 +5,11 @@
5
5
  /doc/
6
6
  /pkg/
7
7
  /spec/reports/
8
+ /vendor/
8
9
  /tmp/
9
10
  TODO.md
10
11
  gems-*
12
+ .rake*
13
+ .byebug
14
+ *.swp
15
+ NOTES
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- joya (0.1.0)
4
+ joya (0.1.11)
5
5
  nokogiri (~> 1.10.4)
6
6
 
7
7
  GEM
@@ -17,7 +17,7 @@ GEM
17
17
  builder
18
18
  minitest (>= 5.0)
19
19
  ruby-progressbar
20
- nokogiri (1.10.4)
20
+ nokogiri (1.10.8)
21
21
  mini_portile2 (~> 2.4.0)
22
22
  rake (10.5.0)
23
23
  ruby-progressbar (1.10.1)
@@ -34,4 +34,4 @@ DEPENDENCIES
34
34
  rake (~> 10.0)
35
35
 
36
36
  BUNDLED WITH
37
- 2.0.2
37
+ 2.1.4
data/README.md CHANGED
@@ -1,41 +1,12 @@
1
1
  Joya
2
2
  ====
3
3
 
4
- [joya](https://en.wiktionary.org/wiki/joya#Spanish) clones gems of a
5
- given RubyGems.org author.
6
-
7
- ## Installation
8
-
9
- ```bash
10
- $ gem install joya
11
- ```
12
-
13
- ## Usage
14
-
15
- Pass the name of a <https://rubygems.org> account:
16
-
17
- ```bash
18
- $ joya sergioro
19
- 4 gems found
20
- [0/4] Unpacking hola-sergio
21
- [1/4] Unpacking trick_or_treat
22
- [2/4] Unpacking repo-sergio
23
- [3/4] Unpacking clup
24
- Done: gems available at gems-sergioro
25
- ```
26
-
27
- Recommended steps to maximize profit:
28
-
29
- 1. Find an awesome Ruby programmer to learn from
30
- 2. Use `joya programmer_name`
31
- 3. Read the source code of the programmer and learn new techniques
32
- 4. Become an awesome Ruby programmer
33
-
34
- ## Contributing
35
-
36
- Bug reports and pull requests are welcome on [GitHub.](https://github.com/sergioro9/joya)
37
-
38
- ## License
39
-
40
- The gem is available as open source under the terms of the [MIT
41
- License](https://opensource.org/licenses/MIT).
4
+ [Joya](https://en.wiktionary.org/wiki/joya#Spanish) clones gems from a [rubygems](https://rubygems.org) users.
5
+
6
+ [ ] remove nokogiri dependency. use only stdlib
7
+ [ ] optimize Joya#unpack_all by multiple processes to download gems in parallel
8
+ [ ] add an option that prints available gems and let you choose which to download
9
+ - you can print all the gems of an author and then let the user use the mouse to choose which gems not to download.
10
+ - you could use whiptail(1) to display the menu of gems
11
+ - you could see the source code of fzf and nerdtree ruby gems, which let you use the mouse to click on files. do something similar for joya
12
+ - conclusion: learn how to detect mouse clicks and mouse location inside a terminal
data/exe/joya CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
+
3
5
  require "joya"
4
6
 
5
- Joya.main
7
+ Joya.main(ARGV)
data/lib/joya.rb CHANGED
@@ -1,97 +1,130 @@
1
+ $LOAD_PATH.unshift(__dir__)
2
+
1
3
  require "joya/version"
4
+ require "joya/gem"
2
5
  require 'open-uri'
3
6
  require 'nokogiri'
4
7
 
5
- class Array
6
- def even_values
7
- self.values_at(* self.each_index.select {|i| i.even?})
8
+
9
+ %w[INT TERM].each do |signal|
10
+ trap(signal) do
11
+ puts "\b"*3+"Download interrupted"
12
+ break
8
13
  end
9
14
  end
10
15
 
11
- class String
16
+ class String # :nodoc:
17
+ # check if a gem is installed
12
18
  def gem_installed?
13
- gem_name=self.dup
14
- path=ENV['GEM_PATH'].split(":")[0]
15
- version='-[0-9]*\.[0-9]*\.[0-9]*'
16
- !Dir.glob([path, 'gems', gem_name << version].join('/')).empty?
19
+ gem_path=ENV['GEM_PATH'].split(":").first
20
+ !Dir.glob([gem_path, 'gems', self + Joya::GEM_VERSION_PATTERN].join('/')).empty?
21
+ rescue NoMethodError
17
22
  end
18
23
  end
19
24
 
20
- class Joya
21
- class Error < StandardError; end
22
-
23
- CSS='.gems__gem__name'
24
- def self.main
25
- parse_args
26
- fetch_gems
27
- %x(mkdir -p #{directory})
28
- Dir.chdir directory
29
- total=Joya.gems.size
30
- digits=total.to_s.size
31
- puts "#{total} gems found"
32
- Joya.gems.each_with_index do |g,i|
33
- printf("[%#{digits}d/%#{digits}d] Unpacking %s\n", i, total, g)
34
- gem_install(g) unless g.gem_installed?
35
- gem_unpack(g)
25
+ # the Joya module
26
+ module Joya
27
+ class Error < StandardError; end # :nodoc:
28
+
29
+ # xpath pattern to scrap gem names of a rubygems user
30
+ GEM_NAME_XPATH="//a[@class='gems__gem__name']//text()[not(parent::span)]"
31
+ GEM_VERSION_PATTERN='-[0-9]*\.[0-9]*\.[0-9]*'
32
+
33
+ @gems=[]
34
+ @author=''
35
+
36
+ class << self
37
+ # gems author
38
+ attr_accessor :author
39
+
40
+ # author's gems
41
+ attr_accessor :gems
42
+
43
+ def main(args) # :nodoc:
44
+ help if(args.include?("-h") or args.include?("--help") or args.empty?)
45
+ version if (args.include?("-v") or args.include?("--version"))
46
+
47
+ # take the first argument starting with '\w' as the author
48
+ @author = args.find{|arg| arg.match(/^\w/)}
49
+ help if author.nil?
50
+
51
+ fetch_gem_names
52
+ print_and_quit if (args.include?("-p") or args.include?("--print"))
53
+ make_dir
54
+ unpack_all
36
55
  end
37
- Dir.chdir '..'
38
- puts "Done: gems available at #{directory}"
39
- rescue
40
- puts "There was a problem, maybe try with a different argument?"
41
- end
42
56
 
43
- def self.parse_args
44
- Joya.author ||= ARGV.shift
45
- if author.nil?
46
- puts "Usage: joya <rubygems_author>"
57
+ # print user gems and exit
58
+ def print_and_quit
59
+ puts "Gems of #{author}:"
60
+ puts gems
47
61
  exit
48
62
  end
49
- end
50
-
51
- def self.url
52
- "https://rubygems.org/profiles/#{Joya.author}"
53
- end
54
63
 
55
- def self.fetch_gems
56
- page=Nokogiri::HTML(open(url))
57
- Joya.gems=page.css(CSS).text.split(regex).even_values
58
- .map{|s| s.gsub(/[ \n]/,'')}
59
- .reject!{|s| s.empty?}
60
- rescue OpenURI::HTTPError
61
- puts "Could not find #{url}"
62
- end
63
-
64
- def self.regex
65
- Regexp.new(/(?<=\w)\n/)
66
- end
64
+ # install missing gems and unpack them in +base_dir+
65
+ def unpack_all
66
+ Dir.chdir base_dir
67
+ total=gems.size
68
+ digits=total.to_s.size
69
+ puts "#{total} gems found"
70
+ puts "Downloading into #{base_dir}/"
71
+ interrupted = false
72
+ gems.each_with_index do |jem,i|
73
+ printf("[%#{digits}d/%#{digits}d] Unpacking %s\n", i+1, total, jem)
74
+ Joya::Gem.install(jem) unless jem.gem_installed?
75
+ Joya::Gem.unpack(jem)
76
+ end
77
+ rescue LocalJumpError
78
+ ensure
79
+ Dir.chdir '..'
80
+ end
67
81
 
68
- def self.gem_install(gem)
69
- %x(gem install #{gem})
70
- end
82
+ def version # :nodoc:
83
+ puts "joya #{Joya::VERSION}"
84
+ exit
85
+ end
71
86
 
72
- def self.gem_unpack(gem)
73
- %x(gem unpack #{gem})
74
- end
87
+ def help # :nodoc:
88
+ puts <<~str
89
+ Usage:
90
+ joya <author> [options]
75
91
 
76
- def self.directory
77
- "gems-#{Joya.author}"
78
- end
92
+ Options:
93
+ -h, --help print this help message
94
+ -p, --print print user gems without downloading
95
+ -v, --version print joya version
96
+ str
97
+ exit
98
+ end
79
99
 
80
- private
100
+ def url # :nodoc:
101
+ "https://rubygems.org/profiles/#{author}"
102
+ end
81
103
 
82
- def self.author=(val)
83
- @author=val
84
- end
104
+ # fetch gem names from a given rubygems author
105
+ def fetch_gem_names
106
+ site=Nokogiri::HTML(open_rubygems)
107
+ @gems=site.xpath(GEM_NAME_XPATH).text.gsub(/\s+/," ").split
108
+ end
85
109
 
86
- def self.author
87
- @author
88
- end
110
+ # open the rubygems url
111
+ def open_rubygems
112
+ URI.open(url)
113
+ rescue OpenURI::HTTPError
114
+ puts "HTTPError: Could not find rubygems of #{author}"
115
+ exit
116
+ end
89
117
 
90
- def self.gems=(val)
91
- @gems=val
92
- end
118
+ # directory where gems will be unpacked
119
+ def base_dir
120
+ "gems-#{author}"
121
+ end
122
+ alias_method :directory, :base_dir
93
123
 
94
- def self.gems
95
- @gems
124
+ # makes +base_dir+
125
+ def make_dir
126
+ FileUtils.mkdir base_dir
127
+ rescue Errno::EEXIST
128
+ end
96
129
  end
97
130
  end
data/lib/joya/gem.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Joya
2
+ # container of +gem+ commands
3
+ class Gem
4
+ # install a gem
5
+ def self.install(jem)
6
+ system("gem install #{jem}", [:err, :out] => File::NULL)
7
+ end
8
+
9
+ # unpack a gem
10
+ def self.unpack(jem)
11
+ system("gem unpack #{jem}", [:err, :out] => File::NULL)
12
+ end
13
+ end
14
+ end
data/lib/joya/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- class Joya
2
- VERSION = "0.1.0"
1
+ module Joya # :nodoc:
2
+ VERSION = "0.1.12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: joya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Romero
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-29 00:00:00.000000000 Z
11
+ date: 2021-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,12 +114,13 @@ files:
114
114
  - exe/joya
115
115
  - joya.gemspec
116
116
  - lib/joya.rb
117
+ - lib/joya/gem.rb
117
118
  - lib/joya/version.rb
118
119
  homepage: https://github.com/sergioro9/joya
119
120
  licenses:
120
121
  - MIT
121
122
  metadata: {}
122
- post_install_message:
123
+ post_install_message:
123
124
  rdoc_options: []
124
125
  require_paths:
125
126
  - lib
@@ -134,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
135
  - !ruby/object:Gem::Version
135
136
  version: '0'
136
137
  requirements: []
137
- rubygems_version: 3.0.6
138
- signing_key:
138
+ rubygems_version: 3.2.11
139
+ signing_key:
139
140
  specification_version: 4
140
141
  summary: Clone gems from a specified author
141
142
  test_files: []