ruboty-sonar 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fb26a94550171751a97ee20bfde93a8ccd0304d4
4
+ data.tar.gz: a420cc9b6b9daec5454f94eb3951253ea1cf94f2
5
+ SHA512:
6
+ metadata.gz: dc2e06c3c9286e3771d76d441b0c68b96626712c537a1fcde3f9cf0a060e0006c424106b6ac6cde420dbe5cd56220f108c8b9dcea87c2c8ea0fe324e6ae5f168
7
+ data.tar.gz: 12f2f354aea7ebb48abc264643bf79a16f980936b22c83333d795149009389b7b4c9092ffc67835b101b552e69c16df246c213b28cf347467e2127530c0138b6
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,22 @@
1
+ # Offense count: 2
2
+ # Configuration parameters: AllowURI, URISchemes.
3
+ Metrics/LineLength:
4
+ Max: 86
5
+
6
+ # Offense count: 2
7
+ # Configuration parameters: CountComments.
8
+ Metrics/MethodLength:
9
+ Max: 13
10
+
11
+ # Offense count: 1
12
+ Style/Documentation:
13
+ Enabled: false
14
+
15
+ # Offense count: 3
16
+ # Configuration parameters: Exclude.
17
+ Style/FileName:
18
+ Enabled: false
19
+
20
+ # Offense count: 2
21
+ Style/MultilineBlockChain:
22
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem update --system 2.1.11
4
+ - gem --version
5
+ rvm:
6
+ - 2.0.0
7
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'rspec', '~> 2.14.1'
5
+ gem 'thor', '~> 0.18.1'
6
+ gem 'simplecov', '~> 0.8.2'
7
+ gem 'gems', '~> 0.0.4'
8
+
9
+ group :test do
10
+ gem 'coveralls', require: false
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 tbpgr
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,187 @@
1
+ # RubotySonar
2
+
3
+ RubotySonar search ruboty plugin gems.
4
+
5
+ [![Build Status](https://travis-ci.org/tbpgr/ruboty-sonar.png?branch=master)](https://travis-ci.org/tbpgr/ruboty-sonar)
6
+ [![Coverage Status](https://coveralls.io/repos/tbpgr/ruboty-sonar/badge.png)](https://coveralls.io/r/tbpgr/ruboty-sonar)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'ruboty-sonar'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install ruboty-sonar
23
+
24
+ ## Usage
25
+
26
+ ### info
27
+ ~~~ruby
28
+ require 'ruboty-sonar'
29
+ print RubotySonar.info ruboty-megen
30
+ __END__
31
+ {
32
+ :name => 'ruboty-megen',
33
+ :desc => 'ruboty-megen generate ruboty README.md template.',
34
+ :downloads => 364,
35
+ :rubygems_uri => 'http://rubygems.org/gems/ruboty-megen',
36
+ :homepage_uri => 'https://github.com/tbpgr/ruboty-megen'
37
+ }
38
+ ~~~
39
+
40
+ ### random
41
+ ~~~ruby
42
+ require 'pp'
43
+ require 'ruboty-sonar'
44
+ pp RubotySonar.random
45
+ pp RubotySonar.random
46
+ __END__
47
+ # randome result
48
+ {:name=>"ruboty-response",
49
+ :desc=>"Ruboty handler to register a response.",
50
+ :downloads=>414,
51
+ :rubygems_uri=>"http://rubygems.org/gems/ruboty-response",
52
+ :homepage_uri=>"https://github.com/kaihar4/ruboty-response"}
53
+ {:name=>"ruboty-seppuku",
54
+ :desc=>"ruboty plugin for seppuku.",
55
+ :downloads=>310,
56
+ :rubygems_uri=>"http://rubygems.org/gems/ruboty-seppuku",
57
+ :homepage_uri=>"https://github.com/blockgiven/ruboty-seppuku"}
58
+ ~~~
59
+
60
+ ### ranking
61
+ ~~~ruby
62
+ require 'pp'
63
+ require 'ruboty-sonar'
64
+ pp RubotySonar.ranking
65
+ __END__
66
+ [{:name=>"ruboty-redis", :downloads=>869, :authors=>"Ryo Nakamura"},
67
+ {:name=>"ruboty-lgtm", :downloads=>827, :authors=>"negipo"},
68
+ {:name=>"ruboty-twitter", :downloads=>626, :authors=>"Ryo Nakamura"},
69
+ {:name=>"ruboty-japan_weather", :downloads=>551, :authors=>"Taiki ONO"},
70
+ {:name=>"ruboty-trust_me", :downloads=>485, :authors=>"block_given?"}]
71
+ ~~~
72
+
73
+ ~~~ruby
74
+ require 'pp'
75
+ require 'ruboty-sonar'
76
+ pp RubotySonar.ranking(3)
77
+ __END__
78
+ [{:name=>"ruboty-redis", :downloads=>869, :authors=>"Ryo Nakamura"},
79
+ {:name=>"ruboty-lgtm", :downloads=>827, :authors=>"negipo"},
80
+ {:name=>"ruboty-twitter", :downloads=>626, :authors=>"Ryo Nakamura"}]
81
+ ~~~
82
+
83
+ ### author_ranking
84
+ ~~~ruby
85
+ require 'pp'
86
+ require 'ruboty-sonar'
87
+ pp RubotySonar.author_ranking
88
+ __END__
89
+ [{:authors=>"block_given?", :downloads=>4530},
90
+ {:authors=>"Ryo Nakamura", :downloads=>1495},
91
+ {:authors=>"kaihar4", :downloads=>1131},
92
+ {:authors=>"negipo", :downloads=>827},
93
+ {:authors=>"Yoshiori SHOJI", :downloads=>805}]
94
+ ~~~
95
+
96
+ ~~~bash
97
+ require 'ruboty-sonar'
98
+ print RubotySonar.author_ranking(3)
99
+ __END__
100
+ [{:authors=>"block_given?", :downloads=>4530},
101
+ {:authors=>"Ryo Nakamura", :downloads=>1495},
102
+ {:authors=>"kaihar4", :downloads=>1131}]
103
+ ~~~
104
+
105
+ ## Usage (Command Line)
106
+ ### Commands (Command Line)
107
+ |name|args|memo|
108
+ |:--|:--|:--|
109
+ |[info](#ruboty-sonar-info)|gem name|Show target gem info. gem_name, descriptions, downloads, rubygems_url, homepage_url|
110
+ |[random](#ruboty-sonar-random)|--|Show random gem info. gem_name, descriptions, downloads, rubygems_url, homepage_url|
111
+ |[ranking](#ruboty-sonar-ranking)|limit|Show gem donloads ranking. default = 5|
112
+ |[author_ranking](#ruboty-sonar-author_ranking)|limit|Show gem's authers donloads ranking. default = 5|
113
+
114
+ ### ruboty-sonar info
115
+ ~~~bash
116
+ $ ruboty-sonar info ruboty-megen
117
+ name:ruboty-megen
118
+ desc:ruboty-megen generate ruboty README.md template.
119
+ downloads:365
120
+ rubygems_uri:http://rubygems.org/gems/ruboty-megen
121
+ homepage_uri:https://github.com/tbpgr/ruboty-megen
122
+ ~~~
123
+
124
+ ### ruboty-sonar random
125
+ ~~~bash
126
+ $ ruboty-sonar random
127
+ name:ruboty-nullpo
128
+ desc:ruboty plugin for ぬるぽ ガッ.
129
+ downloads:136
130
+ rubygems_uri:http://rubygems.org/gems/ruboty-nullpo
131
+ homepage_uri:https://github.com/blockgiven/ruboty-nullpo
132
+
133
+ $ ruboty-sonar random
134
+ name:ruboty-megen
135
+ desc:ruboty-megen generate ruboty README.md template.
136
+ downloads:365
137
+ rubygems_uri:http://rubygems.org/gems/ruboty-megen
138
+ homepage_uri:https://github.com/tbpgr/ruboty-megen
139
+
140
+ $ ruboty-sonar random
141
+ name:ruboty-qiita_scouter
142
+ desc:An Ruboty Handler + Actions to analyze your Qiita power.
143
+ downloads:135
144
+ rubygems_uri:http://rubygems.org/gems/ruboty-qiita_scouter
145
+ homepage_uri:https://github.com/tbpgr/ruboty-qiita_scouter
146
+ ~~~
147
+
148
+ ### ruboty-sonar ranking
149
+ ~~~bash
150
+ $ ruboty-sonar ranking
151
+ no:1,name:ruboty-redis,downloads:869
152
+ no:2,name:ruboty-lgtm,downloads:827
153
+ no:3,name:ruboty-twitter,downloads:626
154
+ no:4,name:ruboty-japan_weather,downloads:551
155
+ no:5,name:ruboty-trust_me,downloads:485
156
+
157
+ $ ruboty-sonar ranking 3
158
+ no:1,name:ruboty-redis,downloads:869
159
+ no:2,name:ruboty-lgtm,downloads:827
160
+ no:3,name:ruboty-twitter,downloads:626
161
+ ~~~
162
+
163
+ ### ruboty-sonar author_ranking
164
+ ~~~bash
165
+ $ ruboty-sonar author_ranking
166
+ no:1,author:block_given?,downloads:4530
167
+ no:2,author:Ryo Nakamura,downloads:1495
168
+ no:3,author:kaihar4,downloads:1131
169
+ no:4,author:negipo,downloads:827
170
+ no:5,author:Yoshiori SHOJI,downloads:805
171
+
172
+ $ ruboty-sonar author_ranking 3
173
+ no:1,author:block_given?,downloads:4530
174
+ no:2,author:Ryo Nakamura,downloads:1495
175
+ no:3,author:kaihar4,downloads:1131
176
+ ~~~
177
+
178
+ ## Dependency
179
+ * ruboty-sonar depend on [gems gem](https://github.com/rubygems/gems)
180
+
181
+ ## Contributing
182
+
183
+ 1. Fork it ( https://github.com/tbpgr/ruboty-sonar/fork )
184
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
185
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
186
+ 4. Push to the branch (`git push origin my-new-feature`)
187
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+ task default: [:spec]
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = 'spec/**/*_spec.rb'
8
+ end
data/bin/ruboty-sonar ADDED
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'ruboty-sonar'
5
+ require 'ruboty-sonar/version'
6
+ require 'thor'
7
+
8
+ module RubotySonar
9
+ # = RubotySonar CLI
10
+ class CLI < Thor
11
+ class_option :help, type: :boolean, aliases: '-h', desc: 'help message.'
12
+ class_option :version, type: :boolean, desc: 'version'
13
+ class_option :debug, type: :boolean, aliases: '-d', desc: 'debug mode'
14
+
15
+ desc 'info [GEM_NAME]', 'get gem info'
16
+ def info(gem_name)
17
+ setting_debug_mode
18
+ gem_info = RubotySonar.info(gem_name)
19
+ msg = <<-EOS
20
+ name:#{gem_info[:name]}
21
+ desc:#{gem_info[:desc]}
22
+ downloads:#{gem_info[:downloads]}
23
+ rubygems_uri:#{gem_info[:rubygems_uri]}
24
+ homepage_uri:#{gem_info[:homepage_uri]}
25
+ EOS
26
+ puts msg
27
+ rescue => e
28
+ output_error_if_debug_mode(e)
29
+ exit(false)
30
+ end
31
+
32
+ desc 'random', 'get gem info at random'
33
+ def random
34
+ setting_debug_mode
35
+ gem_info = RubotySonar.random
36
+ msg = <<-EOS
37
+ name:#{gem_info[:name]}
38
+ desc:#{gem_info[:desc]}
39
+ downloads:#{gem_info[:downloads]}
40
+ rubygems_uri:#{gem_info[:rubygems_uri]}
41
+ homepage_uri:#{gem_info[:homepage_uri]}
42
+ EOS
43
+ puts msg
44
+ rescue => e
45
+ output_error_if_debug_mode(e)
46
+ exit(false)
47
+ end
48
+
49
+ desc 'ranking [limit]', 'Show gem downloads ranking. default = 5'
50
+ def ranking(limit = 5)
51
+ limit = Integer(limit)
52
+ setting_debug_mode
53
+ gems_info = RubotySonar.ranking(limit).map.with_index(1) do |gem_info, i|
54
+ "no:#{i},name:#{gem_info[:name]},downloads:#{gem_info[:downloads]}"
55
+ end
56
+ puts gems_info
57
+ rescue => e
58
+ output_error_if_debug_mode(e)
59
+ exit(false)
60
+ end
61
+
62
+ desc 'author_ranking [limit]', "Show gem's authers downloads ranking. default = 5"
63
+ def author_ranking(limit = 5)
64
+ limit = Integer(limit)
65
+ setting_debug_mode
66
+ gems_info = RubotySonar.author_ranking(limit).map.with_index(1) do |gem_info, i|
67
+ "no:#{i},author:#{gem_info[:authors]},downloads:#{gem_info[:downloads]}"
68
+ end
69
+ puts gems_info
70
+ rescue => e
71
+ output_error_if_debug_mode(e)
72
+ exit(false)
73
+ end
74
+
75
+ desc 'version', 'version'
76
+ def version
77
+ p RubotySonar::VERSION
78
+ end
79
+
80
+ private
81
+
82
+ def setting_debug_mode
83
+ $DEBUG = options[:debug]
84
+ end
85
+
86
+ def output_error_if_debug_mode(e)
87
+ return unless options[:debug]
88
+ STDERR.puts(e.backtrace)
89
+ end
90
+ end
91
+ end
92
+
93
+ RubotySonar::CLI.start(ARGV)
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ require 'gems'
3
+
4
+ module RubotySonar
5
+ module_function
6
+
7
+ RUBOTY_SEARCH_CONDITION = 'ruboty-'
8
+
9
+ def self.info(gem_name)
10
+ gem_info = Gems.info(gem_name)
11
+ {
12
+ name: gem_info['name'],
13
+ desc: gem_info['info'],
14
+ downloads: gem_info['downloads'],
15
+ rubygems_uri: gem_info['project_uri'],
16
+ homepage_uri: gem_info['homepage_uri']
17
+ }
18
+ end
19
+
20
+ def self.random
21
+ gem_info = Gems.search(RUBOTY_SEARCH_CONDITION).sample
22
+ {
23
+ name: gem_info['name'],
24
+ desc: gem_info['info'],
25
+ downloads: gem_info['downloads'],
26
+ rubygems_uri: gem_info['project_uri'],
27
+ homepage_uri: gem_info['homepage_uri']
28
+ }
29
+ end
30
+
31
+ def self.ranking(limit = 5)
32
+ Gems.search(RUBOTY_SEARCH_CONDITION)
33
+ .map do |e|
34
+ {
35
+ name: e['name'],
36
+ downloads: e['downloads'].to_i,
37
+ authors: e['authors']
38
+ }
39
+ end.sort_by { |e|-e[:downloads] }
40
+ .take(limit)
41
+ end
42
+
43
+ def self.author_ranking(limit = 5)
44
+ Gems.search(RUBOTY_SEARCH_CONDITION)
45
+ .map { |e|{ authors: e['authors'], downloads: e['downloads'] } }
46
+ .group_by { |e| e[:authors] }
47
+ .map do |key, values|
48
+ {
49
+ authors: key,
50
+ downloads: values.reduce(0) { |a, e| a + e[:downloads] }
51
+ }
52
+ end.sort_by { |e| -e[:downloads] }
53
+ .take(limit)
54
+ end
55
+ end
@@ -0,0 +1,4 @@
1
+ # RubotySonar
2
+ module RubotySonar
3
+ VERSION = '1.0.0'
4
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty-sonar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ruboty-sonar'
8
+ spec.version = RubotySonar::VERSION
9
+ spec.authors = ['tbpgr']
10
+ spec.email = ['tbpgr@tbpgr.jp']
11
+ spec.summary = 'Search ruboty plugin gems.'
12
+ spec.description = 'Search ruboty plugin gems.'
13
+ spec.homepage = 'https://github.com/tbpgr/ruboty-sonar'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'thor'
22
+ spec.add_runtime_dependency 'gems'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.6'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ end
@@ -0,0 +1,334 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'ruboty-sonar'
4
+ require 'gems'
5
+
6
+ # rubocop: disable LineLength
7
+ describe RubotySonar do
8
+ context :info do
9
+ let(:gems_mock) do
10
+ {
11
+ 'name' => 'ruboty-megen',
12
+ 'downloads' => 364,
13
+ 'version' => '1.0.1',
14
+ 'version_downloads' => 121,
15
+ 'platform' => 'ruby',
16
+ 'authors' => 'tbpgr',
17
+ 'info' => 'ruboty-megen generate ruboty README.md template.',
18
+ 'licenses' => ['MIT'],
19
+ 'project_uri' => 'http://rubygems.org/gems/ruboty-megen',
20
+ 'gem_uri' => 'http://rubygems.org/gems/ruboty-megen-1.0.1.gem',
21
+ 'homepage_uri' => 'https://github.com/tbpgr/ruboty-megen',
22
+ 'wiki_uri' => nil,
23
+ 'documentation_uri' => nil,
24
+ 'mailing_list_uri' => nil,
25
+ 'source_code_uri' => nil,
26
+ 'bug_tracker_uri' => nil,
27
+ 'dependencies' => { 'development' => [{ 'name' => 'bundler', 'requirements' => '~> 1.6' },
28
+ { 'name' => 'rake', 'requirements' => '~> 10.0' },
29
+ { 'name' => 'rspec', 'requirements' => '>= 0' },
30
+ { 'name' => 'simplecov', 'requirements' => '>= 0' }],
31
+ 'runtime' => [{ 'name' => 'thor', 'requirements' => '~> 0.18.1' }]
32
+ }
33
+ }
34
+ end
35
+ cases = [
36
+ {
37
+ case_no: 1,
38
+ case_title: 'valid case',
39
+ gem_name: 'ruboty-megen',
40
+ expected: {
41
+ name: 'ruboty-megen',
42
+ desc: 'ruboty-megen generate ruboty README.md template.',
43
+ downloads: 364,
44
+ rubygems_uri: 'http://rubygems.org/gems/ruboty-megen',
45
+ homepage_uri: 'https://github.com/tbpgr/ruboty-megen'
46
+ }
47
+ }
48
+ ]
49
+
50
+ cases.each do |c|
51
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
52
+ begin
53
+ case_before c
54
+
55
+ # -- given --
56
+ allow(Gems).to receive(:info).and_return(gems_mock)
57
+
58
+ # -- when --
59
+ actual = RubotySonar.info(c[:gem_name])
60
+
61
+ # -- then --
62
+ expect(actual).to eq(c[:expected])
63
+ ensure
64
+ case_after c
65
+ end
66
+ end
67
+
68
+ def case_before(_c)
69
+ # implement each case before
70
+ end
71
+
72
+ def case_after(_c)
73
+ # implement each case after
74
+ end
75
+ end
76
+ end
77
+
78
+ context :random do
79
+ let(:gems_mock) do
80
+ [
81
+ {
82
+ 'name' => 'ruboty-megen',
83
+ 'downloads' => 364,
84
+ 'version' => '1.0.1',
85
+ 'version_downloads' => 121,
86
+ 'platform' => 'ruby',
87
+ 'authors' => 'tbpgr',
88
+ 'info' => 'ruboty-megen generate ruboty README.md template.',
89
+ 'licenses' => ['MIT'],
90
+ 'project_uri' => 'http://rubygems.org/gems/ruboty-megen',
91
+ 'gem_uri' => 'http://rubygems.org/gems/ruboty-megen-1.0.1.gem',
92
+ 'homepage_uri' => 'https://github.com/tbpgr/ruboty-megen',
93
+ 'wiki_uri' => nil,
94
+ 'documentation_uri' => nil,
95
+ 'mailing_list_uri' => nil,
96
+ 'source_code_uri' => nil,
97
+ 'bug_tracker_uri' => nil,
98
+ 'dependencies' => { 'development' => [{ 'name' => 'bundler', 'requirements' => '~> 1.6' },
99
+ { 'name' => 'rake', 'requirements' => '~> 10.0' },
100
+ { 'name' => 'rspec', 'requirements' => '>= 0' },
101
+ { 'name' => 'simplecov', 'requirements' => '>= 0' }],
102
+ 'runtime' => [{ 'name' => 'thor', 'requirements' => '~> 0.18.1' }]
103
+ }
104
+ }
105
+ ]
106
+ end
107
+
108
+ cases = [
109
+ {
110
+ case_no: 1,
111
+ case_title: 'valid case',
112
+ expected: {
113
+ name: 'ruboty-megen',
114
+ desc: 'ruboty-megen generate ruboty README.md template.',
115
+ downloads: 364,
116
+ rubygems_uri: 'http://rubygems.org/gems/ruboty-megen',
117
+ homepage_uri: 'https://github.com/tbpgr/ruboty-megen'
118
+ }
119
+ }
120
+ ]
121
+
122
+ cases.each do |c|
123
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
124
+ begin
125
+ case_before c
126
+
127
+ # -- given --
128
+ allow(Gems).to receive(:search).and_return(gems_mock)
129
+
130
+ # -- when --
131
+ actual = RubotySonar.random
132
+
133
+ # -- then --
134
+ expect(actual).to eq(c[:expected])
135
+ ensure
136
+ case_after c
137
+ end
138
+ end
139
+
140
+ def case_before(_c)
141
+ # implement each case before
142
+ end
143
+
144
+ def case_after(_c)
145
+ # implement each case after
146
+ end
147
+ end
148
+ end
149
+
150
+ context :ranking do
151
+ let(:gems_mock) do
152
+ [
153
+ {
154
+ 'name' => 'ruboty-megen1',
155
+ 'downloads' => 364,
156
+ 'authors' => 'tbpgr1'
157
+ },
158
+ {
159
+ 'name' => 'ruboty-megen2',
160
+ 'downloads' => 363,
161
+ 'authors' => 'tbpgr2'
162
+ },
163
+ {
164
+ 'name' => 'ruboty-megen3',
165
+ 'downloads' => 365,
166
+ 'authors' => 'tbpgr4'
167
+ },
168
+ {
169
+ 'name' => 'ruboty-megen3',
170
+ 'downloads' => 360,
171
+ 'authors' => 'tbpgr2'
172
+ },
173
+ {
174
+ 'name' => 'ruboty-megen3',
175
+ 'downloads' => 362,
176
+ 'authors' => 'tbpgr6'
177
+ }
178
+ ]
179
+ end
180
+
181
+ cases = [
182
+ {
183
+ case_no: 1,
184
+ case_title: 'valid case',
185
+ limit: 3,
186
+ expected: [
187
+ { name: 'ruboty-megen3', downloads: 365, authors: 'tbpgr4' },
188
+ { name: 'ruboty-megen1', downloads: 364, authors: 'tbpgr1' },
189
+ { name: 'ruboty-megen2', downloads: 363, authors: 'tbpgr2' }
190
+ ]
191
+ },
192
+ {
193
+ case_no: 2,
194
+ case_title: 'valid case (default limit)',
195
+ expected: [
196
+ { name: 'ruboty-megen3', downloads: 365, authors: 'tbpgr4' },
197
+ { name: 'ruboty-megen1', downloads: 364, authors: 'tbpgr1' },
198
+ { name: 'ruboty-megen2', downloads: 363, authors: 'tbpgr2' },
199
+ { name: 'ruboty-megen3', downloads: 362, authors: 'tbpgr6' },
200
+ { name: 'ruboty-megen3', downloads: 360, authors: 'tbpgr2' }
201
+ ]
202
+ }
203
+ ]
204
+
205
+ cases.each do |c|
206
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
207
+ begin
208
+ case_before c
209
+
210
+ # -- given --
211
+ allow(Gems).to receive(:search).and_return(gems_mock)
212
+
213
+ # -- when --
214
+ if c[:limit]
215
+ actual = RubotySonar.ranking(c[:limit])
216
+ else
217
+ actual = RubotySonar.ranking
218
+ end
219
+
220
+ # -- then --
221
+ expect(actual).to eq(c[:expected])
222
+ ensure
223
+ case_after c
224
+ end
225
+ end
226
+
227
+ def case_before(_c)
228
+ # implement each case before
229
+ end
230
+
231
+ def case_after(_c)
232
+ # implement each case after
233
+ end
234
+ end
235
+ end
236
+
237
+ context :author_ranking do
238
+ let(:gems_mock) do
239
+ [
240
+ {
241
+ 'name' => 'ruboty-megen1',
242
+ 'downloads' => 364,
243
+ 'authors' => 'tbpgr1'
244
+ },
245
+ {
246
+ 'name' => 'ruboty-megen2',
247
+ 'downloads' => 363,
248
+ 'authors' => 'tbpgr1'
249
+ },
250
+ {
251
+ 'name' => 'ruboty-megen3',
252
+ 'downloads' => 365,
253
+ 'authors' => 'tbpgr2'
254
+ },
255
+ {
256
+ 'name' => 'ruboty-megen3',
257
+ 'downloads' => 360,
258
+ 'authors' => 'tbpgr2'
259
+ },
260
+ {
261
+ 'name' => 'ruboty-megen3',
262
+ 'downloads' => 362,
263
+ 'authors' => 'tbpgr3'
264
+ },
265
+ {
266
+ 'name' => 'ruboty-megen4',
267
+ 'downloads' => 462,
268
+ 'authors' => 'tbpgr4'
269
+ },
270
+ {
271
+ 'name' => 'ruboty-megen5',
272
+ 'downloads' => 562,
273
+ 'authors' => 'tbpgr5'
274
+ }
275
+ ]
276
+ end
277
+
278
+ cases = [
279
+ {
280
+ case_no: 1,
281
+ case_title: 'valid case',
282
+ limit: 3,
283
+ expected: [
284
+ { authors: 'tbpgr1', downloads: 727 },
285
+ { authors: 'tbpgr2', downloads: 725 },
286
+ { authors: 'tbpgr5', downloads: 562 }
287
+ ]
288
+ },
289
+ {
290
+ case_no: 2,
291
+ case_title: 'valid case (default limit)',
292
+ expected: [
293
+ { authors: 'tbpgr1', downloads: 727 },
294
+ { authors: 'tbpgr2', downloads: 725 },
295
+ { authors: 'tbpgr5', downloads: 562 },
296
+ { authors: 'tbpgr4', downloads: 462 },
297
+ { authors: 'tbpgr3', downloads: 362 }
298
+ ]
299
+ }
300
+ ]
301
+
302
+ cases.each do |c|
303
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
304
+ begin
305
+ case_before c
306
+
307
+ # -- given --
308
+ allow(Gems).to receive(:search).and_return(gems_mock)
309
+
310
+ # -- when --
311
+ if c[:limit]
312
+ actual = RubotySonar.author_ranking(c[:limit])
313
+ else
314
+ actual = RubotySonar.author_ranking
315
+ end
316
+
317
+ # -- then --
318
+ expect(actual).to eq(c[:expected])
319
+ ensure
320
+ case_after c
321
+ end
322
+ end
323
+
324
+ def case_before(_c)
325
+ # implement each case before
326
+ end
327
+
328
+ def case_after(_c)
329
+ # implement each case after
330
+ end
331
+ end
332
+ end
333
+ end
334
+ # rubocop: enable LineLength
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+ SimpleCov.start do
10
+ add_filter '/spec/'
11
+ end
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-sonar
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - tbpgr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gems
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Search ruboty plugin gems.
70
+ email:
71
+ - tbpgr@tbpgr.jp
72
+ executables:
73
+ - ruboty-sonar
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .coveralls.yml
78
+ - .gitignore
79
+ - .rspec
80
+ - .rubocop.yml
81
+ - .rubocop_todo.yml
82
+ - .travis.yml
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/ruboty-sonar
88
+ - lib/ruboty-sonar.rb
89
+ - lib/ruboty-sonar/version.rb
90
+ - ruboty-sonar.gemspec
91
+ - spec/ruboty-sonar_spec.rb
92
+ - spec/spec_helper.rb
93
+ homepage: https://github.com/tbpgr/ruboty-sonar
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.3.0
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Search ruboty plugin gems.
117
+ test_files:
118
+ - spec/ruboty-sonar_spec.rb
119
+ - spec/spec_helper.rb