gistcafe 0.1.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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +34 -0
- data/LICENSE +25 -0
- data/README.md +118 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gistcafe.gemspec +28 -0
- data/lib/gistcafe.rb +134 -0
- data/lib/gistcafe/version.rb +3 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aac40458d551363c3a5f3d377cf14638a32067a2ec21575b1a6fe76100c7781e
|
4
|
+
data.tar.gz: 63c953de00e421cd663d0cdbc7c7aeebc17de92eafd9cc859180768b6f549474
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2d2b79196b54ea30e768b82927c3e01d6ee89dfa494ee3103d466eb71a12e3f9196580e04b22d101e0e01eadc36f506dc3cfedfb435b29099118c19c3c434c2b
|
7
|
+
data.tar.gz: 663f760d0b28eedad86f7284a4dd81e55a47209d63fada0ca54fc56a82e251257a6e1c81230a4a59d21b062e55fb8a84ec3811dc24385e86d894ac12d1e4315f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gistcafe (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
rake (12.3.2)
|
11
|
+
rspec (3.10.0)
|
12
|
+
rspec-core (~> 3.10.0)
|
13
|
+
rspec-expectations (~> 3.10.0)
|
14
|
+
rspec-mocks (~> 3.10.0)
|
15
|
+
rspec-core (3.10.1)
|
16
|
+
rspec-support (~> 3.10.0)
|
17
|
+
rspec-expectations (3.10.1)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.10.0)
|
20
|
+
rspec-mocks (3.10.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.10.0)
|
23
|
+
rspec-support (3.10.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
x64-mingw32
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
gistcafe!
|
30
|
+
rake (~> 12.0)
|
31
|
+
rspec (~> 3.0)
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
2.1.2
|
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2007-present, Demis Bellot, ServiceStack, Inc.
|
2
|
+
https://servicestack.net
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
7
|
+
* Redistributions of source code must retain the above copyright
|
8
|
+
notice, this list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer in the
|
11
|
+
documentation and/or other materials provided with the distribution.
|
12
|
+
* Neither the name of the ServiceStack nor the
|
13
|
+
names of its contributors may be used to endorse or promote products
|
14
|
+
derived from this software without specific prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
17
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
20
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
21
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
22
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
23
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
24
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
25
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
Useful utils for [gist.cafe](https://gist.cafe) Ruby Apps.
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'gistcafe'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install gistcafe
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Simple Usage Example:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
org_name = "ruby"
|
25
|
+
uri = URI.parse("https://api.github.com/orgs/#{org_name}/repos")
|
26
|
+
|
27
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
28
|
+
http.use_ssl = (uri.scheme == 'https')
|
29
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
30
|
+
|
31
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
32
|
+
req["User-Agent"] = "gist.cafe"
|
33
|
+
req["Content-Type"] = "application/json"
|
34
|
+
|
35
|
+
res = http.request(req)
|
36
|
+
org_repos = JSON.parse(res.body).map {|x| {
|
37
|
+
name: x['name'],
|
38
|
+
description: x['description'],
|
39
|
+
url: x['url'],
|
40
|
+
lang: x['language'],
|
41
|
+
watchers: x['watchers'],
|
42
|
+
forks: x['forks']
|
43
|
+
} }.sort_by { |x| -x[:watchers] }
|
44
|
+
|
45
|
+
puts "Top 3 #{org_name} GitHub Repos:"
|
46
|
+
Inspect.print_dump(org_repos.take(3))
|
47
|
+
|
48
|
+
puts "\nTop 10 #{org_name} GitHub Repos:"
|
49
|
+
Inspect.print_dump_table(org_repos.take(10).map {|x| {
|
50
|
+
name: x[:name],
|
51
|
+
lang: x[:lang],
|
52
|
+
watchers: x[:watchers],
|
53
|
+
forks: x[:forks],
|
54
|
+
}
|
55
|
+
})
|
56
|
+
```
|
57
|
+
|
58
|
+
Which outputs:
|
59
|
+
|
60
|
+
```
|
61
|
+
Top 3 ruby GitHub Repos:
|
62
|
+
[
|
63
|
+
{
|
64
|
+
name: ruby,
|
65
|
+
description: The Ruby Programming Language [mirror],
|
66
|
+
url: https://api.github.com/repos/ruby/ruby,
|
67
|
+
lang: Ruby,
|
68
|
+
watchers: 17837,
|
69
|
+
forks: 4736
|
70
|
+
},
|
71
|
+
{
|
72
|
+
name: www.ruby-lang.org,
|
73
|
+
description: Source of the https://www.ruby-lang.org website.,
|
74
|
+
url: https://api.github.com/repos/ruby/www.ruby-lang.org,
|
75
|
+
lang: Ruby,
|
76
|
+
watchers: 787,
|
77
|
+
forks: 531
|
78
|
+
},
|
79
|
+
{
|
80
|
+
name: rdoc,
|
81
|
+
description: RDoc produces HTML and online documentation for Ruby projects.,
|
82
|
+
url: https://api.github.com/repos/ruby/rdoc,
|
83
|
+
lang: Ruby,
|
84
|
+
watchers: 635,
|
85
|
+
forks: 377
|
86
|
+
}
|
87
|
+
]
|
88
|
+
|
89
|
+
Top 10 ruby GitHub Repos:
|
90
|
+
+----------------------------------------------+
|
91
|
+
| name | lang | watchers | forks |
|
92
|
+
|----------------------------------------------|
|
93
|
+
| ruby | Ruby | 17837 | 4736 |
|
94
|
+
| www.ruby-lang.org | Ruby | 787 | 531 |
|
95
|
+
| rdoc | Ruby | 635 | 377 |
|
96
|
+
| psych | C | 464 | 165 |
|
97
|
+
| spec | Ruby | 437 | 353 |
|
98
|
+
| racc | Yacc | 435 | 64 |
|
99
|
+
| iconv | C | 48 | 16 |
|
100
|
+
| mspec | Ruby | 46 | 60 |
|
101
|
+
| chkbuild | Ruby | 38 | 18 |
|
102
|
+
| docs.ruby-lang.org | Ruby | 34 | 18 |
|
103
|
+
+----------------------------------------------+
|
104
|
+
```
|
105
|
+
|
106
|
+
## Development
|
107
|
+
|
108
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
109
|
+
|
110
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
111
|
+
|
112
|
+
## Contributing
|
113
|
+
|
114
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ServiceStack/gistcafe-ruby.
|
115
|
+
|
116
|
+
## License
|
117
|
+
|
118
|
+
The gem is available as open source under the terms of the [BSD 2-Clause](https://github.com/ServiceStack/gistcafe-ruby/blob/main/LICENSE).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gistcafe"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/gistcafe.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'lib/gistcafe/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "gistcafe"
|
5
|
+
spec.version = Inspect::VERSION
|
6
|
+
spec.authors = ["ServiceStack, Inc."]
|
7
|
+
spec.email = ["team@servicestack.net"]
|
8
|
+
|
9
|
+
spec.summary = "gist.cafe utils for Ruby"
|
10
|
+
spec.homepage = "https://gist.cafe"
|
11
|
+
spec.license = "BSD 2-Clause"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
#spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/ServiceStack/gistcafe-ruby"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/ServiceStack/gistcafe-ruby/blob/main/CHANGELOG.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
end
|
data/lib/gistcafe.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require "gistcafe/version"
|
2
|
+
|
3
|
+
module Inspect
|
4
|
+
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
def self.vars(args)
|
8
|
+
inspect_vars_path = ENV["INSPECT_VARS"]
|
9
|
+
return if args.nil? || inspect_vars_path.nil? || inspect_vars_path.empty?
|
10
|
+
json = JSON.generate(args)
|
11
|
+
vars_path = inspect_vars_path.gsub('\\','/')
|
12
|
+
if vars_path.index('/')
|
13
|
+
Pathname.new(vars_path).dirname.mkpath
|
14
|
+
end
|
15
|
+
File.write(inspect_vars_path, json)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.dump(obj)
|
19
|
+
json = JSON.pretty_generate(obj, { indent:' '}).gsub('"','')
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.print_dump(obj)
|
23
|
+
puts dump(obj)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.to_list_map(rows)
|
27
|
+
to = []
|
28
|
+
rows.each do |row|
|
29
|
+
if row.respond_to?(:to_hash)
|
30
|
+
to.push(row.to_hash)
|
31
|
+
else
|
32
|
+
to.push(row.to_h)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
to
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.all_keys(rows)
|
39
|
+
to = []
|
40
|
+
rows.each do |row|
|
41
|
+
row.each do |k,v|
|
42
|
+
if !to.include?(k)
|
43
|
+
to.push(k)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
to
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.dump_table(rows)
|
51
|
+
return if rows.nil? || rows.empty?
|
52
|
+
map_rows = to_list_map(rows)
|
53
|
+
keys = all_keys(map_rows)
|
54
|
+
col_sizes = {}
|
55
|
+
|
56
|
+
keys.each do |k|
|
57
|
+
max = k.length
|
58
|
+
map_rows.each do |row|
|
59
|
+
col = row[k]
|
60
|
+
if !col.nil?
|
61
|
+
val_size = "#{col}".length
|
62
|
+
if val_size > max
|
63
|
+
max = val_size
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
col_sizes[k] = max
|
68
|
+
end
|
69
|
+
|
70
|
+
col_sizes_length = col_sizes.length
|
71
|
+
row_width = col_sizes.values.sum + (col_sizes_length * 2) + (col_sizes_length + 1)
|
72
|
+
|
73
|
+
dashes = "-" * (row_width - 2)
|
74
|
+
sb = []
|
75
|
+
sb.push("+#{dashes}+")
|
76
|
+
head = "|"
|
77
|
+
keys.each do |k|
|
78
|
+
head += "#{align_center(k, col_sizes[k])}|"
|
79
|
+
end
|
80
|
+
sb.push(head)
|
81
|
+
sb.push("|#{dashes}|")
|
82
|
+
|
83
|
+
map_rows.each do |row|
|
84
|
+
to = "|"
|
85
|
+
keys.each do |k|
|
86
|
+
to += "#{align_auto(row[k], col_sizes[k])}|"
|
87
|
+
end
|
88
|
+
sb.push(to)
|
89
|
+
end
|
90
|
+
|
91
|
+
sb.push("+#{dashes}+")
|
92
|
+
|
93
|
+
sb.join("\n")
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.print_dump_table(obj)
|
97
|
+
puts dump_table(obj)
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.align_left(str, len, pad=" ")
|
101
|
+
return "" if len < 0
|
102
|
+
a_len = len + 1 + str.length
|
103
|
+
return str if a_len <= 0
|
104
|
+
"#{pad}#{str}#{pad * (len + 1 - str.length)}"
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.align_center(str, len, pad=" ")
|
108
|
+
return "" if len < 0
|
109
|
+
str = "" if str.nil?
|
110
|
+
n_len = str.length
|
111
|
+
half = (len / 2.0 - n_len / 2.0).floor
|
112
|
+
odds = ((n_len % 2) - (len % 2)).abs
|
113
|
+
"#{pad * (half + 1)}#{str}#{pad * (half + 1 + odds)}"
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.align_right(str, len, pad=" ")
|
117
|
+
return "" if len < 0
|
118
|
+
a_len = len + 1 + str.length
|
119
|
+
return str if a_len <= 0
|
120
|
+
"#{pad * (len + 1 - str.length)}#{str}#{pad}"
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.align_auto(obj, len, pad=" ")
|
124
|
+
str = "#{obj}"
|
125
|
+
if str.length <= len
|
126
|
+
if !Float(str, exception:false).nil?
|
127
|
+
return align_right(str, len, pad)
|
128
|
+
end
|
129
|
+
return align_left(str, len, pad)
|
130
|
+
end
|
131
|
+
str
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gistcafe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ServiceStack, Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-01-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- team@servicestack.net
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- ".travis.yml"
|
23
|
+
- CHANGELOG.md
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- bin/console
|
30
|
+
- bin/setup
|
31
|
+
- gistcafe.gemspec
|
32
|
+
- lib/gistcafe.rb
|
33
|
+
- lib/gistcafe/version.rb
|
34
|
+
homepage: https://gist.cafe
|
35
|
+
licenses:
|
36
|
+
- BSD 2-Clause
|
37
|
+
metadata:
|
38
|
+
homepage_uri: https://gist.cafe
|
39
|
+
source_code_uri: https://github.com/ServiceStack/gistcafe-ruby
|
40
|
+
changelog_uri: https://github.com/ServiceStack/gistcafe-ruby/blob/main/CHANGELOG.md
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 2.3.0
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.0.6
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: gist.cafe utils for Ruby
|
60
|
+
test_files: []
|