gem-search 0.1.6 → 0.1.7

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
  SHA1:
3
- metadata.gz: cf0634f75957207eecfa92cbc539e54fda22cbd3
4
- data.tar.gz: afa21e69df314d524de7da7f37a712dc4002b894
3
+ metadata.gz: 231d6017b8ed3cc3a800f89f12a197dc8484ed1f
4
+ data.tar.gz: c5bef05b461fcad27de5b0c730eec8b9c49606cd
5
5
  SHA512:
6
- metadata.gz: 4f09449157f6142afa641e2fd78b06cf3a54f9d87005ddb0c3fabf77145ffacac0f4dc52d87fa7af685f248ab66e761ecdbb80667246826060089be7f27046dc
7
- data.tar.gz: 77c99fdbc05795f6d99a665161db680b37ee2e964c1a5ddfe2e6f833b89bb36f13202fc822f0b7b4305f860fab575ec924bf4d1051f791b5642e0fd6736d99ea
6
+ metadata.gz: 249916d10c938be1f880f3013f4a701e7eb52660d853d55d8cec2b280d1f0b6065628ab219b96a25c5e3777e6569365cfa9008a4cdd78d94aa93878ad3e3ddfa
7
+ data.tar.gz: d067723e49098a5fa604b5c12b08a4a916dd4b54451eb4cdeb7a5c19cb433df89218be795343baf318f98000a20857eb46f98b2e28f279bc55a97102d5cb2e6f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.1.7
2
+
3
+ * Remove reduncancy dots [17ae8cd]
4
+ The request was one extra.
5
+
1
6
  ## v0.1.6
2
7
 
3
8
  * Update gems [17ae8cd]
data/bin/gem-search CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'gem_search'
3
3
 
4
- Gem::Search::CommandBuilder.new(ARGV).build.call
4
+ GemSearch::CommandBuilder.new(ARGV).build.call
data/gem-search.gemspec CHANGED
@@ -11,7 +11,7 @@ def or_over_mac_os_lion?
11
11
 
12
12
  macos_full_version = `/usr/bin/sw_vers -productVersion`.chomp
13
13
  macos_version = macos_full_version[/10\.\d+/]
14
- macos_version >= '10.7' # 10.7 is lion
14
+ macos_version >= '10.7' # 10.7 is lion
15
15
  end
16
16
 
17
17
  Gem::Specification.new do |gem|
@@ -21,12 +21,12 @@ Gem::Specification.new do |gem|
21
21
  gem.summary = 'search gems with using rubygems.org API'
22
22
  gem.description = gem.summary
23
23
 
24
- gem.files = `git ls-files`.split($\)
25
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
24
+ gem.files = `git ls-files -z`.split("\x0")
25
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
26
26
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
27
27
  gem.name = 'gem-search'
28
28
  gem.require_paths = ['lib']
29
- gem.version = Gem::Search::VERSION
29
+ gem.version = GemSearch::VERSION
30
30
 
31
31
  gem.post_install_message = install_message
32
32
 
data/lib/gem_search.rb CHANGED
@@ -1,4 +1,4 @@
1
- module Gem::Search
1
+ module GemSearch
2
2
  require 'mem'
3
3
  require 'slop'
4
4
 
@@ -6,7 +6,6 @@ module Gem::Search
6
6
 
7
7
  require 'gem_search/command_builder'
8
8
  require 'gem_search/commands'
9
- require 'gem_search/version'
10
- require 'gem_search/rendering'
11
9
  require 'gem_search/executor'
10
+ require 'gem_search/version'
12
11
  end
@@ -1,4 +1,4 @@
1
- module Gem::Search
1
+ module GemSearch
2
2
  class CommandBuilder
3
3
  include Mem
4
4
 
@@ -1,4 +1,4 @@
1
- module Gem::Search
1
+ module GemSearch
2
2
  module Commands
3
3
  require 'gem_search/commands/base.rb'
4
4
  require 'gem_search/commands/browse.rb'
@@ -1,4 +1,4 @@
1
- module Gem::Search
1
+ module GemSearch
2
2
  module Commands
3
3
  class Base
4
4
  attr_reader :options
@@ -1,16 +1,16 @@
1
- module Gem::Search
1
+ module GemSearch
2
2
  module Commands
3
3
  class Browse < Base
4
4
  def call
5
5
  executor = Executor.new
6
6
  executor.browse(options[:browse])
7
- rescue OpenURI::HTTPError
8
- puts 'No such gem.'
9
- abort
10
- rescue => e
11
- puts e.message
12
- puts e.stacktrace if ENV['DEBUG']
13
- abort
7
+ rescue OpenURI::HTTPError
8
+ puts 'No such gem.'
9
+ abort
10
+ rescue => e
11
+ puts e.message
12
+ puts e.stacktrace if ENV['DEBUG']
13
+ abort
14
14
  end
15
15
  end
16
16
  end
@@ -1,4 +1,4 @@
1
- module Gem::Search
1
+ module GemSearch
2
2
  module Commands
3
3
  class Help < Base
4
4
  def call
@@ -1,4 +1,4 @@
1
- module Gem::Search
1
+ module GemSearch
2
2
  module Commands
3
3
  class Run < Base
4
4
  ENABLE_SORT_OPTS = {
@@ -12,11 +12,10 @@ module Gem::Search
12
12
  puts options
13
13
  abort
14
14
  end
15
-
16
15
  executor = Executor.new
17
16
  gem = options.arguments[0]
18
17
  executor.search(gem, setup_opts)
19
- rescue Gem::Search::LibraryNotFound => e
18
+ rescue GemSearch::LibraryNotFound => e
20
19
  puts e.message
21
20
  abort
22
21
  rescue => e
@@ -1,8 +1,8 @@
1
- module Gem::Search
1
+ module GemSearch
2
2
  module Commands
3
3
  class Version < Base
4
4
  def call
5
- puts "gem-search #{Gem::Search::VERSION}"
5
+ puts "gem-search #{GemSearch::VERSION}"
6
6
  end
7
7
  end
8
8
  end
@@ -1,30 +1,26 @@
1
1
  require 'json'
2
2
  require 'open-uri'
3
+ require 'gem_search/rendering'
4
+ require 'gem_search/utils/system_util'
3
5
 
4
- module Gem::Search
6
+ module GemSearch
5
7
  class Executor
6
8
  include Rendering
9
+ include Utils::SystemUtil
7
10
  BASE_URL = 'https://rubygems.org'
8
11
  SEARCH_API = "#{BASE_URL}/api/v1/search.json?query=%s&page=%d"
9
12
  GEM_API = "#{BASE_URL}/api/v1/gems/%s.json"
10
13
  GEM_URL = "#{BASE_URL}/gems/%s"
11
14
 
12
15
  MAX_REQUEST_COUNT = 20
16
+ MAX_GEMS_PER_PAGE = 30 # It has been determined by Github API
13
17
 
14
18
  def search(query, opts)
15
19
  return unless query
16
20
  print 'Searching '
17
- gems = []
18
- (1..MAX_REQUEST_COUNT).each do |n|
19
- print '.'
20
- url = SEARCH_API % [query, n]
21
- gems_by_page = open_rubygems_api(url)
22
- break if gems_by_page.size.zero?
23
- gems += gems_by_page
24
- end
21
+ gems = search_gems(query)
25
22
  puts
26
-
27
- fail Gem::Search::LibraryNotFound, 'We did not find results.' if gems.size.zero?
23
+ fail GemSearch::LibraryNotFound, 'We did not find results.' if gems.size.zero?
28
24
  gems_sort!(gems, opts[:sort])
29
25
  Executor.render(gems, opts[:detail])
30
26
  end
@@ -32,7 +28,7 @@ module Gem::Search
32
28
  def browse(gem)
33
29
  return unless gem
34
30
  api_url = GEM_API % gem
35
- result = open_rubygems_api(api_url)
31
+ result = request_ruby_gems_api(api_url)
36
32
  url = result['homepage_uri']
37
33
  if url.nil? || url.empty?
38
34
  url = GEM_URL % gem
@@ -43,31 +39,23 @@ module Gem::Search
43
39
 
44
40
  private
45
41
 
46
- # https://github.com/github/hub/blob/9c589396ae38f7b9f98319065ad491149954c152/lib/hub/context.rb#L517
47
- def browser_open(url)
48
- cmd = osx? ? 'open' :
49
- %w[xdg-open cygstart x-www-browser firefox opera mozilla netscape].find { |comm| which comm }
50
- system(cmd, url)
51
- end
52
-
53
- # refer to: https://github.com/github/hub/blob/9c589396ae38f7b9f98319065ad491149954c152/lib/hub/context.rb#L527
54
- def osx?
55
- require 'rbconfig'
56
- RbConfig::CONFIG['host_os'].to_s.include?('darwin')
42
+ def search_gems(query)
43
+ gems = []
44
+ (1..MAX_REQUEST_COUNT).each do |n|
45
+ print '.'
46
+ url = SEARCH_API % [query, n]
47
+ results = request_ruby_gems_api(url)
48
+ gems += results
49
+ break if search_ended?(results.size)
50
+ end
51
+ gems
57
52
  end
58
53
 
59
- def which(cmd)
60
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
61
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
62
- exts.each { |ext|
63
- exe = "#{path}/#{cmd}#{ext}"
64
- return exe if File.executable? exe
65
- }
66
- end
67
- return nil
54
+ def search_ended?(size)
55
+ size < MAX_GEMS_PER_PAGE || size.zero?
68
56
  end
69
57
 
70
- def open_rubygems_api(url)
58
+ def request_ruby_gems_api(url)
71
59
  option = {}
72
60
  proxy = URI.parse(url).find_proxy
73
61
  if proxy
@@ -1,4 +1,4 @@
1
- module Gem::Search
1
+ module GemSearch
2
2
  module Rendering
3
3
  # NAME', 'DL(ver)', 'DL(all)', 'HOMEPAGE'
4
4
  DEFAULT_RULED_LINE_SIZE = [50, 8, 9, 60]
@@ -7,11 +7,11 @@ module Gem::Search
7
7
  base.extend(self)
8
8
  end
9
9
 
10
- def render(gems, opt_detail)
11
- @opt_detail = opt_detail
10
+ def render(gems, has_detail)
11
+ @has_detail = has_detail
12
12
  ruled_line_size(gems)
13
- render_to_header
14
- render_to_body(gems)
13
+ render_header
14
+ render_body(gems)
15
15
  end
16
16
 
17
17
  private
@@ -22,33 +22,31 @@ module Gem::Search
22
22
  @ruled_line_size[0] = max_name_size if max_name_size > @ruled_line_size[0]
23
23
  end
24
24
 
25
- def render_to_header
25
+ def render_header
26
26
  f = @ruled_line_size
27
27
  fmt = "%-#{f[0]}s %#{f[1]}s %#{f[2]}s"
28
28
  titles = ['NAME', 'DL(ver)', 'DL(all)']
29
- hyphens = ['-'*f[0], '-'*f[1], '-'*f[2]]
30
- if @opt_detail
29
+ hyphens = f[0, 3].map { |field| '-' * field }
30
+ if @has_detail
31
31
  fmt << " %-#{f[3]}s"
32
32
  titles << 'HOMEPAGE'
33
- hyphens << '-'*f[3]
33
+ hyphens << '-' * f[3]
34
34
  end
35
-
36
35
  puts fmt % titles
37
36
  puts fmt % hyphens
38
37
  end
39
38
 
40
- def render_to_body(gems)
39
+ def render_body(gems)
41
40
  f = @ruled_line_size
42
-
43
41
  fmt = "%-#{f[0]}s %#{f[1]}d %#{f[2]}d"
44
- fmt << " %-#{f[3]}s" if @opt_detail
42
+ fmt << " %-#{f[3]}s" if @has_detail
45
43
  gems.each do |gem|
46
44
  columns = [
47
45
  "#{gem['name']} (#{gem['version']})",
48
46
  gem['version_downloads'],
49
47
  gem['downloads']
50
48
  ]
51
- columns << gem['homepage_uri'] if @opt_detail
49
+ columns << gem['homepage_uri'] if @has_detail
52
50
  puts fmt % columns
53
51
  end
54
52
  end
@@ -0,0 +1,26 @@
1
+ module GemSearch::Utils
2
+ module SystemUtil
3
+ # https://github.com/github/hub/blob/9c589396ae38f7b9f98319065ad491149954c152/lib/hub/context.rb#L517
4
+ def browser_open(url)
5
+ cmd = osx? ? 'open' : %w[xdg-open cygstart x-www-browser firefox opera mozilla netscape].find { |comm| which comm }
6
+ system(cmd, url)
7
+ end
8
+
9
+ # refer to: https://github.com/github/hub/blob/9c589396ae38f7b9f98319065ad491149954c152/lib/hub/context.rb#L527
10
+ def osx?
11
+ require 'rbconfig'
12
+ RbConfig::CONFIG['host_os'].to_s.include?('darwin')
13
+ end
14
+
15
+ def which(cmd)
16
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
17
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
18
+ exts.each do |ext|
19
+ exe = "#{path}/#{cmd}#{ext}"
20
+ return exe if File.executable? exe
21
+ end
22
+ end
23
+ nil
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
- module Gem::Search
2
- VERSION = '0.1.6'
1
+ module GemSearch
2
+ VERSION = '0.1.7'
3
3
  end
@@ -39,7 +39,7 @@ RSpec.describe 'bin/gem-search' do
39
39
  context 'with -v' do
40
40
  subject { `#{BIN} -v` }
41
41
  it 'display an usage' do
42
- should == "gem-search #{Gem::Search::VERSION}\n"
42
+ should == "gem-search #{GemSearch::VERSION}\n"
43
43
  end
44
44
  end
45
45
  end
@@ -1,4 +1,4 @@
1
- include Gem::Search
1
+ include GemSearch
2
2
 
3
3
  RSpec.describe Commands::Browse do
4
4
  describe '#call' do
@@ -1,4 +1,4 @@
1
- include Gem::Search
1
+ include GemSearch
2
2
 
3
3
  RSpec.describe Commands::Run do
4
4
  describe '#call' do
@@ -1,4 +1,4 @@
1
- include Gem::Search
1
+ include GemSearch
2
2
 
3
3
  RSpec.describe Executor do
4
4
  let(:executor) { Executor.new }
@@ -29,7 +29,7 @@ RSpec.describe Executor do
29
29
  context 'with no sort option' do
30
30
  it 'display rubygems ordering by DL(all)' do
31
31
  res = <<-'EOS'.unindent
32
- |Searching ..
32
+ |Searching .
33
33
  |NAME DL(ver) DL(all) HOMEPAGE
34
34
  |-------------------------------------------------- -------- --------- ------------------------------------------------------------
35
35
  |factory_girl (3.6.0) 541 2042859 https://github.com/thoughtbot/factory_girl
@@ -51,7 +51,7 @@ RSpec.describe Executor do
51
51
  context 'with no sort option' do
52
52
  it 'display rubygems ordering by DL(all)' do
53
53
  res = <<-'EOS'.unindent
54
- |Searching ..
54
+ |Searching .
55
55
  |NAME DL(ver) DL(all)
56
56
  |-------------------------------------------------- -------- ---------
57
57
  |factory_girl (3.6.0) 541 2042859
@@ -65,7 +65,7 @@ RSpec.describe Executor do
65
65
  context 'with sort option: [a]download' do
66
66
  it 'display rubygems ordering by DL(all)' do
67
67
  res = <<-'EOS'.unindent
68
- |Searching ..
68
+ |Searching .
69
69
  |NAME DL(ver) DL(all)
70
70
  |-------------------------------------------------- -------- ---------
71
71
  |factory_girl (3.6.0) 541 2042859
@@ -79,7 +79,7 @@ RSpec.describe Executor do
79
79
  context 'with sort option: [v]version_downloads' do
80
80
  it 'display rubygems ordering by DL(ver)' do
81
81
  res = <<-'EOS'.unindent
82
- |Searching ..
82
+ |Searching .
83
83
  |NAME DL(ver) DL(all)
84
84
  |-------------------------------------------------- -------- ---------
85
85
  |factory_girl_rails (3.5.0) 39724 1238780
@@ -93,7 +93,7 @@ RSpec.describe Executor do
93
93
  context 'with sort option: [n]ame' do
94
94
  it 'display rubygems ordering by name' do
95
95
  res = <<-'EOS'.unindent
96
- |Searching ..
96
+ |Searching .
97
97
  |NAME DL(ver) DL(all)
98
98
  |-------------------------------------------------- -------- ---------
99
99
  |factory_girl (3.6.0) 541 2042859
@@ -115,7 +115,7 @@ RSpec.describe Executor do
115
115
  let(:query) { 'cucumber-' }
116
116
  it 'display rubygems ordering by name' do
117
117
  res = <<-'EOS'.unindent
118
- |Searching ....
118
+ |Searching ...
119
119
  |NAME DL(ver) DL(all)
120
120
  |-------------------------------------------------- -------- ---------
121
121
  |autotest-cucumber-notification (0.0.6) 1027 3607
@@ -195,7 +195,7 @@ RSpec.describe Executor do
195
195
  let(:query) { 'size_is_42_2345678901234567890123456789012' }
196
196
  it 'is 50 characters' do
197
197
  res = <<-'EOS'.unindent
198
- |Searching ..
198
+ |Searching .
199
199
  |NAME DL(ver) DL(all)
200
200
  |-------------------------------------------------- -------- ---------
201
201
  |size_is_42_2345678901234567890123456789012 (0.0.1) 100 1000
@@ -212,7 +212,7 @@ RSpec.describe Executor do
212
212
  let(:query) { 'size_is_43_23456789012345678901234567890123' }
213
213
  it 'is 51 characters' do
214
214
  res = <<-'EOS'.unindent
215
- |Searching ..
215
+ |Searching .
216
216
  |NAME DL(ver) DL(all)
217
217
  |--------------------------------------------------- -------- ---------
218
218
  |size_is_43_23456789012345678901234567890123 (0.0.2) 200 2000
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - rochefort
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-11 00:00:00.000000000 Z
11
+ date: 2016-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop
@@ -122,6 +122,7 @@ files:
122
122
  - lib/gem_search/commands/version.rb
123
123
  - lib/gem_search/executor.rb
124
124
  - lib/gem_search/rendering.rb
125
+ - lib/gem_search/utils/system_util.rb
125
126
  - lib/gem_search/version.rb
126
127
  - sideci_build.txt
127
128
  - spec/bin/gem_search_spec.rb