gem-search 0.1.9 → 0.2.0
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 +4 -4
- data/.rubocop.yml +17 -0
- data/CHANGELOG.md +7 -2
- data/Gemfile +2 -2
- data/README.md +2 -3
- data/Rakefile +1 -1
- data/lib/gem_search.rb +2 -2
- data/lib/gem_search/command_builder.rb +1 -1
- data/lib/gem_search/commands/base.rb +14 -0
- data/lib/gem_search/commands/browse.rb +23 -7
- data/lib/gem_search/commands/run.rb +35 -23
- data/lib/gem_search/rendering.rb +0 -4
- data/lib/gem_search/request.rb +50 -0
- data/lib/gem_search/utils/system_util.rb +1 -1
- data/lib/gem_search/version.rb +1 -1
- data/spec/commands/browse_spec.rb +38 -3
- data/spec/commands/run_spec.rb +147 -34
- data/spec/helpers.rb +7 -0
- data/spec/helpers/dummy_data.rb +203 -0
- data/spec/request_spec.rb +6 -0
- data/spec/spec_helper.rb +6 -85
- metadata +10 -5
- data/lib/gem_search/executor.rb +0 -79
- data/spec/executor_spec.rb +0 -289
data/spec/helpers.rb
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
# rubocop:disable all
|
2
|
+
module Dummy_data
|
3
|
+
private
|
4
|
+
|
5
|
+
def dummy_search_result_sorted_by_all
|
6
|
+
<<-'EOS'.unindent
|
7
|
+
|Searching .
|
8
|
+
|NAME DL(ver) DL(all) HOMEPAGE
|
9
|
+
|-------------------------------------------------- -------- --------- ------------------------------------------------------------
|
10
|
+
|factory_girl (3.6.0) 541 2042859 https://github.com/thoughtbot/factory_girl
|
11
|
+
|factory_girl_rails (3.5.0) 39724 1238780 http://github.com/thoughtbot/factory_girl_rails
|
12
|
+
|factory_girl_generator (0.0.3) 8015 15547 http://github.com/leshill/factory_girl_generator
|
13
|
+
EOS
|
14
|
+
end
|
15
|
+
|
16
|
+
def dummy_search_result_sorted_by_ver
|
17
|
+
<<-'EOS'.unindent
|
18
|
+
|Searching .
|
19
|
+
|NAME DL(ver) DL(all) HOMEPAGE
|
20
|
+
|-------------------------------------------------- -------- --------- ------------------------------------------------------------
|
21
|
+
|factory_girl_rails (3.5.0) 39724 1238780 http://github.com/thoughtbot/factory_girl_rails
|
22
|
+
|factory_girl_generator (0.0.3) 8015 15547 http://github.com/leshill/factory_girl_generator
|
23
|
+
|factory_girl (3.6.0) 541 2042859 https://github.com/thoughtbot/factory_girl
|
24
|
+
EOS
|
25
|
+
end
|
26
|
+
|
27
|
+
def dummy_search_result_sorted_by_name
|
28
|
+
<<-'EOS'.unindent
|
29
|
+
|Searching .
|
30
|
+
|NAME DL(ver) DL(all) HOMEPAGE
|
31
|
+
|-------------------------------------------------- -------- --------- ------------------------------------------------------------
|
32
|
+
|factory_girl (3.6.0) 541 2042859 https://github.com/thoughtbot/factory_girl
|
33
|
+
|factory_girl_generator (0.0.3) 8015 15547 http://github.com/leshill/factory_girl_generator
|
34
|
+
|factory_girl_rails (3.5.0) 39724 1238780 http://github.com/thoughtbot/factory_girl_rails
|
35
|
+
EOS
|
36
|
+
end
|
37
|
+
|
38
|
+
def dummy_search_results_multiple_pages
|
39
|
+
<<-'EOS'.unindent
|
40
|
+
|Searching ...
|
41
|
+
|NAME DL(ver) DL(all) HOMEPAGE
|
42
|
+
|-------------------------------------------------- -------- --------- ------------------------------------------------------------
|
43
|
+
|autotest-cucumber-notification (0.0.6) 1027 3607 https://github.com/evrone/autotest-cucumber-notification
|
44
|
+
|calabash-cucumber-cn (0.0.6) 88 88 http://github.com/cpunion/calabash-cucumber-cn
|
45
|
+
|cucumber-ajaxer (0.0.4) 1875 4966 http://github.com/chalofa/cucumber-ajaxer
|
46
|
+
|cucumber-api-steps (0.13) 1783 36587 http://github.com/jayzes/cucumber-api-steps
|
47
|
+
|cucumber-blanket (0.3.0) 324 1674 https://github.com/keyvanfatehi/cucumber-blanket
|
48
|
+
|cucumber-cafe (0.0.1) 295 295
|
49
|
+
|cucumber-chef (3.0.8) 1545 28881 http://www.cucumber-chef.org
|
50
|
+
|cucumber-cinema (0.8.0) 1309 9294 http://github.com/ilyakatz/cucumber-cinema
|
51
|
+
|cucumber-core (0.2.0) 316 683 http://cukes.info
|
52
|
+
|cucumber-core (0.2.0) 316 683 http://cukes.info
|
53
|
+
|cucumber-debug (0.0.1) 1702 1702
|
54
|
+
|cucumber-en_snippet (0.0.2) 295 565 https://github.com/mtsmfm/cucumber-en_snippet
|
55
|
+
|cucumber-farmer (1.0.3) 1573 4398 http://github.com/mattscilipoti/cucumber-farmer
|
56
|
+
|cucumber-formatter-oneline (0.1.0) 413 413
|
57
|
+
|cucumber-in-the-yard (1.7.8) 2107 33260 http://github.com/burtlo/Cucumber-In-The-Yard
|
58
|
+
|cucumber-java (0.0.2) 2113 3656 http://cukes.info
|
59
|
+
|cucumber-jira (0.0.1.beta) 166 166 https://github.com/ipwnstuff/cucumber-jira
|
60
|
+
|cucumber-json (0.0.2) 2199 3697 http://github.com/jnewland/cucumber-json
|
61
|
+
|cucumber-jvm (1.1.6) 204 20913 http://github.com/cucumber/cucumber-jvm
|
62
|
+
|cucumber-loggly (0.3.1) 903 4869 https://github.com/brettweavnet/cucumber-loggly
|
63
|
+
|cucumber-mingle (1.0.0) 1539 1539
|
64
|
+
|cucumber-nagios (0.9.2) 27094 75277 http://cucumber-nagios.org/
|
65
|
+
|cucumber-nc (0.0.2) 162 1362 https://github.com/MrJoy/cucumber-nc
|
66
|
+
|cucumber-newrelic (0.0.2) 1694 3201 http://github.com/jnewland/cucumber-newrelic
|
67
|
+
|cucumber-notify (0.0.5) 1168 3348 https://github.com/argent-smith/autotest-cucumber-notification/tree/deprecated
|
68
|
+
|cucumber-openerpscenario (0.1.9.1) 1110 11064
|
69
|
+
|cucumber-peel (0.0.1) 1000 1000 https://github.com/testdouble/cucumber-peel
|
70
|
+
|cucumber-pride (0.0.2) 1272 2321 https://github.com/pvdb/cucumber-pride
|
71
|
+
|cucumber-profiler (1.0.0) 1171 1171 https://github.com/mblum14/cucumber-profiler
|
72
|
+
|cucumber-puppet (0.3.7) 2974 24374 http://projects.puppetlabs.com/projects/cucumber-puppet
|
73
|
+
|cucumber-rails (1.4.0) 286328 2700475 http://cukes.info
|
74
|
+
|cucumber-rails-training-wheels (1.0.0) 109001 109001 http://cukes.info
|
75
|
+
|cucumber-rails2 (0.3.5) 10776 13172 https://github.com/Vanuan/cucumber-rails
|
76
|
+
|cucumber-rapid7 (0.0.1.beta.1) 101 430 https://github.com/ecarey-r7/cucumber-rapid7
|
77
|
+
|cucumber-rapid7 (0.0.1.beta.1) 101 430 https://github.com/ecarey-r7/cucumber-rapid7
|
78
|
+
|cucumber-relizy (0.0.2) 1433 2502 https://github.com/wynst/cucumber-relizy
|
79
|
+
|cucumber-salad (0.4.0) 488 5326 https://github.com/mojotech/cucumber-salad
|
80
|
+
|cucumber-salad (0.4.0) 488 5326 https://github.com/mojotech/cucumber-salad
|
81
|
+
|cucumber-scout (0.0.2) 1634 3124 http://github.com/jnewland/cucumber-scout
|
82
|
+
|cucumber-screenshot (0.3.4) 2241 15704 http://github.com/mocoso/cucumber-screenshot
|
83
|
+
|cucumber-selenium-standalone (0.0.3) 1322 3593 http://github.com/techwhizbang/cucumber-selenium-standalone
|
84
|
+
|cucumber-sinatra (0.5.0) 8463 28042 http://github.com/bernd/cucumber-sinatra
|
85
|
+
|cucumber-slice (0.0.2) 629 1199 https://github.com/testdouble/cucumber-slice
|
86
|
+
|cucumber-slices (0.0.4) 172 649 http://github.com/psytau/cucumber-slices
|
87
|
+
|cucumber-sshd (0.1.0) 152 152 https://rubygems.org/gems/cucumber-sshd
|
88
|
+
|cucumber-standalone (0.0.1) 1665 1665 http://github.com/jnewland/cucumber-standalone
|
89
|
+
|cucumber-step_writer (0.1.2) 1251 3229
|
90
|
+
|cucumber-table (0.0.1) 527 527
|
91
|
+
|cucumber-the (1.0.0) 1209 1209
|
92
|
+
|cucumber-timecop (0.0.3) 445 820 https://github.com/zedtux/cucumber-timecop
|
93
|
+
|cucumber-timed_formatter (0.1.1) 1066 2165 http://github.com/kronn/cucumber-timed_formatter
|
94
|
+
|cucumber-to-rally (0.1.3) 1001 3894
|
95
|
+
|cucumber-usual_suspects (0.0.1) 1378 1378 http://github.com/mattwynne/cucumber-usual_suspects
|
96
|
+
|cucumber-value (0.0.1) 1233 1233 https://github.com/hatofmonkeys/cucumber-value
|
97
|
+
|cucumber-vimscript (0.0.3) 1097 3316 http://github.com/AndrewRadev/cucumber-vimscript
|
98
|
+
|cucumber-voip (0.1.0) 1244 1244 https://github.com/benlangfeld/cucumber-voip
|
99
|
+
|cucumber-websteps (0.10.0) 18583 22129 http://relishapp.com/kucaahbe/cucumber-websteps
|
100
|
+
|cucumber-wordpress (1.3.1) 1346 7458 http://github.com/dxw/cucumber-wordpress
|
101
|
+
|guard-cucumber-js (0.0.2) 1039 1935
|
102
|
+
|mattscilipoti-cucumber-rails (0.2.4.2) 1394 3989 http://github.com/aslakhellesoy/cucumber-rails
|
103
|
+
|mattscilipoti_cucumber-rails (0.2.4) 1401 1401 http://github.com/aslakhellesoy/cucumber-rails
|
104
|
+
|tasty-cucumber-client (0.1.10) 1504 11518 http://tasty-cucumber.com
|
105
|
+
|vagrant-cucumber-host (0.1.14) 163 163
|
106
|
+
EOS
|
107
|
+
end
|
108
|
+
|
109
|
+
def dummy_search_result_name_size_is_42
|
110
|
+
[{
|
111
|
+
'name' => 'size_is_42_2345678901234567890123456789012',
|
112
|
+
'downloads' => 1000,
|
113
|
+
'version' => '0.0.1',
|
114
|
+
'version_downloads' => 100
|
115
|
+
}].to_json
|
116
|
+
end
|
117
|
+
|
118
|
+
def dummy_search_result_name_size_is_43
|
119
|
+
[{
|
120
|
+
'name' => 'size_is_43_23456789012345678901234567890123',
|
121
|
+
'downloads' => 2000,
|
122
|
+
'version' => '0.0.2',
|
123
|
+
'version_downloads' => 200
|
124
|
+
}].to_json
|
125
|
+
end
|
126
|
+
|
127
|
+
def dummy_search_result
|
128
|
+
# top 3 gems searching with 'factory_girl'
|
129
|
+
# https://rubygems.org/api/v1/search.json?query=factory_girl
|
130
|
+
[{"name"=>"factory_girl",
|
131
|
+
"downloads"=>2042859,
|
132
|
+
"version"=>"3.6.0",
|
133
|
+
"version_downloads"=>541,
|
134
|
+
"platform"=>"ruby",
|
135
|
+
"authors"=>"Josh Clayton, Joe Ferris",
|
136
|
+
"info"=>
|
137
|
+
"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.",
|
138
|
+
"project_uri"=>"http://rubygems.org/gems/factory_girl",
|
139
|
+
"gem_uri"=>"http://rubygems.org/gems/factory_girl-3.6.0.gem",
|
140
|
+
"homepage_uri"=>"https://github.com/thoughtbot/factory_girl",
|
141
|
+
"wiki_uri"=>"",
|
142
|
+
"documentation_uri"=>"",
|
143
|
+
"mailing_list_uri"=>"",
|
144
|
+
"source_code_uri"=>"https://github.com/thoughtbot/factory_girl",
|
145
|
+
"bug_tracker_uri"=>"",
|
146
|
+
"dependencies"=>
|
147
|
+
{"development"=>
|
148
|
+
[{"name"=>"appraisal", "requirements"=>"~> 0.4"},
|
149
|
+
{"name"=>"aruba", "requirements"=>">= 0"},
|
150
|
+
{"name"=>"bourne", "requirements"=>">= 0"},
|
151
|
+
{"name"=>"cucumber", "requirements"=>"~> 1.1"},
|
152
|
+
{"name"=>"mocha", "requirements"=>">= 0"},
|
153
|
+
{"name"=>"rspec", "requirements"=>"~> 2.0"},
|
154
|
+
{"name"=>"simplecov", "requirements"=>">= 0"},
|
155
|
+
{"name"=>"sqlite3-ruby", "requirements"=>">= 0"},
|
156
|
+
{"name"=>"timecop", "requirements"=>">= 0"},
|
157
|
+
{"name"=>"yard", "requirements"=>">= 0"}],
|
158
|
+
"runtime"=>[{"name"=>"activesupport", "requirements"=>">= 3.0.0"}]}},
|
159
|
+
{"name"=>"factory_girl_rails",
|
160
|
+
"downloads"=>1238780,
|
161
|
+
"version"=>"3.5.0",
|
162
|
+
"version_downloads"=>39724,
|
163
|
+
"platform"=>"ruby",
|
164
|
+
"authors"=>"Joe Ferris",
|
165
|
+
"info"=>
|
166
|
+
"factory_girl_rails provides integration between\n factory_girl and rails 3 (currently just automatic factory definition\n loading)",
|
167
|
+
"project_uri"=>"http://rubygems.org/gems/factory_girl_rails",
|
168
|
+
"gem_uri"=>"http://rubygems.org/gems/factory_girl_rails-3.5.0.gem",
|
169
|
+
"homepage_uri"=>"http://github.com/thoughtbot/factory_girl_rails",
|
170
|
+
"wiki_uri"=>nil,
|
171
|
+
"documentation_uri"=>nil,
|
172
|
+
"mailing_list_uri"=>nil,
|
173
|
+
"source_code_uri"=>nil,
|
174
|
+
"bug_tracker_uri"=>nil,
|
175
|
+
"dependencies"=>
|
176
|
+
{"development"=>
|
177
|
+
[{"name"=>"aruba", "requirements"=>">= 0"},
|
178
|
+
{"name"=>"cucumber", "requirements"=>"~> 1.0.0"},
|
179
|
+
{"name"=>"rails", "requirements"=>"= 3.0.7"},
|
180
|
+
{"name"=>"rake", "requirements"=>">= 0"},
|
181
|
+
{"name"=>"rspec", "requirements"=>"~> 2.6.0"}],
|
182
|
+
"runtime"=>
|
183
|
+
[{"name"=>"factory_girl", "requirements"=>"~> 3.5.0"},
|
184
|
+
{"name"=>"railties", "requirements"=>">= 3.0.0"}]}},
|
185
|
+
{"name"=>"factory_girl_generator",
|
186
|
+
"downloads"=>15547,
|
187
|
+
"version"=>"0.0.3",
|
188
|
+
"version_downloads"=>8015,
|
189
|
+
"platform"=>"ruby",
|
190
|
+
"authors"=>"Les Hill",
|
191
|
+
"info"=>"Rails 3 generator for factory_girl",
|
192
|
+
"project_uri"=>"http://rubygems.org/gems/factory_girl_generator",
|
193
|
+
"gem_uri"=>"http://rubygems.org/gems/factory_girl_generator-0.0.3.gem",
|
194
|
+
"homepage_uri"=>"http://github.com/leshill/factory_girl_generator",
|
195
|
+
"wiki_uri"=>nil,
|
196
|
+
"documentation_uri"=>nil,
|
197
|
+
"mailing_list_uri"=>nil,
|
198
|
+
"source_code_uri"=>nil,
|
199
|
+
"bug_tracker_uri"=>nil,
|
200
|
+
"dependencies"=>{"development"=>[], "runtime"=>[]}}
|
201
|
+
].to_json
|
202
|
+
end
|
203
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,7 +7,11 @@ require 'webmock/rspec'
|
|
7
7
|
# require 'pry'
|
8
8
|
require 'gem_search'
|
9
9
|
|
10
|
+
require 'helpers'
|
11
|
+
|
10
12
|
RSpec.configure do |config|
|
13
|
+
config.include Helpers
|
14
|
+
|
11
15
|
config.expect_with :rspec do |expectations|
|
12
16
|
expectations.syntax = :expect
|
13
17
|
end
|
@@ -39,7 +43,7 @@ def stub_request_search_no_result_with_page(query, page)
|
|
39
43
|
end
|
40
44
|
|
41
45
|
def build_search_uri(query, page)
|
42
|
-
|
46
|
+
Request::SEARCH_API % [query, page]
|
43
47
|
end
|
44
48
|
|
45
49
|
# stubs for gems API
|
@@ -52,90 +56,7 @@ def stub_request_gems_no_result(query)
|
|
52
56
|
end
|
53
57
|
|
54
58
|
def build_gems_uri(query)
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
def dummy_search_result
|
59
|
-
# top 3 gems searching with 'factory_girl'
|
60
|
-
# https://rubygems.org/api/v1/search.json?query=factory_girl
|
61
|
-
[{"name"=>"factory_girl",
|
62
|
-
"downloads"=>2042859,
|
63
|
-
"version"=>"3.6.0",
|
64
|
-
"version_downloads"=>541,
|
65
|
-
"platform"=>"ruby",
|
66
|
-
"authors"=>"Josh Clayton, Joe Ferris",
|
67
|
-
"info"=>
|
68
|
-
"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.",
|
69
|
-
"project_uri"=>"http://rubygems.org/gems/factory_girl",
|
70
|
-
"gem_uri"=>"http://rubygems.org/gems/factory_girl-3.6.0.gem",
|
71
|
-
"homepage_uri"=>"https://github.com/thoughtbot/factory_girl",
|
72
|
-
"wiki_uri"=>"",
|
73
|
-
"documentation_uri"=>"",
|
74
|
-
"mailing_list_uri"=>"",
|
75
|
-
"source_code_uri"=>"https://github.com/thoughtbot/factory_girl",
|
76
|
-
"bug_tracker_uri"=>"",
|
77
|
-
"dependencies"=>
|
78
|
-
{"development"=>
|
79
|
-
[{"name"=>"appraisal", "requirements"=>"~> 0.4"},
|
80
|
-
{"name"=>"aruba", "requirements"=>">= 0"},
|
81
|
-
{"name"=>"bourne", "requirements"=>">= 0"},
|
82
|
-
{"name"=>"cucumber", "requirements"=>"~> 1.1"},
|
83
|
-
{"name"=>"mocha", "requirements"=>">= 0"},
|
84
|
-
{"name"=>"rspec", "requirements"=>"~> 2.0"},
|
85
|
-
{"name"=>"simplecov", "requirements"=>">= 0"},
|
86
|
-
{"name"=>"sqlite3-ruby", "requirements"=>">= 0"},
|
87
|
-
{"name"=>"timecop", "requirements"=>">= 0"},
|
88
|
-
{"name"=>"yard", "requirements"=>">= 0"}],
|
89
|
-
"runtime"=>[{"name"=>"activesupport", "requirements"=>">= 3.0.0"}]}},
|
90
|
-
{"name"=>"factory_girl_rails",
|
91
|
-
"downloads"=>1238780,
|
92
|
-
"version"=>"3.5.0",
|
93
|
-
"version_downloads"=>39724,
|
94
|
-
"platform"=>"ruby",
|
95
|
-
"authors"=>"Joe Ferris",
|
96
|
-
"info"=>
|
97
|
-
"factory_girl_rails provides integration between\n factory_girl and rails 3 (currently just automatic factory definition\n loading)",
|
98
|
-
"project_uri"=>"http://rubygems.org/gems/factory_girl_rails",
|
99
|
-
"gem_uri"=>"http://rubygems.org/gems/factory_girl_rails-3.5.0.gem",
|
100
|
-
"homepage_uri"=>"http://github.com/thoughtbot/factory_girl_rails",
|
101
|
-
"wiki_uri"=>nil,
|
102
|
-
"documentation_uri"=>nil,
|
103
|
-
"mailing_list_uri"=>nil,
|
104
|
-
"source_code_uri"=>nil,
|
105
|
-
"bug_tracker_uri"=>nil,
|
106
|
-
"dependencies"=>
|
107
|
-
{"development"=>
|
108
|
-
[{"name"=>"aruba", "requirements"=>">= 0"},
|
109
|
-
{"name"=>"cucumber", "requirements"=>"~> 1.0.0"},
|
110
|
-
{"name"=>"rails", "requirements"=>"= 3.0.7"},
|
111
|
-
{"name"=>"rake", "requirements"=>">= 0"},
|
112
|
-
{"name"=>"rspec", "requirements"=>"~> 2.6.0"}],
|
113
|
-
"runtime"=>
|
114
|
-
[{"name"=>"factory_girl", "requirements"=>"~> 3.5.0"},
|
115
|
-
{"name"=>"railties", "requirements"=>">= 3.0.0"}]}},
|
116
|
-
{"name"=>"factory_girl_generator",
|
117
|
-
"downloads"=>15547,
|
118
|
-
"version"=>"0.0.3",
|
119
|
-
"version_downloads"=>8015,
|
120
|
-
"platform"=>"ruby",
|
121
|
-
"authors"=>"Les Hill",
|
122
|
-
"info"=>"Rails 3 generator for factory_girl",
|
123
|
-
"project_uri"=>"http://rubygems.org/gems/factory_girl_generator",
|
124
|
-
"gem_uri"=>"http://rubygems.org/gems/factory_girl_generator-0.0.3.gem",
|
125
|
-
"homepage_uri"=>"http://github.com/leshill/factory_girl_generator",
|
126
|
-
"wiki_uri"=>nil,
|
127
|
-
"documentation_uri"=>nil,
|
128
|
-
"mailing_list_uri"=>nil,
|
129
|
-
"source_code_uri"=>nil,
|
130
|
-
"bug_tracker_uri"=>nil,
|
131
|
-
"dependencies"=>{"development"=>[], "runtime"=>[]}}
|
132
|
-
].to_json
|
133
|
-
end
|
134
|
-
|
135
|
-
def default_opts(merge_opts = nil)
|
136
|
-
opts = { sort: 'downloads', has_homepage: true }
|
137
|
-
opts.merge!(merge_opts) if merge_opts
|
138
|
-
opts
|
59
|
+
Request::GEM_API % query
|
139
60
|
end
|
140
61
|
|
141
62
|
class String
|
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.
|
4
|
+
version: 0.2.0
|
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
|
+
date: 2016-02-16 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
|
+
- ".rubocop.yml"
|
107
108
|
- CHANGELOG.md
|
108
109
|
- Gemfile
|
109
110
|
- LICENSE
|
@@ -120,20 +121,22 @@ files:
|
|
120
121
|
- lib/gem_search/commands/help.rb
|
121
122
|
- lib/gem_search/commands/run.rb
|
122
123
|
- lib/gem_search/commands/version.rb
|
123
|
-
- lib/gem_search/executor.rb
|
124
124
|
- lib/gem_search/rendering.rb
|
125
|
+
- lib/gem_search/request.rb
|
125
126
|
- lib/gem_search/utils/system_util.rb
|
126
127
|
- lib/gem_search/version.rb
|
127
128
|
- sideci_build.txt
|
128
129
|
- spec/bin/gem_search_spec.rb
|
129
130
|
- spec/commands/browse_spec.rb
|
130
131
|
- spec/commands/run_spec.rb
|
131
|
-
- spec/
|
132
|
+
- spec/helpers.rb
|
133
|
+
- spec/helpers/dummy_data.rb
|
132
134
|
- spec/http_stubs/gems/git-trend.json
|
133
135
|
- spec/http_stubs/gems/git-trend_no_homepage.json
|
134
136
|
- spec/http_stubs/search/cucumber-_1.json
|
135
137
|
- spec/http_stubs/search/cucumber-_2.json
|
136
138
|
- spec/http_stubs/search/cucumber-_3.json
|
139
|
+
- spec/request_spec.rb
|
137
140
|
- spec/spec_helper.rb
|
138
141
|
homepage: https://github.com/rochefort/gem-search
|
139
142
|
licenses: []
|
@@ -162,10 +165,12 @@ test_files:
|
|
162
165
|
- spec/bin/gem_search_spec.rb
|
163
166
|
- spec/commands/browse_spec.rb
|
164
167
|
- spec/commands/run_spec.rb
|
165
|
-
- spec/
|
168
|
+
- spec/helpers.rb
|
169
|
+
- spec/helpers/dummy_data.rb
|
166
170
|
- spec/http_stubs/gems/git-trend.json
|
167
171
|
- spec/http_stubs/gems/git-trend_no_homepage.json
|
168
172
|
- spec/http_stubs/search/cucumber-_1.json
|
169
173
|
- spec/http_stubs/search/cucumber-_2.json
|
170
174
|
- spec/http_stubs/search/cucumber-_3.json
|
175
|
+
- spec/request_spec.rb
|
171
176
|
- spec/spec_helper.rb
|
data/lib/gem_search/executor.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'open-uri'
|
3
|
-
require 'gem_search/rendering'
|
4
|
-
require 'gem_search/utils/system_util'
|
5
|
-
|
6
|
-
module GemSearch
|
7
|
-
class Executor
|
8
|
-
include Rendering
|
9
|
-
include Utils::SystemUtil
|
10
|
-
BASE_URL = 'https://rubygems.org'
|
11
|
-
SEARCH_API = "#{BASE_URL}/api/v1/search.json?query=%s&page=%d"
|
12
|
-
GEM_API = "#{BASE_URL}/api/v1/gems/%s.json"
|
13
|
-
GEM_URL = "#{BASE_URL}/gems/%s"
|
14
|
-
|
15
|
-
MAX_REQUEST_COUNT = 20
|
16
|
-
MAX_GEMS_PER_PAGE = 30 # It has been determined by Github API
|
17
|
-
|
18
|
-
def search(query, opts)
|
19
|
-
return unless query
|
20
|
-
print 'Searching '
|
21
|
-
gems = search_gems(query)
|
22
|
-
puts
|
23
|
-
fail GemSearch::LibraryNotFound, 'We did not find results.' if gems.size.zero?
|
24
|
-
gems_sort!(gems, opts[:sort])
|
25
|
-
Executor.render(gems, opts[:has_homepage])
|
26
|
-
end
|
27
|
-
|
28
|
-
def browse(gem)
|
29
|
-
return unless gem
|
30
|
-
api_url = GEM_API % gem
|
31
|
-
result = request_ruby_gems_api(api_url)
|
32
|
-
url = result['homepage_uri']
|
33
|
-
if url.nil? || url.empty?
|
34
|
-
url = GEM_URL % gem
|
35
|
-
end
|
36
|
-
puts "Opening #{url}"
|
37
|
-
browser_open(url)
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
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
|
52
|
-
end
|
53
|
-
|
54
|
-
def search_ended?(size)
|
55
|
-
size < MAX_GEMS_PER_PAGE || size.zero?
|
56
|
-
end
|
57
|
-
|
58
|
-
def request_ruby_gems_api(url)
|
59
|
-
option = {}
|
60
|
-
proxy = URI.parse(url).find_proxy
|
61
|
-
if proxy
|
62
|
-
if proxy.user && proxy.password
|
63
|
-
option[:proxy_http_basic_authentication] = [proxy, proxy.user, proxy.password]
|
64
|
-
else
|
65
|
-
option[:proxy] = proxy
|
66
|
-
end
|
67
|
-
end
|
68
|
-
JSON.parse(open(url, option).read)
|
69
|
-
end
|
70
|
-
|
71
|
-
def gems_sort!(gems, opt_sort)
|
72
|
-
if opt_sort == 'name'
|
73
|
-
gems.sort! { |x, y| x[opt_sort] <=> y[opt_sort] }
|
74
|
-
else
|
75
|
-
gems.sort! { |x, y| y[opt_sort] <=> x[opt_sort] }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|