gem-search 0.1.0 → 0.1.1

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: fa5d29683d40347c2e64155c2eaec2d83a339595
4
- data.tar.gz: ddabcfcf4e8f76e4678435f790c2ba4c329d0f67
3
+ metadata.gz: d6ff3a0f935a8163dae5b0184b2244d681de1b1b
4
+ data.tar.gz: e3ae44d76970cfabf800fbc3fe3db8d0fb69764c
5
5
  SHA512:
6
- metadata.gz: 87f4cb2856f3830c13c762a777000a71a5453d0c73aa01e4c39c41a8f09c1f84136818cb51525ae6dd71542b8a9e5a2b7e32e894a986d5b88c01f3ef2f66c188
7
- data.tar.gz: 2a4e03660736f1a56e27c4676ff808ef4139d47b7171dfda94cf3cdddf92624f90f3ea28e4591ce32b64e87a0d7c5229fc17e4a5a2d5c4f5699a8b6507814546
6
+ metadata.gz: 01886f5d4122f7e45c08ad2042a0540079f821ef86c7363af4440b8fcf39d6c3e9e2f4e00ddbb980aa3d1b60948c268cf33e7ffa2d0f6ee7266f30d4c5f20a56
7
+ data.tar.gz: 40d0eb2af445c882777d04aefe62aa03b65fd42718594a4acd3f1a1fc570510c75bd25ded9ea399ff5447dbf29aab3558498ccb302b1be50338aba014bb7cf2b
@@ -0,0 +1,5 @@
1
+ ## v0.1.1
2
+
3
+ * Change default sort option from n[ame] to do a[ll] (download) [7041464]
4
+ * Fix default sort option doesn't work. [e404c6e]
5
+ * Fix proxy doesn't work by not using authentication [210ea37]
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
- [![Build Status](https://secure.travis-ci.org/rochefort/gem-search.png)](http://travis-ci.org/rochefort/gem-search)
2
- [![Dependency Status](https://gemnasium.com/rochefort/gem-search.png)](https://gemnasium.com/rochefort/gem-search)
3
- [![Code Climate](https://codeclimate.com/github/rochefort/gem-search.png)](https://codeclimate.com/github/rochefort/gem-search)
4
- [![Gem Version](https://badge.fury.io/rb/gem-search.svg)](http://badge.fury.io/rb/gem-search)
1
+ [![Build Status](http://img.shields.io/travis/rochefort/gem-search.svg?style=flat)](http://travis-ci.org/rochefort/gem-search)
2
+ [![Dependency Status](http://img.shields.io/gemnasium/rochefort/gem-search.svg?style=flat)](https://gemnasium.com/rochefort/gem-search)
3
+ [![Code Climate](http://img.shields.io/codeclimate/github/rochefort/gem-search.svg?style=flat)](https://codeclimate.com/github/rochefort/gem-search)
4
+ [![Gem Version](http://img.shields.io/gem/v/gem-search.svg?style=flat)](http://badge.fury.io/rb/gem-search)
5
5
 
6
6
  # gem-search
7
7
 
@@ -12,15 +12,17 @@ module Gem::Search
12
12
  ENABLE_SORT_OPT = {
13
13
  'v' => 'version_downloads',
14
14
  'a' => 'downloads',
15
+ 'n' => 'name',
15
16
  }
16
17
 
17
18
  OPTS = Slop.parse(help: true) do
18
19
  banner "Usage: gem-search gem_name [options]\n"
19
20
  on :s, :sort, opt_description([
20
21
  'Sort by the item.',
21
- ' [n]ame :default eg. gem-search webkit',
22
+ ' default [a]ll',
23
+ ' [a]ll :DL(all) eg. gem-search webkit -s a',
22
24
  ' [v]er :DL(ver) eg. gem-search webkit -s v',
23
- ' [a]ll :DL(all) eg. gem-search webkit -s a'
25
+ ' [n]ame : eg. gem-search webkit -s n',
24
26
  ]), :argument => :optional
25
27
  on :v, :version, 'Display the version.'
26
28
  end
@@ -30,7 +32,11 @@ module Gem::Search
30
32
  validate
31
33
 
32
34
  gs = Executor.new
33
- gs.search(ARGV[0], ENABLE_SORT_OPT[OPTS['sort']])
35
+ if ENABLE_SORT_OPT[OPTS['sort']]
36
+ gs.search(ARGV[0], ENABLE_SORT_OPT[OPTS['sort']])
37
+ else
38
+ gs.search(ARGV[0])
39
+ end
34
40
  rescue LibraryNotFound => e
35
41
  puts e.message
36
42
  abort
@@ -58,4 +64,4 @@ module Gem::Search
58
64
  end
59
65
  end
60
66
  end
61
- end
67
+ end
@@ -8,9 +8,8 @@ module Gem::Search
8
8
  SEARCH_URL = "#{BASE_URL}/api/v1/search.json?query=%s&page=%d"
9
9
  MAX_REQUEST_COUNT = 20
10
10
 
11
- def search(query, opt_sort='name')
11
+ def search(query, opt_sort='downloads')
12
12
  return unless query
13
-
14
13
  print 'Searching '
15
14
  gems = []
16
15
  (1..MAX_REQUEST_COUNT).each do |n|
@@ -31,8 +30,12 @@ module Gem::Search
31
30
  def search_rubygems(url)
32
31
  option = {}
33
32
  proxy = URI.parse(url).find_proxy
34
- if proxy && proxy.user && proxy.password
35
- option[:proxy_http_basic_authentication] = [proxy, proxy.user, proxy.password]
33
+ if proxy
34
+ if proxy.user && proxy.password
35
+ option[:proxy_http_basic_authentication] = [proxy, proxy.user, proxy.password]
36
+ else
37
+ option[:proxy] = proxy
38
+ end
36
39
  end
37
40
  JSON.parse(open(url, option).read)
38
41
  end
@@ -1,3 +1,3 @@
1
1
  module Gem::Search
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -5,9 +5,10 @@ USAGE = <<-EOS
5
5
  Usage: gem-search gem_name [options]
6
6
 
7
7
  -s, --sort Sort by the item.
8
- [n]ame :default eg. gem-search webkit
9
- [v]er :DL(ver) eg. gem-search webkit -s v
8
+ default [a]ll
10
9
  [a]ll :DL(all) eg. gem-search webkit -s a
10
+ [v]er :DL(ver) eg. gem-search webkit -s v
11
+ [n]ame : eg. gem-search webkit -s n
11
12
  -v, --version Display the version.
12
13
  -h, --help Display this help message.
13
14
  EOS
@@ -30,8 +31,7 @@ describe 'bin/gem-search' do
30
31
  it_behaves_like 'display an usage'
31
32
  end
32
33
 
33
- # non-exisitng option: -x
34
- context 'with -x' do
34
+ context 'with -x(non-exisitng option)' do
35
35
  subject { `#{BIN} -x` }
36
36
  it_behaves_like 'display an usage'
37
37
  end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ include Gem::Search
4
+
5
+ describe Command do
6
+ describe '#run' do
7
+ before do
8
+ @executor = Executor.new
9
+ Executor.should_receive(:new).and_return(@executor)
10
+ ARGV.stub(:[]).with(0).and_return(query)
11
+ stub_request_search(1, dummy_search_result)
12
+ stub_request_no_result_with_page(2)
13
+ end
14
+ let(:query) {'factory-girl'}
15
+
16
+ context 'with no sort option' do
17
+ before do
18
+ Command::OPTS.stub(:[]).and_return(nil)
19
+ end
20
+ it 'called with no sort option' do
21
+ @executor.should_receive(:search).with(query).once
22
+ Command.new.run
23
+ end
24
+ end
25
+
26
+ context 'with sort option' do
27
+ before do
28
+ Command::OPTS.stub(:[]).and_return(nil)
29
+ Command::OPTS.stub(:[]).with('sort').and_return('a')
30
+ end
31
+ it 'called with sort option' do
32
+ @executor.should_receive(:search).with(query, 'downloads').once
33
+ Command.new.run
34
+ end
35
+ end
36
+ end
37
+ end
@@ -37,8 +37,21 @@ describe Executor do
37
37
  |NAME DL(ver) DL(all)
38
38
  |-------------------------------------------------- -------- ---------
39
39
  |factory_girl (3.6.0) 541 2042859
40
+ |factory_girl_rails (3.5.0) 39724 1238780
40
41
  |factory_girl_generator (0.0.3) 8015 15547
42
+ EOS
43
+ end
44
+ end
45
+
46
+ context 'with sort option: [a]download' do
47
+ it 'display rubygems ordering by name' do
48
+ capture(:stdout) { @executor.search(query, 'download') }.should == <<-'EOS'.unindent
49
+ |Searching ..
50
+ |NAME DL(ver) DL(all)
51
+ |-------------------------------------------------- -------- ---------
52
+ |factory_girl (3.6.0) 541 2042859
41
53
  |factory_girl_rails (3.5.0) 39724 1238780
54
+ |factory_girl_generator (0.0.3) 8015 15547
42
55
  EOS
43
56
  end
44
57
  end
@@ -56,15 +69,15 @@ describe Executor do
56
69
  end
57
70
  end
58
71
 
59
- context 'with sort option: [a]download' do
72
+ context 'with sort option: [n]ame' do
60
73
  it 'display rubygems ordering by name' do
61
- capture(:stdout) { @executor.search(query, 'download') }.should == <<-'EOS'.unindent
74
+ capture(:stdout) { @executor.search(query, 'name') }.should == <<-'EOS'.unindent
62
75
  |Searching ..
63
76
  |NAME DL(ver) DL(all)
64
77
  |-------------------------------------------------- -------- ---------
65
78
  |factory_girl (3.6.0) 541 2042859
66
- |factory_girl_rails (3.5.0) 39724 1238780
67
79
  |factory_girl_generator (0.0.3) 8015 15547
80
+ |factory_girl_rails (3.5.0) 39724 1238780
68
81
  EOS
69
82
  end
70
83
  end
@@ -79,7 +92,7 @@ describe Executor do
79
92
  end
80
93
  let(:query) { 'cucumber-' }
81
94
  it 'display rubygems ordering by name' do
82
- capture(:stdout) { @executor.search(query) }.should == <<-'EOS'.unindent
95
+ capture(:stdout) { @executor.search(query, 'name') }.should == <<-'EOS'.unindent
83
96
  |Searching ....
84
97
  |NAME DL(ver) DL(all)
85
98
  |-------------------------------------------------- -------- ---------
@@ -186,95 +199,6 @@ describe Executor do
186
199
  end
187
200
 
188
201
  private
189
- def stub_request_search(page, body)
190
- stub_request(:get, build_search_uri(query, page)).to_return(:status => 200, :body => body)
191
- end
192
-
193
- def stub_request_no_result_with_page(page)
194
- stub_request(:get, build_search_uri(query, page)).to_return(:status => 200, :body => '[]')
195
- end
196
-
197
- def build_search_uri(query, page)
198
- Executor::SEARCH_URL % [query, page]
199
- end
200
-
201
- def dummy_search_result
202
- # top 3 gems searching with 'factory_girl'
203
- # https://rubygems.org/api/v1/search.json?query=factory_girl
204
- [{"name"=>"factory_girl",
205
- "downloads"=>2042859,
206
- "version"=>"3.6.0",
207
- "version_downloads"=>541,
208
- "platform"=>"ruby",
209
- "authors"=>"Josh Clayton, Joe Ferris",
210
- "info"=>
211
- "factory_girl provides a framework and DSL for defining and\n using factories - less error-prone, more explicit, and\n all-around easier to work with than fixtures.",
212
- "project_uri"=>"http://rubygems.org/gems/factory_girl",
213
- "gem_uri"=>"http://rubygems.org/gems/factory_girl-3.6.0.gem",
214
- "homepage_uri"=>"https://github.com/thoughtbot/factory_girl",
215
- "wiki_uri"=>"",
216
- "documentation_uri"=>"",
217
- "mailing_list_uri"=>"",
218
- "source_code_uri"=>"https://github.com/thoughtbot/factory_girl",
219
- "bug_tracker_uri"=>"",
220
- "dependencies"=>
221
- {"development"=>
222
- [{"name"=>"appraisal", "requirements"=>"~> 0.4"},
223
- {"name"=>"aruba", "requirements"=>">= 0"},
224
- {"name"=>"bourne", "requirements"=>">= 0"},
225
- {"name"=>"cucumber", "requirements"=>"~> 1.1"},
226
- {"name"=>"mocha", "requirements"=>">= 0"},
227
- {"name"=>"rspec", "requirements"=>"~> 2.0"},
228
- {"name"=>"simplecov", "requirements"=>">= 0"},
229
- {"name"=>"sqlite3-ruby", "requirements"=>">= 0"},
230
- {"name"=>"timecop", "requirements"=>">= 0"},
231
- {"name"=>"yard", "requirements"=>">= 0"}],
232
- "runtime"=>[{"name"=>"activesupport", "requirements"=>">= 3.0.0"}]}},
233
- {"name"=>"factory_girl_rails",
234
- "downloads"=>1238780,
235
- "version"=>"3.5.0",
236
- "version_downloads"=>39724,
237
- "platform"=>"ruby",
238
- "authors"=>"Joe Ferris",
239
- "info"=>
240
- "factory_girl_rails provides integration between\n factory_girl and rails 3 (currently just automatic factory definition\n loading)",
241
- "project_uri"=>"http://rubygems.org/gems/factory_girl_rails",
242
- "gem_uri"=>"http://rubygems.org/gems/factory_girl_rails-3.5.0.gem",
243
- "homepage_uri"=>"http://github.com/thoughtbot/factory_girl_rails",
244
- "wiki_uri"=>nil,
245
- "documentation_uri"=>nil,
246
- "mailing_list_uri"=>nil,
247
- "source_code_uri"=>nil,
248
- "bug_tracker_uri"=>nil,
249
- "dependencies"=>
250
- {"development"=>
251
- [{"name"=>"aruba", "requirements"=>">= 0"},
252
- {"name"=>"cucumber", "requirements"=>"~> 1.0.0"},
253
- {"name"=>"rails", "requirements"=>"= 3.0.7"},
254
- {"name"=>"rake", "requirements"=>">= 0"},
255
- {"name"=>"rspec", "requirements"=>"~> 2.6.0"}],
256
- "runtime"=>
257
- [{"name"=>"factory_girl", "requirements"=>"~> 3.5.0"},
258
- {"name"=>"railties", "requirements"=>">= 3.0.0"}]}},
259
- {"name"=>"factory_girl_generator",
260
- "downloads"=>15547,
261
- "version"=>"0.0.3",
262
- "version_downloads"=>8015,
263
- "platform"=>"ruby",
264
- "authors"=>"Les Hill",
265
- "info"=>"Rails 3 generator for factory_girl",
266
- "project_uri"=>"http://rubygems.org/gems/factory_girl_generator",
267
- "gem_uri"=>"http://rubygems.org/gems/factory_girl_generator-0.0.3.gem",
268
- "homepage_uri"=>"http://github.com/leshill/factory_girl_generator",
269
- "wiki_uri"=>nil,
270
- "documentation_uri"=>nil,
271
- "mailing_list_uri"=>nil,
272
- "source_code_uri"=>nil,
273
- "bug_tracker_uri"=>nil,
274
- "dependencies"=>{"development"=>[], "runtime"=>[]}}
275
- ].to_json
276
- end
277
-
278
202
  def dummy_search_result_name_size_is_42
279
203
  [{"name"=>"size_is_42_2345678901234567890123456789012",
280
204
  "downloads"=>1000,
@@ -290,4 +214,4 @@ describe Executor do
290
214
  "version_downloads"=>200}
291
215
  ].to_json
292
216
  end
293
- end
217
+ end
@@ -25,8 +25,97 @@ def load_http_stubs(file_name)
25
25
  open(File.join(File.dirname(__FILE__), 'http_stubs', file_name)).read
26
26
  end
27
27
 
28
+ def stub_request_search(page, body)
29
+ stub_request(:get, build_search_uri(query, page)).to_return(:status => 200, :body => body)
30
+ end
31
+
32
+ def stub_request_no_result_with_page(page)
33
+ stub_request(:get, build_search_uri(query, page)).to_return(:status => 200, :body => '[]')
34
+ end
35
+
36
+ def build_search_uri(query, page)
37
+ Executor::SEARCH_URL % [query, page]
38
+ end
39
+
40
+ def dummy_search_result
41
+ # top 3 gems searching with 'factory_girl'
42
+ # https://rubygems.org/api/v1/search.json?query=factory_girl
43
+ [{"name"=>"factory_girl",
44
+ "downloads"=>2042859,
45
+ "version"=>"3.6.0",
46
+ "version_downloads"=>541,
47
+ "platform"=>"ruby",
48
+ "authors"=>"Josh Clayton, Joe Ferris",
49
+ "info"=>
50
+ "factory_girl provides a framework and DSL for defining and\n using factories - less error-prone, more explicit, and\n all-around easier to work with than fixtures.",
51
+ "project_uri"=>"http://rubygems.org/gems/factory_girl",
52
+ "gem_uri"=>"http://rubygems.org/gems/factory_girl-3.6.0.gem",
53
+ "homepage_uri"=>"https://github.com/thoughtbot/factory_girl",
54
+ "wiki_uri"=>"",
55
+ "documentation_uri"=>"",
56
+ "mailing_list_uri"=>"",
57
+ "source_code_uri"=>"https://github.com/thoughtbot/factory_girl",
58
+ "bug_tracker_uri"=>"",
59
+ "dependencies"=>
60
+ {"development"=>
61
+ [{"name"=>"appraisal", "requirements"=>"~> 0.4"},
62
+ {"name"=>"aruba", "requirements"=>">= 0"},
63
+ {"name"=>"bourne", "requirements"=>">= 0"},
64
+ {"name"=>"cucumber", "requirements"=>"~> 1.1"},
65
+ {"name"=>"mocha", "requirements"=>">= 0"},
66
+ {"name"=>"rspec", "requirements"=>"~> 2.0"},
67
+ {"name"=>"simplecov", "requirements"=>">= 0"},
68
+ {"name"=>"sqlite3-ruby", "requirements"=>">= 0"},
69
+ {"name"=>"timecop", "requirements"=>">= 0"},
70
+ {"name"=>"yard", "requirements"=>">= 0"}],
71
+ "runtime"=>[{"name"=>"activesupport", "requirements"=>">= 3.0.0"}]}},
72
+ {"name"=>"factory_girl_rails",
73
+ "downloads"=>1238780,
74
+ "version"=>"3.5.0",
75
+ "version_downloads"=>39724,
76
+ "platform"=>"ruby",
77
+ "authors"=>"Joe Ferris",
78
+ "info"=>
79
+ "factory_girl_rails provides integration between\n factory_girl and rails 3 (currently just automatic factory definition\n loading)",
80
+ "project_uri"=>"http://rubygems.org/gems/factory_girl_rails",
81
+ "gem_uri"=>"http://rubygems.org/gems/factory_girl_rails-3.5.0.gem",
82
+ "homepage_uri"=>"http://github.com/thoughtbot/factory_girl_rails",
83
+ "wiki_uri"=>nil,
84
+ "documentation_uri"=>nil,
85
+ "mailing_list_uri"=>nil,
86
+ "source_code_uri"=>nil,
87
+ "bug_tracker_uri"=>nil,
88
+ "dependencies"=>
89
+ {"development"=>
90
+ [{"name"=>"aruba", "requirements"=>">= 0"},
91
+ {"name"=>"cucumber", "requirements"=>"~> 1.0.0"},
92
+ {"name"=>"rails", "requirements"=>"= 3.0.7"},
93
+ {"name"=>"rake", "requirements"=>">= 0"},
94
+ {"name"=>"rspec", "requirements"=>"~> 2.6.0"}],
95
+ "runtime"=>
96
+ [{"name"=>"factory_girl", "requirements"=>"~> 3.5.0"},
97
+ {"name"=>"railties", "requirements"=>">= 3.0.0"}]}},
98
+ {"name"=>"factory_girl_generator",
99
+ "downloads"=>15547,
100
+ "version"=>"0.0.3",
101
+ "version_downloads"=>8015,
102
+ "platform"=>"ruby",
103
+ "authors"=>"Les Hill",
104
+ "info"=>"Rails 3 generator for factory_girl",
105
+ "project_uri"=>"http://rubygems.org/gems/factory_girl_generator",
106
+ "gem_uri"=>"http://rubygems.org/gems/factory_girl_generator-0.0.3.gem",
107
+ "homepage_uri"=>"http://github.com/leshill/factory_girl_generator",
108
+ "wiki_uri"=>nil,
109
+ "documentation_uri"=>nil,
110
+ "mailing_list_uri"=>nil,
111
+ "source_code_uri"=>nil,
112
+ "bug_tracker_uri"=>nil,
113
+ "dependencies"=>{"development"=>[], "runtime"=>[]}}
114
+ ].to_json
115
+ end
116
+
28
117
  class String
29
118
  def unindent
30
119
  gsub(/^\s+\|/, '')
31
120
  end
32
- end
121
+ end
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - rochefort
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-22 00:00:00.000000000 Z
11
+ date: 2014-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop
@@ -104,6 +104,7 @@ extra_rdoc_files: []
104
104
  files:
105
105
  - ".gitignore"
106
106
  - ".rspec"
107
+ - CHANGELOG.md
107
108
  - Gemfile
108
109
  - LICENSE
109
110
  - README.md
@@ -116,6 +117,7 @@ files:
116
117
  - lib/gem-search/rendering.rb
117
118
  - lib/gem-search/version.rb
118
119
  - spec/bin/gem-search_spec.rb
120
+ - spec/command_spec.rb
119
121
  - spec/executor_spec.rb
120
122
  - spec/http_stubs/cucumber-_1.json
121
123
  - spec/http_stubs/cucumber-_2.json
@@ -146,6 +148,7 @@ specification_version: 4
146
148
  summary: search gems with using rubygems.org API
147
149
  test_files:
148
150
  - spec/bin/gem-search_spec.rb
151
+ - spec/command_spec.rb
149
152
  - spec/executor_spec.rb
150
153
  - spec/http_stubs/cucumber-_1.json
151
154
  - spec/http_stubs/cucumber-_2.json