gem-search 0.1.4 → 0.1.5

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: 8356a8e7af2ec374120d282eedaa11b3c7c2bd7b
4
- data.tar.gz: dcbe5e724bbf8fef828d07adab9e25a6c456a179
3
+ metadata.gz: 007f61dd3c35fc00a951fd431c22ddc81b6a5d97
4
+ data.tar.gz: c6251305ba1722f85da3c9ef7174755bbc39e765
5
5
  SHA512:
6
- metadata.gz: 96f1228d384a6ce4f7de35762ae2f132084d2e219b22d8f3ee590556d56e3c590e07ca7c8609239ff4f50f55af59472832ca2a2952d494c1a146ee10b8a66261
7
- data.tar.gz: d2f2a18ea20e935a6dee3e969819f0b249c58f1907f967f5d32269ca90c91bc345e8bebf5223fa651fad1e92faa332af52140e1e98b18c34ce92c1ddef1fdd80
6
+ metadata.gz: 5fccfe3e6be4a304b2cef71d4c878522047d27e658a9a55c0efe04764392c1baa57467ff78c656e5d2deccc426e84408a11b21a612cfabc2fa38521b28df461e
7
+ data.tar.gz: 0c6546b3481356f6458571b7e014262bdd7fc5555ac3ae6050c610745ed8b06a47796cf5cd97df07d3fb1bf0b9e6d5e2671b0cf368697f1fd4ab9204e0e35eb7
@@ -1,6 +1,11 @@
1
+ ## v0.1.5
2
+
3
+ * Update slop for v4.0.0 and refactor. [94db668]
4
+
5
+
1
6
  ## v0.1.4
2
7
 
3
- * Fix cannnot open gem url when gem has no homepage url. [b476b28]
8
+ * Fix cannot open gem url when gem has no homepage url. [b476b28]
4
9
 
5
10
  ## v0.1.3
6
11
 
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
- gem-search browse 'gem_name'
121
+ gem-search -b `keyword'
122
+
123
+ or
124
+
125
+ gem-search --browse `keyword'
122
126
 
123
127
 
124
128
 
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'gem_search'
3
3
 
4
- Gem::Search::Command.new.run
4
+ Gem::Search::CommandBuilder.new(ARGV).build.call
@@ -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', '~>3.6.0'
34
- gem.add_dependency 'json', '~>1.8.1'
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'
@@ -1,9 +1,12 @@
1
- module Gem
2
- module Search
3
- class LibraryNotFound < StandardError; end
4
- autoload :Command, 'gem_search/command'
5
- autoload :Executor, 'gem_search/executor'
6
- autoload :Rendering, 'gem_search/rendering'
7
- autoload :VERSION, 'gem_search/version'
8
- end
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,9 @@
1
+ module Gem::Search
2
+ module Commands
3
+ require 'gem_search/commands/base.rb'
4
+ require 'gem_search/commands/browse.rb'
5
+ require 'gem_search/commands/help.rb'
6
+ require 'gem_search/commands/run.rb'
7
+ require 'gem_search/commands/version.rb'
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Gem::Search
2
+ module Commands
3
+ class Base
4
+ attr_reader :options
5
+
6
+ def initialize(options)
7
+ @options = options
8
+ end
9
+ end
10
+ end
11
+ 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,9 @@
1
+ module Gem::Search
2
+ module Commands
3
+ class Help < Base
4
+ def call
5
+ puts @options
6
+ end
7
+ end
8
+ end
9
+ 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
@@ -0,0 +1,9 @@
1
+ module Gem::Search
2
+ module Commands
3
+ class Version < Base
4
+ def call
5
+ puts "gem-search #{Gem::Search::VERSION}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -3,7 +3,7 @@ require 'open-uri'
3
3
 
4
4
  module Gem::Search
5
5
  class Executor
6
- include Gem::Search::Rendering
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
 
@@ -1,3 +1,3 @@
1
1
  module Gem::Search
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -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 Sort by the item.
8
- default [a]ll
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
12
- -d, --detail Display homepage url of gem
13
- -v, --version Display the version.
14
- -h, --help Display this help message.
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 Command do
6
- describe '#run' do
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
- allow(ARGV).to receive(:[]).with(0).and_return(query)
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 'with no sort option' do
17
- before do
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
- Command.new.run
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(Command::OPTS).to receive(:[]).and_return(nil)
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
- Command.new.run
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
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: 2014-08-13 00:00:00.000000000 Z
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: 3.6.0
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: 3.6.0
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.1
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.1
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/command.rb
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/command_spec.rb
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: "\U0001F37A Thanks for installing!"
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.2.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/command_spec.rb
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
@@ -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