my_gems_summary 1.9 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/my_gems.rb +33 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da9d1a6ba99119d2d1676383249150b0426eeec6e58ac96b8e8b4c0935929434
|
4
|
+
data.tar.gz: ffa25cc33a588b889b645af17ba07eca69855e57ace48492e61bcf0d0a5ec8eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e7dfc6280ed49334a1be4cfc18c8ef0e7226e3acb1fb932233543676d86007d2b8b2bb83cca93bf36bbdec63fe4133cc806eeb098e8a0c7a08f72131f81fd9b
|
7
|
+
data.tar.gz: 2f29383a74fb0db90a8cc0d157a9e07384619ea5ac755207ebf4018698366aeaefe9be88e90fc28d2d6048a42859033b95e8c65b79c2f96eaa9cebf88348ace6
|
data/lib/my_gems.rb
CHANGED
@@ -1,37 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'gems'
|
2
4
|
|
3
5
|
GemDTO = Struct.new(:name, :downloads)
|
4
6
|
|
5
7
|
module MyGems
|
6
8
|
def self.valid_credentials?
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
puts "🥺 Let's authenticate 😭"
|
9
|
+
Gems.gems
|
10
|
+
rescue StandardError
|
11
|
+
puts '🥺 Opps, looks like we are missing your rubygems.org credentials 😭'
|
12
|
+
puts "🥺 Let's authenticate 😭"
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
puts "💻 Please run 'gem signin' and try again 💻"
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.my_gems
|
18
|
+
gems = Gems.gems.map { |gem| GemDTO.new(gem['name'], gem['downloads']) }
|
19
|
+
gems.sort_by(&:downloads).reverse
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.valid_gems?(gems)
|
23
|
+
return gems unless gems.empty?
|
24
|
+
|
25
|
+
puts '🥺 Opps, looks like you have no gems 😭'
|
26
|
+
puts "🥺 Let's add some 💻"
|
27
|
+
|
28
|
+
puts "💻 Please run 'gem build & gem push' and try again 💻"
|
29
|
+
puts "💻 Maybe you can find some funny stuff here github.com/kammradt 💻"
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.gem_with_longest_name(gems)
|
33
|
+
gems.max_by { |gem| gem.name.length }
|
15
34
|
end
|
16
35
|
|
17
36
|
def self.show
|
18
37
|
puts "⭐ Let's see if you're a star!⭐ "
|
19
38
|
return unless valid_credentials?
|
20
39
|
|
40
|
+
gems = my_gems
|
41
|
+
return unless valid_gems?(gems)
|
42
|
+
|
21
43
|
puts "📚 Here's your summary:"
|
22
44
|
puts "\n"
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
gem_with_longest_name = my_gems.max_by { |gem| gem.name.length }
|
28
|
-
|
29
|
-
my_gems.each do |gem|
|
30
|
-
name_output = gem.name.ljust(gem_with_longest_name.first.length)
|
45
|
+
|
46
|
+
gems.each do |gem|
|
47
|
+
name_output = gem.name.ljust(gem_with_longest_name(gems).name.length)
|
31
48
|
puts "🛑 #{name_output} 🔝 #{gem.downloads} downloads"
|
32
49
|
end
|
33
50
|
|
34
51
|
puts "\n"
|
35
|
-
puts
|
52
|
+
puts 'Bye! See you soon 👋👋👋'
|
36
53
|
end
|
37
54
|
end
|