gem-search 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a1e1368ab020ee422a5df16ebed3581a5d1d295
4
- data.tar.gz: bf0313e4e6bbc42fdbff3b5f51f781048531ceb2
3
+ metadata.gz: e9f10dc591dfbf9e885007e8e2580719038dd36b
4
+ data.tar.gz: d62a21ea00f03fbfe5754d0d944d5acdbbc1d417
5
5
  SHA512:
6
- metadata.gz: d95848032e753ecb45d4757ccb2a951e4da0a3dc2983822b533a8bc6a824a8d847dfa1f30e9221190c8a799e4c415a08775614b9733df301ce3e994d6f4cd421
7
- data.tar.gz: 0e6b871fcc56fb661ae43db82a2812c01f506cc59b480d124778743ca8e48025008c0098e0406e3450ab6f915ff9dc04472285dbc64088f687e42080331d692a
6
+ metadata.gz: a858c132709e646532309ded6096d6b12a3514a72316631705966684521a6796b6d202a68c975a0ac6599eff8d5cea3d76aa5962c78e5e4ba4c6654c9e84e3cf
7
+ data.tar.gz: 6f0d063bd87eee11f0f9b15f79bcdea9f64444e8e9e03818e437ff2fa934ee746cb41a081b64549476105d987750eb5313358c193d10315f88fda9adc855278e
@@ -1,3 +1,7 @@
1
+ ## v0.1.3
2
+
3
+ * Implement a feature that is shown a homepage url when detail ooption is selected [f89d9c2]
4
+
1
5
  ## v0.1.2
2
6
 
3
7
  * Correspond to linux with browse option [80bb881]
data/README.md CHANGED
@@ -83,6 +83,38 @@ gtk-webkit-ruby (0.0.3) 289 289
83
83
  capybara-webkit-remote (0.0.4) 209 838
84
84
  ```
85
85
 
86
+ ### Display Homepage URL
87
+ gem-search `keyword' -d
88
+
89
+ or
90
+
91
+ gem-search `keyword' --detail
92
+
93
+ e.g.:
94
+ ```
95
+ $ gem-search webkit -d
96
+ NAME DL(ver) DL(all) HOMEPAGE
97
+ -------------------------------------------------- -------- --------- ------------------------------------------------------------
98
+ capybara-webkit (1.2.0) 11691 1291179 http://github.com/thoughtbot/capybara-webkit
99
+ jasmine-headless-webkit (0.8.4) 213767 273893
100
+ guard-jasmine-headless-webkit (0.3.2) 66446 80976
101
+ rspec-formatter-webkit (2.4.0) 1532 14984 http://deveiate.org/webkit-rspec-formatter.html
102
+ webkit_remote (0.5.5) 224 6111 http://github.com/pwnall/webkit_remote
103
+ webkit-gtk (2.2.0) 297 5571 http://ruby-gnome2.sourceforge.jp/
104
+ gtk-webkit-ruby (0.0.8) 716 4585 http://github.com/geoffyoungs/gtk-webkit-ruby
105
+ capybara-webkit-remote (0.0.4) 1206 4450 http://github.com/pettyjamesm/capybara-webkit-remote
106
+ intentmedia-capybara-webkit (0.7.2.4) 1155 4208 http://github.com/thoughtbot/capybara-webkit
107
+ webkit-gtk2 (2.2.0) 282 3976 http://ruby-gnome2.sourceforge.jp/
108
+ webkit-rspec-formatter (2.0.2) 1417 3614 http://deveiate.org/webkit-rspec-formatter.html
109
+ gtk_webkit_pdf (0.0.2.2) 698 3314 https://github.com/mohanraj-ramanujam/gtk_webkit_pdf
110
+ otherinbox-capybara-webkit (0.12.0.1) 2343 3145 http://github.com/thoughtbot/capybara-webkit
111
+ jasmine-headless-webkit-firstbanco (0.9.0.rc.4) 179 1591
112
+ webkit_remote_unstable (0.1.3) 222 1295 http://github.com/pwnall/webkit_remote_unstable
113
+ imseng-capybara-webkit (0.12.1) 549 549 http://github.com/imseng/capybara-webkit
114
+ bitium-capybara-webkit (1.1.1) 388 388 http://github.com/thoughtbot/capybara-webkit
115
+ node-webkit-bootstrap (1.0.0) 226 226 https://github.com/audiosocket/node-webkit-bootstrap
116
+ ```
117
+
86
118
  ### Browse
87
119
  It open rubygem's homepage in the system's default web browser.
88
120
 
@@ -33,6 +33,7 @@ Gem::Specification.new do |gem|
33
33
  gem.add_dependency 'slop', '~>3.6.0'
34
34
  gem.add_dependency 'json', '~>1.8.1'
35
35
 
36
+ # gem.add_development_dependency 'pry', '~>0.9.12.6'
36
37
  gem.add_development_dependency 'webmock', '~>1.18.0'
37
38
  gem.add_development_dependency 'rake', '~>10.3.1'
38
39
 
@@ -24,6 +24,7 @@ module Gem::Search
24
24
  ' [v]er :DL(ver) eg. gem-search webkit -s v',
25
25
  ' [n]ame : eg. gem-search webkit -s n',
26
26
  ]), argument: :optional
27
+ on :d, :detail, 'Display homepage url of gem'
27
28
  on :v, :version, 'Display the version.'
28
29
 
29
30
  command 'browse' do
@@ -51,11 +52,7 @@ module Gem::Search
51
52
  validate
52
53
 
53
54
  gs = Executor.new
54
- if ENABLE_SORT_OPT[OPTS['sort']]
55
- gs.search(ARGV[0], ENABLE_SORT_OPT[OPTS['sort']])
56
- else
57
- gs.search(ARGV[0])
58
- end
55
+ gs.search(ARGV[0], setup_opts)
59
56
  rescue LibraryNotFound => e
60
57
  puts e.message
61
58
  abort
@@ -65,6 +62,13 @@ module Gem::Search
65
62
  abort
66
63
  end
67
64
 
65
+ def setup_opts
66
+ {
67
+ sort: ENABLE_SORT_OPT[OPTS['sort']] || 'downloads',
68
+ detail: OPTS.detail?
69
+ }
70
+ end
71
+
68
72
  private
69
73
 
70
74
  def version
@@ -11,7 +11,7 @@ module Gem::Search
11
11
 
12
12
  MAX_REQUEST_COUNT = 20
13
13
 
14
- def search(query, opt_sort = 'downloads')
14
+ def search(query, opts)
15
15
  return unless query
16
16
  print 'Searching '
17
17
  gems = []
@@ -25,8 +25,8 @@ module Gem::Search
25
25
  puts
26
26
 
27
27
  fail Gem::Search::LibraryNotFound, 'We did not find results.' if gems.size.zero?
28
- gems_sort!(gems, opt_sort)
29
- Executor.render(gems)
28
+ gems_sort!(gems, opts[:sort])
29
+ Executor.render(gems, opts[:detail])
30
30
  end
31
31
 
32
32
  def browse(gem)
@@ -55,6 +55,17 @@ module Gem::Search
55
55
  RbConfig::CONFIG['host_os'].to_s.include?('darwin')
56
56
  end
57
57
 
58
+ def which(cmd)
59
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
60
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
61
+ exts.each { |ext|
62
+ exe = "#{path}/#{cmd}#{ext}"
63
+ return exe if File.executable? exe
64
+ }
65
+ end
66
+ return nil
67
+ end
68
+
58
69
  def open_rubygems_api(url)
59
70
  option = {}
60
71
  proxy = URI.parse(url).find_proxy
@@ -1,12 +1,14 @@
1
1
  module Gem::Search
2
2
  module Rendering
3
- DEFAULT_RULED_LINE_SIZE = [50, 8, 9]
3
+ # NAME', 'DL(ver)', 'DL(all)', 'HOMEPAGE'
4
+ DEFAULT_RULED_LINE_SIZE = [50, 8, 9, 60]
4
5
 
5
6
  def self.included(base)
6
7
  base.extend(self)
7
8
  end
8
9
 
9
- def render(gems)
10
+ def render(gems, opt_detail)
11
+ @opt_detail = opt_detail
10
12
  ruled_line_size(gems)
11
13
  render_to_header
12
14
  render_to_body(gems)
@@ -15,26 +17,39 @@ module Gem::Search
15
17
  private
16
18
 
17
19
  def ruled_line_size(gems)
20
+ @ruled_line_size = DEFAULT_RULED_LINE_SIZE.dup
18
21
  max_name_size = gems.map { |gem| "#{gem['name'] } (#{gem['version']})".size }.max
19
- DEFAULT_RULED_LINE_SIZE[0] = max_name_size if max_name_size > DEFAULT_RULED_LINE_SIZE[0]
22
+ @ruled_line_size[0] = max_name_size if max_name_size > @ruled_line_size[0]
20
23
  end
21
24
 
22
25
  def render_to_header
23
- f = DEFAULT_RULED_LINE_SIZE
26
+ f = @ruled_line_size
24
27
  fmt = "%-#{f[0]}s %#{f[1]}s %#{f[2]}s"
25
- puts fmt % ['NAME', 'DL(ver)', 'DL(all)']
26
- puts fmt % ['-'*f[0], '-'*f[1], '-'*f[2]]
28
+ titles = ['NAME', 'DL(ver)', 'DL(all)']
29
+ hyphens = ['-'*f[0], '-'*f[1], '-'*f[2]]
30
+ if @opt_detail
31
+ fmt << " %-#{f[3]}s"
32
+ titles << 'HOMEPAGE'
33
+ hyphens << '-'*f[3]
34
+ end
35
+
36
+ puts fmt % titles
37
+ puts fmt % hyphens
27
38
  end
28
39
 
29
40
  def render_to_body(gems)
30
- f = DEFAULT_RULED_LINE_SIZE
41
+ f = @ruled_line_size
42
+
31
43
  fmt = "%-#{f[0]}s %#{f[1]}d %#{f[2]}d"
44
+ fmt << " %-#{f[3]}s" if @opt_detail
32
45
  gems.each do |gem|
33
- puts fmt % [
46
+ columns = [
34
47
  "#{gem['name']} (#{gem['version']})",
35
48
  gem['version_downloads'],
36
49
  gem['downloads']
37
50
  ]
51
+ columns << gem['homepage_uri'] if @opt_detail
52
+ puts fmt % columns
38
53
  end
39
54
  end
40
55
  end
@@ -1,3 +1,3 @@
1
1
  module Gem::Search
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -9,6 +9,7 @@ Usage: gem-search gem_name [options]
9
9
  [a]ll :DL(all) eg. gem-search webkit -s a
10
10
  [v]er :DL(ver) eg. gem-search webkit -s v
11
11
  [n]ame : eg. gem-search webkit -s n
12
+ -d, --detail Display homepage url of gem
12
13
  -v, --version Display the version.
13
14
  -h, --help Display this help message.
14
15
 
@@ -18,7 +18,7 @@ RSpec.describe Command do
18
18
  allow(Command::OPTS).to receive(:[]).and_return(nil)
19
19
  end
20
20
  it 'called with no sort option' do
21
- expect(@executor).to receive(:search).with(query).once
21
+ expect(@executor).to receive(:search).with(query, default_opts).once
22
22
  Command.new.run
23
23
  end
24
24
  end
@@ -29,7 +29,7 @@ RSpec.describe Command do
29
29
  allow(Command::OPTS).to receive(:[]).with('sort').and_return('a')
30
30
  end
31
31
  it 'called with sort option' do
32
- expect(@executor).to receive(:search).with(query, 'downloads').once
32
+ expect(@executor).to receive(:search).with(query, default_opts(sort: 'downloads')).once
33
33
  Command.new.run
34
34
  end
35
35
  end
@@ -20,7 +20,29 @@ RSpec.describe Executor do
20
20
  context 'when no matching gem' do
21
21
  before { stub_request_search_no_result_with_page(query, 1) }
22
22
  let(:query) { 'no_match_gem_name' }
23
- it { expect { @executor.search(query) }.to raise_error(LibraryNotFound) }
23
+ it { expect { @executor.search(query, default_opts) }.to raise_error(LibraryNotFound) }
24
+ end
25
+
26
+ describe 'with detail' do
27
+ before do
28
+ stub_request_search(query, 1, dummy_search_result)
29
+ stub_request_search_no_result_with_page(query, 2)
30
+ end
31
+ let(:query) { 'factory_girl' }
32
+
33
+ context 'with no sort option' do
34
+ it 'display rubygems ordering by DL(all)' do
35
+ res = <<-'EOS'.unindent
36
+ |Searching ..
37
+ |NAME DL(ver) DL(all) HOMEPAGE
38
+ |-------------------------------------------------- -------- --------- ------------------------------------------------------------
39
+ |factory_girl (3.6.0) 541 2042859 https://github.com/thoughtbot/factory_girl
40
+ |factory_girl_rails (3.5.0) 39724 1238780 http://github.com/thoughtbot/factory_girl_rails
41
+ |factory_girl_generator (0.0.3) 8015 15547 http://github.com/leshill/factory_girl_generator
42
+ EOS
43
+ expect { @executor.search(query, default_opts(detail: true)) }.to output(res).to_stdout
44
+ end
45
+ end
24
46
  end
25
47
 
26
48
  describe 'sorting' do
@@ -31,7 +53,7 @@ RSpec.describe Executor do
31
53
  let(:query) { 'factory_girl' }
32
54
 
33
55
  context 'with no sort option' do
34
- it 'display rubygems ordering by name' do
56
+ it 'display rubygems ordering by DL(all)' do
35
57
  res = <<-'EOS'.unindent
36
58
  |Searching ..
37
59
  |NAME DL(ver) DL(all)
@@ -40,12 +62,12 @@ RSpec.describe Executor do
40
62
  |factory_girl_rails (3.5.0) 39724 1238780
41
63
  |factory_girl_generator (0.0.3) 8015 15547
42
64
  EOS
43
- expect { @executor.search(query) }.to output(res).to_stdout
65
+ expect { @executor.search(query, default_opts) }.to output(res).to_stdout
44
66
  end
45
67
  end
46
68
 
47
69
  context 'with sort option: [a]download' do
48
- it 'display rubygems ordering by name' do
70
+ it 'display rubygems ordering by DL(all)' do
49
71
  res = <<-'EOS'.unindent
50
72
  |Searching ..
51
73
  |NAME DL(ver) DL(all)
@@ -54,12 +76,12 @@ RSpec.describe Executor do
54
76
  |factory_girl_rails (3.5.0) 39724 1238780
55
77
  |factory_girl_generator (0.0.3) 8015 15547
56
78
  EOS
57
- expect { @executor.search(query, 'download') }.to output(res).to_stdout
79
+ expect { @executor.search(query, default_opts) }.to output(res).to_stdout
58
80
  end
59
81
  end
60
82
 
61
83
  context 'with sort option: [v]version_downloads' do
62
- it 'display rubygems ordering by name' do
84
+ it 'display rubygems ordering by DL(ver)' do
63
85
  res = <<-'EOS'.unindent
64
86
  |Searching ..
65
87
  |NAME DL(ver) DL(all)
@@ -68,7 +90,7 @@ RSpec.describe Executor do
68
90
  |factory_girl_generator (0.0.3) 8015 15547
69
91
  |factory_girl (3.6.0) 541 2042859
70
92
  EOS
71
- expect { @executor.search(query, 'version_downloads') }.to output(res).to_stdout
93
+ expect { @executor.search(query, default_opts(sort: 'version_downloads')) }.to output(res).to_stdout
72
94
  end
73
95
  end
74
96
 
@@ -82,7 +104,7 @@ RSpec.describe Executor do
82
104
  |factory_girl_generator (0.0.3) 8015 15547
83
105
  |factory_girl_rails (3.5.0) 39724 1238780
84
106
  EOS
85
- expect { @executor.search(query, 'name') }.to output(res).to_stdout
107
+ expect { @executor.search(query, default_opts(sort: 'name')) }.to output(res).to_stdout
86
108
  end
87
109
  end
88
110
  end
@@ -164,7 +186,7 @@ RSpec.describe Executor do
164
186
  |tasty-cucumber-client (0.1.10) 1504 11518
165
187
  |vagrant-cucumber-host (0.1.14) 163 163
166
188
  EOS
167
- expect { @executor.search(query, 'name') }.to output(res).to_stdout
189
+ expect { @executor.search(query, default_opts(sort: 'name')) }.to output(res).to_stdout
168
190
  end
169
191
  end
170
192
 
@@ -182,7 +204,7 @@ RSpec.describe Executor do
182
204
  |-------------------------------------------------- -------- ---------
183
205
  |size_is_42_2345678901234567890123456789012 (0.0.1) 100 1000
184
206
  EOS
185
- expect { @executor.search(query) }.to output(res).to_stdout
207
+ expect { @executor.search(query, default_opts) }.to output(res).to_stdout
186
208
  end
187
209
  end
188
210
 
@@ -199,7 +221,7 @@ RSpec.describe Executor do
199
221
  |--------------------------------------------------- -------- ---------
200
222
  |size_is_43_23456789012345678901234567890123 (0.0.2) 200 2000
201
223
  EOS
202
- expect { @executor.search(query) }.to output(res).to_stdout
224
+ expect { @executor.search(query, default_opts) }.to output(res).to_stdout
203
225
  end
204
226
  end
205
227
  end
@@ -224,7 +246,7 @@ RSpec.describe Executor do
224
246
  context 'when no homepage_uri' do
225
247
  before do
226
248
  url = Executor::GEM_URL % query
227
- allow(@executor).to receive(:system).with('open', url)
249
+ allow(@executor).to receive(:system).with(anything(), url)
228
250
  stub_request_gems(query, load_http_stubs("gems/#{query}.json"))
229
251
  end
230
252
  let(:query) { 'git-trend_no_homepage' }
@@ -238,7 +260,7 @@ RSpec.describe Executor do
238
260
  before do
239
261
  http_stub = load_http_stubs("gems/#{query}.json")
240
262
  url = JSON.parse(http_stub)['homepage_uri']
241
- allow(@executor).to receive(:system).with('open', url)
263
+ allow(@executor).to receive(:system).with(anything(), url)
242
264
  stub_request_gems(query, http_stub)
243
265
  end
244
266
  let(:query) { 'git-trend' }
@@ -4,6 +4,7 @@ require 'simplecov'
4
4
  SimpleCov.start
5
5
 
6
6
  require 'webmock/rspec'
7
+ # require 'pry'
7
8
  require 'gem_search'
8
9
 
9
10
  RSpec.configure do |config|
@@ -117,6 +118,12 @@ def dummy_search_result
117
118
  ].to_json
118
119
  end
119
120
 
121
+ def default_opts(merge_opts = nil)
122
+ opts = { sort: 'downloads', detail: false }
123
+ opts.merge!(merge_opts) if merge_opts
124
+ opts
125
+ end
126
+
120
127
  class String
121
128
  def unindent
122
129
  gsub(/^\s+\|/, '')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - rochefort