rubycat 0.1.0 → 0.2.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 +4 -4
- data/Manifest.txt +2 -0
- data/lib/rubycat.rb +5 -0
- data/lib/rubycat/card.rb +55 -11
- data/lib/rubycat/catalog.rb +26 -7
- data/lib/rubycat/service/rubygems.rb +26 -0
- data/lib/rubycat/version.rb +1 -1
- data/test/data/RUBY.md +4 -2
- data/test/test_reader.rb +1 -1
- data/test/test_rubygems.rb +43 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bc966e42b5b73ec39f11771083a4ffe56f99637
|
4
|
+
data.tar.gz: cd8fc699fa69c4ba3b823925832dd6db93a8bd5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 711cf038156b6c6d1c716416cc9a942204260f91a8c43836792479756c2706bd95acc5eaefbe3fdb5c2b306af1b70ff6456c42b034f0ad55df4fbdf4f5c8e6ce
|
7
|
+
data.tar.gz: 6c60ffb244dc8d0bca41359b80ee2838c8603d011089b2cf81db64cdc7a4cf12e5c828a81a0e45ed0b811a305655ce44ae5919b924e317e07193501c5e356be7
|
data/Manifest.txt
CHANGED
data/lib/rubycat.rb
CHANGED
@@ -12,6 +12,11 @@ require 'rubycat/version' ## let version always go first
|
|
12
12
|
require 'rubycat/card'
|
13
13
|
require 'rubycat/catalog'
|
14
14
|
|
15
|
+
## services / apis
|
16
|
+
|
17
|
+
require 'rubycat/service/rubygems'
|
18
|
+
|
19
|
+
|
15
20
|
|
16
21
|
# say hello
|
17
22
|
puts RubyCat.banner if defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG
|
data/lib/rubycat/card.rb
CHANGED
@@ -5,19 +5,37 @@ module RubyCat
|
|
5
5
|
|
6
6
|
class Card
|
7
7
|
|
8
|
+
## read only
|
8
9
|
attr_reader :name # e.g. sinatra
|
9
10
|
attr_reader :gem_url # e.g. https://rubygems.org/gems/sinatra
|
10
11
|
attr_reader :github_url # e.g. https://github.com/sinatra/sinatra
|
11
12
|
attr_reader :categories # e.g.
|
12
13
|
|
14
|
+
attr_reader :desc # info/blurb/description/summary (use summary ??)
|
15
|
+
attr_reader :latest_version ## as string
|
16
|
+
attr_reader :latest_version_downloads
|
17
|
+
attr_reader :downloads ## total downloads
|
18
|
+
attr_reader :deps # runtime dependencies as a string for now (activerecord, activesupport etc.)
|
19
|
+
|
20
|
+
|
21
|
+
def to_hash
|
22
|
+
{ name: @name,
|
23
|
+
gem_url: @gem_url,
|
24
|
+
github_url: @github_url,
|
25
|
+
categories: @categories,
|
26
|
+
desc: @desc,
|
27
|
+
latest_version: @latest_version,
|
28
|
+
latest_version_downloads: @latest_version_downloads,
|
29
|
+
downloads: @downloads,
|
30
|
+
deps: @deps }
|
31
|
+
end
|
32
|
+
|
33
|
+
|
13
34
|
|
14
35
|
def initialize( card )
|
15
36
|
@categories = card.categories
|
16
37
|
@name = nil
|
17
38
|
|
18
|
-
## todo/fix: lotus/lotusrb - fix: make gem name higher priority
|
19
|
-
## for now uses github name
|
20
|
-
## also check/fallback to rubygems name (if no github entry)
|
21
39
|
|
22
40
|
github_link = card.links.find {|it| it[0].include?( ':octocat:') }
|
23
41
|
|
@@ -44,15 +62,41 @@ class Card
|
|
44
62
|
pp card
|
45
63
|
end
|
46
64
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
65
|
+
gem_link = card.links.find {|it| it[0] == ':gem:' }
|
66
|
+
if gem_link
|
67
|
+
@gem_url = gem_link[1]
|
68
|
+
puts "gem_url: #{@gem_url}"
|
69
|
+
|
70
|
+
uri = URI.parse( @gem_url )
|
71
|
+
names = uri.path[1..-1].split('/') ## cut off leading / and split
|
72
|
+
pp names
|
73
|
+
## assume last name entry is name of gem
|
74
|
+
@name = names[-1]
|
75
|
+
else
|
76
|
+
puts "*** no gem_url found"
|
77
|
+
pp card
|
78
|
+
end
|
55
79
|
end
|
80
|
+
|
81
|
+
|
82
|
+
def sync_gems_info( json )
|
83
|
+
@desc = json['info']
|
84
|
+
@latest_version = json['version']
|
85
|
+
@latest_version_downloads = json['version_downloads']
|
86
|
+
@downloads = json['downloads']
|
87
|
+
|
88
|
+
deps_runtime = json['dependencies']['runtime']
|
89
|
+
if deps_runtime && deps_runtime.size > 0
|
90
|
+
deps = []
|
91
|
+
deps_runtime.each do |dep|
|
92
|
+
deps << dep['name']
|
93
|
+
end
|
94
|
+
@deps = deps.join(', ')
|
95
|
+
else
|
96
|
+
@deps = nil
|
97
|
+
end
|
98
|
+
end # method sync_gems_info
|
99
|
+
|
56
100
|
end ## class Card
|
57
101
|
|
58
102
|
|
data/lib/rubycat/catalog.rb
CHANGED
@@ -5,6 +5,8 @@ module RubyCat
|
|
5
5
|
|
6
6
|
class Catalog
|
7
7
|
|
8
|
+
attr_reader :cards
|
9
|
+
|
8
10
|
def initialize
|
9
11
|
@cards = []
|
10
12
|
end
|
@@ -13,6 +15,28 @@ class Catalog
|
|
13
15
|
@cards += cards.map { |card| Card.new(card) } ## convert to RubyCat card
|
14
16
|
end
|
15
17
|
|
18
|
+
def sync( opts={} ) ## change name to populate/autofill, etc. ??
|
19
|
+
## get (extra) data from rubygems via api
|
20
|
+
|
21
|
+
gems = RubyGemsService.new
|
22
|
+
|
23
|
+
@cards.each_with_index do |card,i|
|
24
|
+
|
25
|
+
if card.gem_url
|
26
|
+
json = gems.info( card.name )
|
27
|
+
pp json
|
28
|
+
|
29
|
+
card.sync_gems_info( json )
|
30
|
+
end
|
31
|
+
|
32
|
+
pp card
|
33
|
+
|
34
|
+
### for debugging/testing; stop after processing x (e.g. 2) recs
|
35
|
+
break if opts[:limit] && i >= opts[:limit].to_i ## e.g. i > 2 etc.
|
36
|
+
end
|
37
|
+
end # method sync
|
38
|
+
|
39
|
+
|
16
40
|
def render
|
17
41
|
## render to json
|
18
42
|
puts "--snip--"
|
@@ -20,13 +44,8 @@ class Catalog
|
|
20
44
|
ary = []
|
21
45
|
|
22
46
|
@cards.each do |card|
|
23
|
-
h =
|
24
|
-
|
25
|
-
gem_url: card.gem_url,
|
26
|
-
github_url: card.github_url,
|
27
|
-
categories: card.categories
|
28
|
-
}
|
29
|
-
pp h
|
47
|
+
h = card.to_hash
|
48
|
+
## pp h
|
30
49
|
ary << h
|
31
50
|
end
|
32
51
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
### add to RubyCat module/namespace - why?? why not??
|
5
|
+
|
6
|
+
|
7
|
+
class RubyGemsService
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@worker = Fetcher::Worker.new
|
11
|
+
@api_base = 'http://rubygems.org/api/v1'
|
12
|
+
end
|
13
|
+
|
14
|
+
def info( name )
|
15
|
+
api_url = "#{@api_base}/gems/#{name}.json"
|
16
|
+
|
17
|
+
### fix/todo: add read_json! -- !!!! to fetcher
|
18
|
+
txt = @worker.read_utf8!( api_url )
|
19
|
+
pp txt
|
20
|
+
|
21
|
+
json = JSON.parse( txt )
|
22
|
+
## pp json
|
23
|
+
json ## return parsed json hash (or raise HTTP excep)
|
24
|
+
end
|
25
|
+
end ## class RubyGemsService
|
26
|
+
|
data/lib/rubycat/version.rb
CHANGED
data/test/data/RUBY.md
CHANGED
@@ -79,7 +79,7 @@ Fun / Hack:
|
|
79
79
|
|
80
80
|
Future:
|
81
81
|
|
82
|
-
- [Mustermann](http://rkh.github.io/mustermann), [:octocat:](https://github.com/rkh/mustermann) - your personal string matching expert; can be used as a plugin for Sinatra 1.x and will power Sinatra 2.0; by Konstantin Haase et al
|
82
|
+
- [Mustermann](http://rkh.github.io/mustermann), [:octocat:](https://github.com/rkh/mustermann), [:gem:](https://rubygems.org/gems/mustermann) - your personal string matching expert; can be used as a plugin for Sinatra 1.x and will power Sinatra 2.0; by Konstantin Haase et al
|
83
83
|
|
84
84
|
|
85
85
|
## Volt
|
@@ -95,6 +95,8 @@ _Client/Server Isomorphic Framework_
|
|
95
95
|
|
96
96
|
- [Lattice :octocat:](https://github.com/celluloid/lattice), [:gem:](https://rubygems.org/gems/lattice), [:book:](http://rubydoc.info/gems/lattice) - an actor-based web framework built on top of celluloid, reel, and webmachine; designed for realtime apps, end-to-end streaming, and websockets by Tony Arcieri et al
|
97
97
|
|
98
|
+
- [Angelo :octocat:](https://github.com/kenichi/angelo), [:gem:](https://rubygems.org/gems/angelo) - sinatra-like mini-language for reel (built upon Celluloid::IO, no rack); supports web sockets and server sent events (SSE) by Kenichi Nakamura
|
99
|
+
|
98
100
|
|
99
101
|
|
100
102
|
## Web Service Frameworks
|
@@ -143,7 +145,7 @@ _JSON HTTP API Builder_
|
|
143
145
|
|
144
146
|
## Thanks
|
145
147
|
|
146
|
-
Josep M. Blanquer
|
148
|
+
Tony Arcieri • Josep M. Blanquer
|
147
149
|
|
148
150
|
## Meta
|
149
151
|
|
data/test/test_reader.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_rubygems.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
class TestRubyGems < MiniTest::Test
|
13
|
+
|
14
|
+
def test_ruby
|
15
|
+
|
16
|
+
r = CatalogDb::CardReader.from_file( "#{RubyCat.root}/test/data/RUBY.md" )
|
17
|
+
cards = r.read
|
18
|
+
|
19
|
+
pp cards
|
20
|
+
|
21
|
+
c = cards[0]
|
22
|
+
|
23
|
+
assert_equal [["Rack HQ", "http://rack.github.io"],
|
24
|
+
[":octocat:", "https://github.com/rack"],
|
25
|
+
[":gem:", "https://rubygems.org/gems/rack"],
|
26
|
+
[":book:", "http://rubydoc.info/gems/rack"]], c.links
|
27
|
+
|
28
|
+
assert_equal 'Webframeworks › Rack', c.categories
|
29
|
+
|
30
|
+
cat = RubyCat::Catalog.new
|
31
|
+
cat.add( cards )
|
32
|
+
cat.render
|
33
|
+
|
34
|
+
## try sync w/ RubyGemsService/API
|
35
|
+
cat.sync( limit: 2 ) ## only sync first three recs
|
36
|
+
## cat.sync
|
37
|
+
|
38
|
+
cat.render ## dump w/ new (updated) values
|
39
|
+
|
40
|
+
assert true # if we get here - test success
|
41
|
+
end
|
42
|
+
|
43
|
+
end # class TestRubyGems
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubycat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: catalogdb
|
@@ -98,10 +98,12 @@ files:
|
|
98
98
|
- lib/rubycat.rb
|
99
99
|
- lib/rubycat/card.rb
|
100
100
|
- lib/rubycat/catalog.rb
|
101
|
+
- lib/rubycat/service/rubygems.rb
|
101
102
|
- lib/rubycat/version.rb
|
102
103
|
- test/data/RUBY.md
|
103
104
|
- test/helper.rb
|
104
105
|
- test/test_reader.rb
|
106
|
+
- test/test_rubygems.rb
|
105
107
|
- test/test_version.rb
|
106
108
|
homepage: https://github.com/textkit/rubycat
|
107
109
|
licenses:
|
@@ -131,5 +133,6 @@ specification_version: 4
|
|
131
133
|
summary: rubycat - ruby (library) catalog (cards) command line tool (using the catalog.db
|
132
134
|
machinery)
|
133
135
|
test_files:
|
136
|
+
- test/test_rubygems.rb
|
134
137
|
- test/test_version.rb
|
135
138
|
- test/test_reader.rb
|