gem-search 0.1.4 → 0.1.5
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/CHANGELOG.md +6 -1
- data/README.md +5 -1
- data/bin/gem-search +1 -1
- data/gem-search.gemspec +3 -2
- data/lib/gem_search.rb +11 -8
- data/lib/gem_search/command_builder.rb +52 -0
- data/lib/gem_search/commands.rb +9 -0
- data/lib/gem_search/commands/base.rb +11 -0
- data/lib/gem_search/commands/browse.rb +17 -0
- data/lib/gem_search/commands/help.rb +9 -0
- data/lib/gem_search/commands/run.rb +43 -0
- data/lib/gem_search/commands/version.rb +9 -0
- data/lib/gem_search/executor.rb +2 -1
- data/lib/gem_search/version.rb +1 -1
- data/spec/bin/gem_search_spec.rb +10 -15
- data/spec/commands/browse_spec.rb +22 -0
- data/spec/{command_spec.rb → commands/run_spec.rb} +12 -13
- metadata +33 -11
- data/lib/gem_search/command.rb +0 -91
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 007f61dd3c35fc00a951fd431c22ddc81b6a5d97
|
4
|
+
data.tar.gz: c6251305ba1722f85da3c9ef7174755bbc39e765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fccfe3e6be4a304b2cef71d4c878522047d27e658a9a55c0efe04764392c1baa57467ff78c656e5d2deccc426e84408a11b21a612cfabc2fa38521b28df461e
|
7
|
+
data.tar.gz: 0c6546b3481356f6458571b7e014262bdd7fc5555ac3ae6050c610745ed8b06a47796cf5cd97df07d3fb1bf0b9e6d5e2671b0cf368697f1fd4ab9204e0e35eb7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -118,7 +118,11 @@ node-webkit-bootstrap (1.0.0) 226 226 https://gi
|
|
118
118
|
### Browse
|
119
119
|
It open rubygem's homepage in the system's default web browser.
|
120
120
|
|
121
|
-
|
121
|
+
gem-search -b `keyword'
|
122
|
+
|
123
|
+
or
|
124
|
+
|
125
|
+
gem-search --browse `keyword'
|
122
126
|
|
123
127
|
|
124
128
|
|
data/bin/gem-search
CHANGED
data/gem-search.gemspec
CHANGED
@@ -30,8 +30,9 @@ Gem::Specification.new do |gem|
|
|
30
30
|
|
31
31
|
gem.post_install_message = install_message
|
32
32
|
|
33
|
-
gem.add_dependency 'slop', '~>
|
34
|
-
gem.add_dependency 'json', '~>1.8.
|
33
|
+
gem.add_dependency 'slop', '~>4.0.0'
|
34
|
+
gem.add_dependency 'json', '~>1.8.2'
|
35
|
+
gem.add_dependency 'mem', '~>0.1.5'
|
35
36
|
|
36
37
|
# gem.add_development_dependency 'pry', '~>0.9.12.6'
|
37
38
|
gem.add_development_dependency 'webmock', '~>1.18.0'
|
data/lib/gem_search.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
module Gem
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module Gem::Search
|
2
|
+
require 'mem'
|
3
|
+
require 'slop'
|
4
|
+
|
5
|
+
class LibraryNotFound < StandardError; end
|
6
|
+
|
7
|
+
require 'gem_search/command_builder'
|
8
|
+
require 'gem_search/commands'
|
9
|
+
require 'gem_search/version'
|
10
|
+
require 'gem_search/rendering'
|
11
|
+
require 'gem_search/executor'
|
9
12
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Gem::Search
|
2
|
+
class CommandBuilder
|
3
|
+
include Mem
|
4
|
+
|
5
|
+
attr_reader :arguments
|
6
|
+
|
7
|
+
def initialize(arguments = ARGV)
|
8
|
+
@arguments = arguments
|
9
|
+
end
|
10
|
+
|
11
|
+
def build
|
12
|
+
command_class.new(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def command_class
|
18
|
+
case
|
19
|
+
when options[:help] then Commands::Help
|
20
|
+
when options[:version] then Commands::Version
|
21
|
+
when options[:browse] then Commands::Browse
|
22
|
+
else Commands::Run
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def options
|
27
|
+
Slop.parse(arguments, suppress_errors: true) do |opts|
|
28
|
+
opts.banner = "Usage: gem-search gem_name [options]\n"
|
29
|
+
sort_msg = detail_message([
|
30
|
+
'Sort by the field.',
|
31
|
+
'default [a]ll',
|
32
|
+
'[a]ll :DL(all) e.g.: gem-search webkit -s a',
|
33
|
+
'[v]er :DL(ver) e.g.: gem-search webkit -s v',
|
34
|
+
'[n]ame : e.g.: gem-search webkit -s n',
|
35
|
+
])
|
36
|
+
opts.string('-s', '--sort', sort_msg)
|
37
|
+
opts.string('-b', '--browse', "Open rubygem's homepage in the system's default web browser.")
|
38
|
+
opts.on('-d', '--detail', "Display rubygems's homepage url.")
|
39
|
+
opts.on('-v', '--version', 'Display the version.')
|
40
|
+
opts.on('-h', '--help', 'Display this help message.')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
memoize :options
|
44
|
+
|
45
|
+
def detail_message(msgs)
|
46
|
+
indent = ' ' * 21
|
47
|
+
main = msgs[0]
|
48
|
+
detail = msgs[1..-1].map { |msg| "#{indent}#{msg}" }.join("\n")
|
49
|
+
"#{main}\n#{detail}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Gem::Search
|
2
|
+
module Commands
|
3
|
+
class Browse < Base
|
4
|
+
def call
|
5
|
+
executor = Executor.new
|
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
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Gem::Search
|
2
|
+
module Commands
|
3
|
+
class Run < Base
|
4
|
+
ENABLE_SORT_OPTS = {
|
5
|
+
'v' => 'version_downloads',
|
6
|
+
'a' => 'downloads',
|
7
|
+
'n' => 'name',
|
8
|
+
}
|
9
|
+
|
10
|
+
def call
|
11
|
+
unless valid?(options.arguments)
|
12
|
+
puts options
|
13
|
+
abort
|
14
|
+
end
|
15
|
+
|
16
|
+
executor = Executor.new
|
17
|
+
gem = options.arguments[0]
|
18
|
+
executor.search(gem, setup_opts)
|
19
|
+
rescue Gem::Search::LibraryNotFound => e
|
20
|
+
puts e.message
|
21
|
+
abort
|
22
|
+
rescue => e
|
23
|
+
puts "An unexpected #{e.class} has occurred."
|
24
|
+
puts e.message
|
25
|
+
puts e.backtrace if ENV['DEBUG']
|
26
|
+
abort
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def setup_opts
|
32
|
+
{
|
33
|
+
sort: ENABLE_SORT_OPTS[options['sort']] || 'downloads',
|
34
|
+
detail: options.detail?
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def valid?(arguments)
|
39
|
+
arguments.size > 0 && arguments.none? { |arg| arg.match(/\A-/) }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/gem_search/executor.rb
CHANGED
@@ -3,7 +3,7 @@ require 'open-uri'
|
|
3
3
|
|
4
4
|
module Gem::Search
|
5
5
|
class Executor
|
6
|
-
include
|
6
|
+
include Rendering
|
7
7
|
BASE_URL = 'https://rubygems.org'
|
8
8
|
SEARCH_API = "#{BASE_URL}/api/v1/search.json?query=%s&page=%d"
|
9
9
|
GEM_API = "#{BASE_URL}/api/v1/gems/%s.json"
|
@@ -37,6 +37,7 @@ module Gem::Search
|
|
37
37
|
if url.nil? || url.empty?
|
38
38
|
url = GEM_URL % gem
|
39
39
|
end
|
40
|
+
puts "Opening #{url}"
|
40
41
|
browser_open(url)
|
41
42
|
end
|
42
43
|
|
data/lib/gem_search/version.rb
CHANGED
data/spec/bin/gem_search_spec.rb
CHANGED
@@ -1,23 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
BIN = 'bin/gem-search'
|
4
|
+
|
4
5
|
USAGE = <<-EOS
|
5
6
|
Usage: gem-search gem_name [options]
|
6
7
|
|
7
|
-
-s, --sort
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
-
|
13
|
-
-
|
14
|
-
-
|
15
|
-
|
16
|
-
Available commands:
|
17
|
-
|
18
|
-
browse Open rubygem's homepage in the system's default web browser
|
19
|
-
|
20
|
-
See `<command> --help` for more information on a specific command.
|
8
|
+
-s, --sort Sort by the field.
|
9
|
+
default [a]ll
|
10
|
+
[a]ll :DL(all) e.g.: gem-search webkit -s a
|
11
|
+
[v]er :DL(ver) e.g.: gem-search webkit -s v
|
12
|
+
[n]ame : e.g.: gem-search webkit -s n
|
13
|
+
-b, --browse Open rubygem's homepage in the system's default web browser.
|
14
|
+
-d, --detail Display rubygems's homepage url.
|
15
|
+
-v, --version Display the version.
|
16
|
+
-h, --help Display this help message.
|
21
17
|
EOS
|
22
18
|
|
23
19
|
RSpec.shared_examples 'display an usage' do
|
@@ -48,5 +44,4 @@ RSpec.describe 'bin/gem-search' do
|
|
48
44
|
should == "gem-search #{Gem::Search::VERSION}\n"
|
49
45
|
end
|
50
46
|
end
|
51
|
-
|
52
47
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Gem::Search
|
4
|
+
|
5
|
+
RSpec.describe Commands::Browse do
|
6
|
+
describe '#call' do
|
7
|
+
before do
|
8
|
+
@executor = Executor.new
|
9
|
+
allow(Executor).to receive(:new).and_return(@executor)
|
10
|
+
@options = { browse: query }
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:query) { 'factory_girl' }
|
14
|
+
|
15
|
+
context 'with browse option' do
|
16
|
+
it 'called Executor#browse with browse option' do
|
17
|
+
expect(@executor).to receive(:browse).with(query).once
|
18
|
+
Commands::Browse.new(@options).call
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -2,35 +2,34 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
include Gem::Search
|
4
4
|
|
5
|
-
RSpec.describe
|
6
|
-
describe '#
|
5
|
+
RSpec.describe Commands::Run do
|
6
|
+
describe '#call' do
|
7
7
|
before do
|
8
8
|
@executor = Executor.new
|
9
9
|
allow(Executor).to receive(:new).and_return(@executor)
|
10
|
-
|
10
|
+
@options = {}
|
11
|
+
allow(@options).to receive(:arguments).and_return([query])
|
12
|
+
allow(@options).to receive(:detail?).and_return(false)
|
11
13
|
stub_request_search(query, 1, dummy_search_result)
|
12
14
|
stub_request_search_no_result_with_page(query, 2)
|
13
15
|
end
|
16
|
+
|
14
17
|
let(:query) { 'factory_girl' }
|
15
18
|
|
16
|
-
context '
|
17
|
-
|
18
|
-
allow(Command::OPTS).to receive(:[]).and_return(nil)
|
19
|
-
end
|
20
|
-
it 'called with no sort option' do
|
19
|
+
context 'without sort option' do
|
20
|
+
it 'called Executor#search without sort option' do
|
21
21
|
expect(@executor).to receive(:search).with(query, default_opts).once
|
22
|
-
|
22
|
+
Commands::Run.new(@options).call
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'with sort option' do
|
27
27
|
before do
|
28
|
-
allow(
|
29
|
-
allow(Command::OPTS).to receive(:[]).with('sort').and_return('a')
|
28
|
+
allow(@options).to receive(:sort).and_return('a')
|
30
29
|
end
|
31
|
-
it 'called with sort option' do
|
30
|
+
it 'called Executor#search with sort option' do
|
32
31
|
expect(@executor).to receive(:search).with(query, default_opts(sort: 'downloads')).once
|
33
|
-
|
32
|
+
Commands::Run.new(@options).call
|
34
33
|
end
|
35
34
|
end
|
36
35
|
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.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rochefort
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slop
|
@@ -16,28 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.8.
|
33
|
+
version: 1.8.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.8.
|
40
|
+
version: 1.8.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mem
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.5
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.5
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: webmock
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,12 +126,19 @@ files:
|
|
112
126
|
- bin/gem-search
|
113
127
|
- gem-search.gemspec
|
114
128
|
- lib/gem_search.rb
|
115
|
-
- lib/gem_search/
|
129
|
+
- lib/gem_search/command_builder.rb
|
130
|
+
- lib/gem_search/commands.rb
|
131
|
+
- lib/gem_search/commands/base.rb
|
132
|
+
- lib/gem_search/commands/browse.rb
|
133
|
+
- lib/gem_search/commands/help.rb
|
134
|
+
- lib/gem_search/commands/run.rb
|
135
|
+
- lib/gem_search/commands/version.rb
|
116
136
|
- lib/gem_search/executor.rb
|
117
137
|
- lib/gem_search/rendering.rb
|
118
138
|
- lib/gem_search/version.rb
|
119
139
|
- spec/bin/gem_search_spec.rb
|
120
|
-
- spec/
|
140
|
+
- spec/commands/browse_spec.rb
|
141
|
+
- spec/commands/run_spec.rb
|
121
142
|
- spec/executor_spec.rb
|
122
143
|
- spec/http_stubs/gems/git-trend.json
|
123
144
|
- spec/http_stubs/gems/git-trend_no_homepage.json
|
@@ -128,7 +149,7 @@ files:
|
|
128
149
|
homepage: https://github.com/rochefort/gem-search
|
129
150
|
licenses: []
|
130
151
|
metadata: {}
|
131
|
-
post_install_message:
|
152
|
+
post_install_message: Thanks for installing!
|
132
153
|
rdoc_options: []
|
133
154
|
require_paths:
|
134
155
|
- lib
|
@@ -144,13 +165,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
165
|
version: '0'
|
145
166
|
requirements: []
|
146
167
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.
|
168
|
+
rubygems_version: 2.4.5
|
148
169
|
signing_key:
|
149
170
|
specification_version: 4
|
150
171
|
summary: search gems with using rubygems.org API
|
151
172
|
test_files:
|
152
173
|
- spec/bin/gem_search_spec.rb
|
153
|
-
- spec/
|
174
|
+
- spec/commands/browse_spec.rb
|
175
|
+
- spec/commands/run_spec.rb
|
154
176
|
- spec/executor_spec.rb
|
155
177
|
- spec/http_stubs/gems/git-trend.json
|
156
178
|
- spec/http_stubs/gems/git-trend_no_homepage.json
|
data/lib/gem_search/command.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'slop'
|
2
|
-
|
3
|
-
class Slop
|
4
|
-
def opt_description(msgs)
|
5
|
-
ind = ' ' * 22
|
6
|
-
msgs.inject { |rtn, msg| rtn << "\n#{ind}#{msg}" }
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
module Gem::Search
|
11
|
-
class Command
|
12
|
-
ENABLE_SORT_OPT = {
|
13
|
-
'v' => 'version_downloads',
|
14
|
-
'a' => 'downloads',
|
15
|
-
'n' => 'name',
|
16
|
-
}
|
17
|
-
|
18
|
-
OPTS = Slop.parse(help: true) do
|
19
|
-
banner "Usage: gem-search gem_name [options]\n"
|
20
|
-
on :s, :sort, opt_description([
|
21
|
-
'Sort by the item.',
|
22
|
-
' default [a]ll',
|
23
|
-
' [a]ll :DL(all) eg. gem-search webkit -s a',
|
24
|
-
' [v]er :DL(ver) eg. gem-search webkit -s v',
|
25
|
-
' [n]ame : eg. gem-search webkit -s n',
|
26
|
-
]), argument: :optional
|
27
|
-
on :d, :detail, 'Display homepage url of gem'
|
28
|
-
on :v, :version, 'Display the version.'
|
29
|
-
|
30
|
-
command 'browse' do
|
31
|
-
description "Open rubygem's homepage in the system's default web browser"
|
32
|
-
run do |_opts, args|
|
33
|
-
gem = args.first
|
34
|
-
executor = Executor.new
|
35
|
-
begin
|
36
|
-
executor.browse(gem)
|
37
|
-
rescue OpenURI::HTTPError
|
38
|
-
puts 'No such gem.'
|
39
|
-
abort
|
40
|
-
rescue => e
|
41
|
-
puts e.message
|
42
|
-
puts e.stacktrace
|
43
|
-
abort
|
44
|
-
end
|
45
|
-
exit
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def run
|
51
|
-
version if OPTS['v']
|
52
|
-
validate
|
53
|
-
|
54
|
-
gs = Executor.new
|
55
|
-
gs.search(ARGV[0], setup_opts)
|
56
|
-
rescue LibraryNotFound => e
|
57
|
-
puts e.message
|
58
|
-
abort
|
59
|
-
rescue => e
|
60
|
-
puts "An unexpected #{e.class} has occurred."
|
61
|
-
puts e.message
|
62
|
-
abort
|
63
|
-
end
|
64
|
-
|
65
|
-
def setup_opts
|
66
|
-
{
|
67
|
-
sort: ENABLE_SORT_OPT[OPTS['sort']] || 'downloads',
|
68
|
-
detail: OPTS.detail?
|
69
|
-
}
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def version
|
75
|
-
puts "gem-search #{Gem::Search::VERSION}"
|
76
|
-
exit
|
77
|
-
end
|
78
|
-
|
79
|
-
def validate
|
80
|
-
if (ARGV.size == 0)
|
81
|
-
puts OPTS
|
82
|
-
abort
|
83
|
-
end
|
84
|
-
|
85
|
-
if ARGV.any? { |arg| arg.match(/\A-/) }
|
86
|
-
puts OPTS
|
87
|
-
exit
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|