itamae-sonar 1.0.0 → 1.0.1
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/.coveralls.yml +1 -0
- data/CHANGELOG.md +10 -0
- data/README.md +2 -0
- data/lib/itamae-sonar.rb +82 -55
- data/lib/itamae-sonar/version.rb +1 -1
- data/spec/itamae-sonar_spec.rb +3 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59aff8db71919acfc136b81081bca783d403c1f1
|
4
|
+
data.tar.gz: 6e86a67a5dc9d05aab1114b5cedff8dfbda0302c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b397beb461970333ab8b54a9fe5289ad4aff3cc2a2eec902c48a50cd0c33d4e490f71e7bb68de71f4ff8fecd92424bedb1aaed1ef5e87a8e9bedda8a26906380
|
7
|
+
data.tar.gz: 250f5a69dfd75ba385b198d5d549160570eda8e67e4875809e84caccfbf5ac315ff523850fad1d7cb65a416c74d084b9c559f9c668113805b15a34a2cb1b168d
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -4,7 +4,9 @@ ItamaeSonar search itamae plugin gems.
|
|
4
4
|
|
5
5
|
[Itamae](https://github.com/ryotarai/itamae) is Simple and lightweight configuration management tool inspired by Chef.
|
6
6
|
|
7
|
+
[](http://badge.fury.io/rb/itamae-sonar)
|
7
8
|
[](https://travis-ci.org/tbpgr/itamae-sonar)
|
9
|
+
[](https://coveralls.io/r/tbpgr/itamae-sonar)
|
8
10
|
|
9
11
|
## Installation
|
10
12
|
|
data/lib/itamae-sonar.rb
CHANGED
@@ -1,55 +1,82 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'gems'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'gems'
|
3
|
+
require 'date'
|
4
|
+
require 'gems/configuration'
|
5
|
+
require 'gems/request'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
# open class for paging
|
9
|
+
module Gems
|
10
|
+
class Client
|
11
|
+
include Gems::Request
|
12
|
+
def search_with_page(query, page)
|
13
|
+
response = get('/api/v1/search.json', :query => query, :page => page.to_s)
|
14
|
+
JSON.parse(response)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ItamaeSonar
|
20
|
+
module_function
|
21
|
+
|
22
|
+
RUBOTY_SEARCH_CONDITION = 'itamae-'
|
23
|
+
|
24
|
+
def self.info(gem_name)
|
25
|
+
gem_info = Gems.info(gem_name)
|
26
|
+
{
|
27
|
+
name: gem_info['name'],
|
28
|
+
desc: gem_info['info'],
|
29
|
+
downloads: gem_info['downloads'],
|
30
|
+
rubygems_uri: gem_info['project_uri'],
|
31
|
+
homepage_uri: gem_info['homepage_uri']
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.search(query)
|
36
|
+
results = []
|
37
|
+
page = 1
|
38
|
+
loop {
|
39
|
+
ret = Gems.search_with_page(query, page)
|
40
|
+
break if ret.empty?
|
41
|
+
results += ret
|
42
|
+
page += 1
|
43
|
+
}
|
44
|
+
results
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.random
|
48
|
+
gem_info = search(RUBOTY_SEARCH_CONDITION).sample
|
49
|
+
{
|
50
|
+
name: gem_info['name'],
|
51
|
+
desc: gem_info['info'],
|
52
|
+
downloads: gem_info['downloads'],
|
53
|
+
rubygems_uri: gem_info['project_uri'],
|
54
|
+
homepage_uri: gem_info['homepage_uri']
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.ranking(limit = 5)
|
59
|
+
search(RUBOTY_SEARCH_CONDITION)
|
60
|
+
.map { |e|
|
61
|
+
{
|
62
|
+
name: e['name'],
|
63
|
+
downloads: e['downloads'].to_i,
|
64
|
+
authors: e['authors']
|
65
|
+
}
|
66
|
+
}.sort_by { |e|-e[:downloads] }
|
67
|
+
.take(limit)
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.author_ranking(limit = 5)
|
71
|
+
search(RUBOTY_SEARCH_CONDITION)
|
72
|
+
.map { |e|{ authors: e['authors'], downloads: e['downloads'] } }
|
73
|
+
.group_by { |e| e[:authors] }
|
74
|
+
.map { |key, values|
|
75
|
+
{
|
76
|
+
authors: key,
|
77
|
+
downloads: values.reduce(0) { |a, e|a + e[:downloads] }
|
78
|
+
}
|
79
|
+
}.sort_by { |e| -e[:downloads] }
|
80
|
+
.take(limit)
|
81
|
+
end
|
82
|
+
end
|
data/lib/itamae-sonar/version.rb
CHANGED
data/spec/itamae-sonar_spec.rb
CHANGED
@@ -125,7 +125,7 @@ describe ItamaeSonar do
|
|
125
125
|
case_before c
|
126
126
|
|
127
127
|
# -- given --
|
128
|
-
allow(
|
128
|
+
allow(ItamaeSonar).to receive(:search).and_return(itamae_mock)
|
129
129
|
|
130
130
|
# -- when --
|
131
131
|
actual = ItamaeSonar.random
|
@@ -208,7 +208,7 @@ describe ItamaeSonar do
|
|
208
208
|
case_before c
|
209
209
|
|
210
210
|
# -- given --
|
211
|
-
allow(
|
211
|
+
allow(ItamaeSonar).to receive(:search).and_return(itamae_mock)
|
212
212
|
|
213
213
|
# -- when --
|
214
214
|
if c[:limit]
|
@@ -305,7 +305,7 @@ describe ItamaeSonar do
|
|
305
305
|
case_before c
|
306
306
|
|
307
307
|
# -- given --
|
308
|
-
allow(
|
308
|
+
allow(ItamaeSonar).to receive(:search).and_return(itamae_mock)
|
309
309
|
|
310
310
|
# -- when --
|
311
311
|
if c[:limit]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itamae-sonar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tbpgr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -74,10 +74,12 @@ executables:
|
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
+
- .coveralls.yml
|
77
78
|
- .gitignore
|
78
79
|
- .rspec
|
79
80
|
- .rubocop.yml
|
80
81
|
- .travis.yml
|
82
|
+
- CHANGELOG.md
|
81
83
|
- Gemfile
|
82
84
|
- LICENSE.txt
|
83
85
|
- README.md
|