-
Notifications
You must be signed in to change notification settings - Fork 2
/
describe_gems.rb
executable file
·83 lines (60 loc) · 1.71 KB
/
describe_gems.rb
1
2
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env ruby
##############################################################
###
## File: describe_gems.rb
## Desc: Display the summary and description for a set of gems
#
require 'terminal-size' # A tiny gem to accomplish a simple task: Determining the terminal size.
MAX_COLUMNS = Terminal.size[:width] # - 1
usage_str = <<EOS
Usage: #{$0.split('/').last} gem+
where "gem+" is one or more gem names
EOS
if ARGV.empty?
puts usage_str
exit
end
require 'pp'
require 'yaml' # STDLIB
require 'systemu' # systemu
# FIXME: make word_wrap a gem
require 'word_wrap' # Simple tool for word-wrapping text
require 'word_wrap/core_ext' # Simple tool for word-wrapping text
def wrap_with_label(a_label, a_desc)
spacer = " "*a_label.size
desc_array = a_desc.fit(MAX_COLUMNS - a_label.size).split("\n")
desc_array[0]= a_label + desc_array.first
if desc_array.size > 1
(1..desc_array.size-1).each do |x|
desc_array[x] = spacer + desc_array[x]
end
end
return desc_array.join("\n")
end
gems = ARGV
gems.each do |gem|
spec = YAML.load(`gem spec #{gem}`)
unless spec
puts "\n#{gem} -- ERROR no such gem installed"
next
end
puts "\n#{gem} (#{spec.version}) #{spec.homepage}"
summary = spec.summary
unless summary.nil? || 0 == summary.strip.length
puts wrap_with_label(" Summary: ", "#{summary}" )
end
description = spec.description
unless description.nil? ||
0 == description.strip.length ||
summary == description
puts wrap_with_label(" Description: ", "#{description}" )
end
depends = spec.dependencies
unless depends.empty?
puts wrap_with_label(
" Depends on: ",
depends.map{|d| d.name}.join(', ')
)
end
puts
end