itamae-sonar 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7bc4c6d62ea536ac994831d60c796dc7d84d788b
4
+ data.tar.gz: cc5c5557064b26eb063fa9c1d06d2d594de8b6a1
5
+ SHA512:
6
+ metadata.gz: b61ab93155c1bf54a8f2233afb11c623d8f810dfa1f701d895469c81bf2149d26496851b2262f5b348223875a3cce5727ff04576c26ebf04a1c4bbeeaace10b6
7
+ data.tar.gz: c2071784bba7ca336ce57bcde1bbad6caa5af2eea2d427fdb9d316ba923e1eac786118cd23733e5f1637257a9a2c4b731c9be2c0fb6025edf528f13b64b33e1b
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,24 @@
1
+ Style/Blocks:
2
+ Enabled: false
3
+
4
+ # Offense count: 1
5
+ Style/Documentation:
6
+ Enabled: false
7
+
8
+ # Offense count: 3
9
+ # Configuration parameters: Exclude.
10
+ Style/FileName:
11
+ Enabled: false
12
+
13
+ # Offense count: 2
14
+ # Configuration parameters: CountComments.
15
+ Style/MethodLength:
16
+ Max: 13
17
+
18
+ # Offense count: 2
19
+ Style/MultilineBlockChain:
20
+ Enabled: false
21
+
22
+ # Offense count: 2
23
+ Style/RegexpLiteral:
24
+ MaxSlashes: 0
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,201 @@
1
+ # ItamaeSonar
2
+
3
+ ItamaeSonar search itamae plugin gems.
4
+
5
+ [Itamae](https://github.com/ryotarai/itamae) is Simple and lightweight configuration management tool inspired by Chef.
6
+
7
+ [![Build Status](https://travis-ci.org/tbpgr/itamae-sonar.png?branch=master)](https://travis-ci.org/tbpgr/itamae-sonar)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'itamae-sonar'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install itamae-sonar
24
+
25
+ ## Usage
26
+
27
+ ### info
28
+ ~~~ruby
29
+ require 'pp'
30
+ require 'itamae-sonar'
31
+ pp ItamaeSonar.info 'itamae'
32
+ __END__
33
+ {:name=>"itamae",
34
+ :desc=>"Simple Configuration Management Tool",
35
+ :downloads=>6894,
36
+ :rubygems_uri=>"http://rubygems.org/gems/itamae",
37
+ :homepage_uri=>"https://github.com/ryotarai/itamae"}
38
+ ~~~
39
+
40
+ ### random
41
+ ~~~ruby
42
+ require 'pp'
43
+ require 'itamae-sonar'
44
+ pp ItamaeSonar.random
45
+ pp ItamaeSonar.random
46
+ __END__
47
+ # randome result
48
+ {:name=>"itamae-plugin-recipe-selinux",
49
+ :desc=>"Itamae selinux recipe plugin",
50
+ :downloads=>1065,
51
+ :rubygems_uri=>"http://rubygems.org/gems/itamae-plugin-recipe-selinux",
52
+ :homepage_uri=>""}
53
+ {:name=>"itamae-plugin-resource-ghq",
54
+ :desc=>"Itamae resource plugin to manage repositories with ghq.",
55
+ :downloads=>165,
56
+ :rubygems_uri=>"http://rubygems.org/gems/itamae-plugin-resource-ghq",
57
+ :homepage_uri=>"https://github.com/k0kubun/itamae-plugin-resource-ghq"}
58
+ ~~~
59
+
60
+ ### ranking
61
+ ~~~ruby
62
+ require 'pp'
63
+ require 'itamae-sonar'
64
+ pp ItamaeSonar.ranking
65
+ __END__
66
+ [{:name=>"itamae-plugin-resource-mail_alias",
67
+ :downloads=>1069,
68
+ :authors=>"Gosuke Miyashita"},
69
+ {:name=>"itamae-plugin-recipe-selinux",
70
+ :downloads=>1065,
71
+ :authors=>"Gosuke Miyashita"},
72
+ {:name=>"itamae-plugin-resource-cask",
73
+ :downloads=>628,
74
+ :authors=>"Takashi Kokubun"},
75
+ {:name=>"itamae-plugin-recipe-rtn_rbenv",
76
+ :downloads=>308,
77
+ :authors=>"Ru/MuckRu"},
78
+ {:name=>"itamae-plugin-resource-ghq",
79
+ :downloads=>165,
80
+ :authors=>"Takashi Kokubun"}]
81
+ ~~~
82
+
83
+ ~~~ruby
84
+ require 'pp'
85
+ require 'itamae-sonar'
86
+ pp ItamaeSonar.ranking(3)
87
+ __END__
88
+ [{:name=>"itamae-plugin-resource-mail_alias",
89
+ :downloads=>1069,
90
+ :authors=>"Gosuke Miyashita"},
91
+ {:name=>"itamae-plugin-recipe-selinux",
92
+ :downloads=>1065,
93
+ :authors=>"Gosuke Miyashita"},
94
+ {:name=>"itamae-plugin-resource-cask",
95
+ :downloads=>628,
96
+ :authors=>"Takashi Kokubun"}]
97
+ ~~~
98
+
99
+ ### author_ranking
100
+ ~~~ruby
101
+ require 'pp'
102
+ require 'itamae-sonar'
103
+ pp ItamaeSonar.author_ranking
104
+ __END__
105
+ [{:authors=>"Gosuke Miyashita", :downloads=>2134},
106
+ {:authors=>"Takashi Kokubun", :downloads=>915},
107
+ {:authors=>"Ru/MuckRu", :downloads=>308},
108
+ {:authors=>"Takatoshi Maeda", :downloads=>96}]
109
+ ~~~
110
+
111
+ ~~~bash
112
+ require 'itamae-sonar'
113
+ print ItamaeSonar.author_ranking(3)
114
+ __END__
115
+ [{:authors=>"Gosuke Miyashita", :downloads=>2134},
116
+ {:authors=>"Takashi Kokubun", :downloads=>915},
117
+ {:authors=>"Ru/MuckRu", :downloads=>308}]
118
+ ~~~
119
+
120
+ ## Usage (Command Line)
121
+ ### Commands (Command Line)
122
+ |name|args|memo|
123
+ |:--|:--|:--|
124
+ |[info](#itamae-sonar-info)|gem name|Show target gem info. gem_name, descriptions, downloads, rubygems_url, homepage_url|
125
+ |[random](#itamae-sonar-random)|--|Show random gem info. gem_name, descriptions, downloads, rubygems_url, homepage_url|
126
+ |[ranking](#itamae-sonar-ranking)|limit|Show gem donloads ranking. default = 5|
127
+ |[author_ranking](#itamae-sonar-author_ranking)|limit|Show gem's authers donloads ranking. default = 5|
128
+
129
+ ### itamae-sonar info
130
+ ~~~bash
131
+ $ itamae-sonar info itamae
132
+ name:itamae
133
+ desc:Simple Configuration Management Tool
134
+ downloads:6894
135
+ rubygems_uri:http://rubygems.org/gems/itamae
136
+ homepage_uri:https://github.com/ryotarai/itamae
137
+ ~~~
138
+
139
+ ### itamae-sonar random
140
+ ~~~bash
141
+ $ itamae-sonar random
142
+ name:itamae-plugin-recipe-rtn_rbenv
143
+ desc:Itamae Recipe 'rbenv'
144
+ downloads:308
145
+ rubygems_uri:http://rubygems.org/gems/itamae-plugin-recipe-rtn_rbenv
146
+ homepage_uri:https://github.com/rutan/itamae-plugin-recipe-rtn_rbenv
147
+
148
+ $ itamae-sonar random
149
+ name:itamae-plugin-recipe-rtn_rbenv
150
+ desc:Itamae Recipe 'rbenv'
151
+ downloads:308
152
+ rubygems_uri:http://rubygems.org/gems/itamae-plugin-recipe-rtn_rbenv
153
+ homepage_uri:https://github.com/rutan/itamae-plugin-recipe-rtn_rbenv
154
+
155
+ $ itamae-sonar random
156
+ name:itamae-plugin-recipe-rbenv
157
+ desc:Itamae plugin to install ruby with rbenv
158
+ downloads:122
159
+ rubygems_uri:http://rubygems.org/gems/itamae-plugin-recipe-rbenv
160
+ homepage_uri:https://github.com/k0kubun/itamae-plugin-recipe-rbenv
161
+ ~~~
162
+
163
+ ### itamae-sonar ranking
164
+ ~~~bash
165
+ $ itamae-sonar ranking
166
+ no:1,name:itamae-plugin-resource-mail_alias,downloads:1069
167
+ no:2,name:itamae-plugin-recipe-selinux,downloads:1065
168
+ no:3,name:itamae-plugin-resource-cask,downloads:628
169
+ no:4,name:itamae-plugin-recipe-rtn_rbenv,downloads:308
170
+ no:5,name:itamae-plugin-resource-ghq,downloads:165
171
+
172
+ $ itamae-sonar ranking 3
173
+ no:1,name:itamae-plugin-resource-mail_alias,downloads:1069
174
+ no:2,name:itamae-plugin-recipe-selinux,downloads:1065
175
+ no:3,name:itamae-plugin-resource-cask,downloads:628
176
+ ~~~
177
+
178
+ ### itamae-sonar author_ranking
179
+ ~~~bash
180
+ $ itamae-sonar author_ranking
181
+ no:1,author:Gosuke Miyashita,downloads:2134
182
+ no:2,author:Takashi Kokubun,downloads:915
183
+ no:3,author:Ru/MuckRu,downloads:308
184
+ no:4,author:Takatoshi Maeda,downloads:96
185
+
186
+ $ itamae-sonar author_ranking 3
187
+ no:1,author:Gosuke Miyashita,downloads:2134
188
+ no:2,author:Takashi Kokubun,downloads:915
189
+ no:3,author:Ru/MuckRu,downloads:308
190
+ ~~~
191
+
192
+ ## Dependency
193
+ * itamae-sonar depend on [gems gem](https://github.com/rubygems/gems)
194
+
195
+ ## Contributing
196
+
197
+ 1. Fork it ( https://github.com/[my-github-username]/itamae-sonar/fork )
198
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
199
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
200
+ 4. Push to the branch (`git push origin my-new-feature`)
201
+ 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/itamae-sonar ADDED
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'itamae-sonar'
5
+ require 'itamae-sonar/version'
6
+ require 'thor'
7
+
8
+ # rubocop :disable LineLength
9
+ module ItamaeSonar
10
+ # = ItamaeSonar CLI
11
+ class CLI < Thor
12
+ class_option :help, type: :boolean, aliases: '-h', desc: 'help message.'
13
+ class_option :version, type: :boolean, desc: 'version'
14
+ class_option :debug, type: :boolean, aliases: '-d', desc: 'debug mode'
15
+
16
+ desc 'info [GEM_NAME]', 'get gem info'
17
+ def info(gem_name)
18
+ setting_debug_mode
19
+ gem_info = ItamaeSonar.info(gem_name)
20
+ msg = <<-EOS
21
+ name:#{gem_info[:name]}
22
+ desc:#{gem_info[:desc]}
23
+ downloads:#{gem_info[:downloads]}
24
+ rubygems_uri:#{gem_info[:rubygems_uri]}
25
+ homepage_uri:#{gem_info[:homepage_uri]}
26
+ EOS
27
+ puts msg
28
+ rescue => e
29
+ output_error_if_debug_mode(e)
30
+ exit(false)
31
+ end
32
+
33
+ desc 'random', 'get gem info at random'
34
+ def random
35
+ setting_debug_mode
36
+ gem_info = ItamaeSonar.random
37
+ msg = <<-EOS
38
+ name:#{gem_info[:name]}
39
+ desc:#{gem_info[:desc]}
40
+ downloads:#{gem_info[:downloads]}
41
+ rubygems_uri:#{gem_info[:rubygems_uri]}
42
+ homepage_uri:#{gem_info[:homepage_uri]}
43
+ EOS
44
+ puts msg
45
+ rescue => e
46
+ output_error_if_debug_mode(e)
47
+ exit(false)
48
+ end
49
+
50
+ desc 'ranking [limit]', 'Show gem downloads ranking. default = 5'
51
+ def ranking(limit = 5)
52
+ limit = Integer(limit)
53
+ setting_debug_mode
54
+ gems_info = ItamaeSonar.ranking(limit).map.with_index(1) { |gem_info, i|
55
+ "no:#{i},name:#{gem_info[:name]},downloads:#{gem_info[:downloads]}"
56
+ }
57
+ puts gems_info
58
+ rescue => e
59
+ output_error_if_debug_mode(e)
60
+ exit(false)
61
+ end
62
+
63
+ desc 'author_ranking [limit]', "Show gem's authers downloads ranking. default = 5"
64
+ def author_ranking(limit = 5)
65
+ limit = Integer(limit)
66
+ setting_debug_mode
67
+ gems_info = ItamaeSonar.author_ranking(limit).map.with_index(1) { |gem_info, i|
68
+ "no:#{i},author:#{gem_info[:authors]},downloads:#{gem_info[:downloads]}"
69
+ }
70
+ puts gems_info
71
+ rescue => e
72
+ output_error_if_debug_mode(e)
73
+ exit(false)
74
+ end
75
+
76
+ desc 'version', 'version'
77
+ def version
78
+ p ItamaeSonar::VERSION
79
+ end
80
+
81
+ private
82
+
83
+ def setting_debug_mode
84
+ $DEBUG = options[:debug]
85
+ end
86
+
87
+ def output_error_if_debug_mode(e)
88
+ return unless options[:debug]
89
+ STDERR.puts(e.backtrace)
90
+ end
91
+ end
92
+ end
93
+
94
+ ItamaeSonar::CLI.start(ARGV)
95
+ # rubocop :enable LineLength
@@ -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 'itamae-sonar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'itamae-sonar'
8
+ spec.version = ItamaeSonar::VERSION
9
+ spec.authors = ['tbpgr']
10
+ spec.email = ['tbpgr@tbpgr.jp']
11
+ spec.summary = 'Search itamae plugin gems.'
12
+ spec.description = 'Search itamae plugin gems.'
13
+ spec.homepage = 'https://github.com/tbpgr/itamae-sonar'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(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,4 @@
1
+ # ItamaeSonar
2
+ module ItamaeSonar
3
+ VERSION = '1.0.0'
4
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ require 'gems'
3
+
4
+ module ItamaeSonar
5
+ module_function
6
+
7
+ RUBOTY_SEARCH_CONDITION = 'itamae-'
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 { |e|
34
+ {
35
+ name: e['name'],
36
+ downloads: e['downloads'].to_i,
37
+ authors: e['authors']
38
+ }
39
+ }.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 { |key, values|
48
+ {
49
+ authors: key,
50
+ downloads: values.reduce(0) { |a, e|a + e[:downloads] }
51
+ }
52
+ }.sort_by { |e| -e[:downloads] }
53
+ .take(limit)
54
+ end
55
+ end
@@ -0,0 +1,334 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'itamae-sonar'
4
+ require 'gems'
5
+
6
+ # rubocop :disable LineLength
7
+ describe ItamaeSonar do
8
+ context :info do
9
+ let(:itamae_mock) do
10
+ {
11
+ 'name' => 'itamae-megen',
12
+ 'downloads' => 364,
13
+ 'version' => '1.0.1',
14
+ 'version_downloads' => 121,
15
+ 'platform' => 'ruby',
16
+ 'authors' => 'tbpgr',
17
+ 'info' => 'itamae-megen generate itamae README.md template.',
18
+ 'licenses' => ['MIT'],
19
+ 'project_uri' => 'http://rubygems.org/gems/itamae-megen',
20
+ 'gem_uri' => 'http://rubygems.org/gems/itamae-megen-1.0.1.gem',
21
+ 'homepage_uri' => 'https://github.com/tbpgr/itamae-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: 'itamae-megen',
40
+ expected: {
41
+ name: 'itamae-megen',
42
+ desc: 'itamae-megen generate itamae README.md template.',
43
+ downloads: 364,
44
+ rubygems_uri: 'http://rubygems.org/gems/itamae-megen',
45
+ homepage_uri: 'https://github.com/tbpgr/itamae-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(itamae_mock)
57
+
58
+ # -- when --
59
+ actual = ItamaeSonar.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(:itamae_mock) do
80
+ [
81
+ {
82
+ 'name' => 'itamae-megen',
83
+ 'downloads' => 364,
84
+ 'version' => '1.0.1',
85
+ 'version_downloads' => 121,
86
+ 'platform' => 'ruby',
87
+ 'authors' => 'tbpgr',
88
+ 'info' => 'itamae-megen generate itamae README.md template.',
89
+ 'licenses' => ['MIT'],
90
+ 'project_uri' => 'http://rubygems.org/gems/itamae-megen',
91
+ 'gem_uri' => 'http://rubygems.org/gems/itamae-megen-1.0.1.gem',
92
+ 'homepage_uri' => 'https://github.com/tbpgr/itamae-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: 'itamae-megen',
114
+ desc: 'itamae-megen generate itamae README.md template.',
115
+ downloads: 364,
116
+ rubygems_uri: 'http://rubygems.org/gems/itamae-megen',
117
+ homepage_uri: 'https://github.com/tbpgr/itamae-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(itamae_mock)
129
+
130
+ # -- when --
131
+ actual = ItamaeSonar.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(:itamae_mock) do
152
+ [
153
+ {
154
+ 'name' => 'itamae-megen1',
155
+ 'downloads' => 364,
156
+ 'authors' => 'tbpgr1'
157
+ },
158
+ {
159
+ 'name' => 'itamae-megen2',
160
+ 'downloads' => 363,
161
+ 'authors' => 'tbpgr2'
162
+ },
163
+ {
164
+ 'name' => 'itamae-megen3',
165
+ 'downloads' => 365,
166
+ 'authors' => 'tbpgr4'
167
+ },
168
+ {
169
+ 'name' => 'itamae-megen3',
170
+ 'downloads' => 360,
171
+ 'authors' => 'tbpgr2'
172
+ },
173
+ {
174
+ 'name' => 'itamae-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: 'itamae-megen3', downloads: 365, authors: 'tbpgr4' },
188
+ { name: 'itamae-megen1', downloads: 364, authors: 'tbpgr1' },
189
+ { name: 'itamae-megen2', downloads: 363, authors: 'tbpgr2' }
190
+ ]
191
+ },
192
+ {
193
+ case_no: 2,
194
+ case_title: 'valid case (default limit)',
195
+ expected: [
196
+ { name: 'itamae-megen3', downloads: 365, authors: 'tbpgr4' },
197
+ { name: 'itamae-megen1', downloads: 364, authors: 'tbpgr1' },
198
+ { name: 'itamae-megen2', downloads: 363, authors: 'tbpgr2' },
199
+ { name: 'itamae-megen3', downloads: 362, authors: 'tbpgr6' },
200
+ { name: 'itamae-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(itamae_mock)
212
+
213
+ # -- when --
214
+ if c[:limit]
215
+ actual = ItamaeSonar.ranking(c[:limit])
216
+ else
217
+ actual = ItamaeSonar.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(:itamae_mock) do
239
+ [
240
+ {
241
+ 'name' => 'itamae-megen1',
242
+ 'downloads' => 364,
243
+ 'authors' => 'tbpgr1'
244
+ },
245
+ {
246
+ 'name' => 'itamae-megen2',
247
+ 'downloads' => 363,
248
+ 'authors' => 'tbpgr1'
249
+ },
250
+ {
251
+ 'name' => 'itamae-megen3',
252
+ 'downloads' => 365,
253
+ 'authors' => 'tbpgr2'
254
+ },
255
+ {
256
+ 'name' => 'itamae-megen3',
257
+ 'downloads' => 360,
258
+ 'authors' => 'tbpgr2'
259
+ },
260
+ {
261
+ 'name' => 'itamae-megen3',
262
+ 'downloads' => 362,
263
+ 'authors' => 'tbpgr3'
264
+ },
265
+ {
266
+ 'name' => 'itamae-megen4',
267
+ 'downloads' => 462,
268
+ 'authors' => 'tbpgr4'
269
+ },
270
+ {
271
+ 'name' => 'itamae-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(itamae_mock)
309
+
310
+ # -- when --
311
+ if c[:limit]
312
+ actual = ItamaeSonar.author_ranking(c[:limit])
313
+ else
314
+ actual = ItamaeSonar.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,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itamae-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-04 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 itamae plugin gems.
70
+ email:
71
+ - tbpgr@tbpgr.jp
72
+ executables:
73
+ - itamae-sonar
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - .rubocop.yml
80
+ - .travis.yml
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/itamae-sonar
86
+ - itamae-sonar.gemspec
87
+ - lib/itamae-sonar.rb
88
+ - lib/itamae-sonar/version.rb
89
+ - spec/itamae-sonar_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/tbpgr/itamae-sonar
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.3.0
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Search itamae plugin gems.
115
+ test_files:
116
+ - spec/itamae-sonar_spec.rb
117
+ - spec/spec_helper.rb