Module: NextRails::BundleReport
Defined Under Namespace
Classes: RailsVersionCompatibility, RubyVersionCompatibility
Instance Method Summary
collapse
Instance Method Details
#build_json(out_of_date_gems, total_gem_count, sourced_from_git_count) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/next_rails/bundle_report.rb', line 81
def build_json(out_of_date_gems, total_gem_count, sourced_from_git_count)
output = Hash.new { [] }
out_of_date_gems.each do |gem|
output[:outdated_gems] += [
{
name: gem.name,
installed_version: gem.version,
installed_age: gem.age,
latest_version: gem.latest_version.version,
latest_age: gem.latest_version.age
}
]
end
output.merge(
{
sourced_from_git_count: sourced_from_git_count,
total_gem_count: total_gem_count
}
)
end
|
#compatible_ruby_version(rails_version) ⇒ Object
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
|
# File 'lib/next_rails/bundle_report.rb', line 25
def compatible_ruby_version(rails_version)
uri = URI('https://rubygems.org/api/v1/versions/rails.json')
res = Net::HTTP.get_response(uri)
all_versions_res = JSON.parse(res.body)
all_versions = []
all_versions_res.each { |rv| all_versions << rv['number'] }
rv = rails_version[:rails_version]
matched_versions = all_versions.select { |h| h.start_with?(rv) }
exact_version = matched_versions.include?(rv) ? rv : matched_versions[0]
if exact_version
uri = URI("https://rubygems.org/api/v2/rubygems/rails/versions/#{exact_version}.json")
res = Net::HTTP.get_response(uri)
ruby_version = JSON.parse(res.body)["ruby_version"]
else
ruby_version = nil
end
if ruby_version
puts "The required ruby version is #{ruby_version} for matched rails version #{exact_version}"
ruby_version
else
puts "Could not find a compatible ruby version"
end
end
|
#outdated(format = nil) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/next_rails/bundle_report.rb', line 64
def outdated(format = nil)
gems = ::GemInfo.all
out_of_date_gems = gems.reject(&:up_to_date?).sort_by(&:created_at)
sourced_from_git = gems.select(&:sourced_from_git?)
if format == 'json'
output_to_json(out_of_date_gems, gems.count, sourced_from_git.count)
else
output_to_stdout(out_of_date_gems, gems.count, sourced_from_git.count)
end
end
|
#output_to_json(out_of_date_gems, total_gem_count, sourced_from_git_count) ⇒ Object
76
77
78
79
|
# File 'lib/next_rails/bundle_report.rb', line 76
def output_to_json(out_of_date_gems, total_gem_count, sourced_from_git_count)
obj = build_json(out_of_date_gems, total_gem_count, sourced_from_git_count)
puts JSON.pretty_generate(obj)
end
|
#output_to_stdout(out_of_date_gems, total_gem_count, sourced_from_git_count) ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/next_rails/bundle_report.rb', line 103
def output_to_stdout(out_of_date_gems, total_gem_count, sourced_from_git_count)
out_of_date_gems.each do |gem|
= "#{gem.name} #{gem.version}"
puts " \#{Rainbow(header).bold.white}: released \#{gem.age} (latest version, \#{gem.latest_version.version}, released \#{gem.latest_version.age})\n MESSAGE\n end\n\n percentage_out_of_date = ((out_of_date_gems.count / total_gem_count.to_f) * 100).round\n footer = <<-MESSAGE\n \#{Rainbow(sourced_from_git_count.to_s).yellow} gems are sourced from git\n \#{Rainbow(out_of_date_gems.count.to_s).red} of the \#{total_gem_count} gems are out-of-date (\#{percentage_out_of_date}%)\n MESSAGE\n\n puts ''\n puts footer\nend\n"
|
#rails_compatibility(rails_version: nil, include_rails_gems: nil) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/next_rails/bundle_report.rb', line 18
def rails_compatibility(rails_version: nil, include_rails_gems: nil)
return unless rails_version
options = { rails_version: rails_version, include_rails_gems: include_rails_gems }
puts RailsVersionCompatibility.new(options: options).generate
end
|
#ruby_compatibility(ruby_version: nil) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/next_rails/bundle_report.rb', line 11
def ruby_compatibility(ruby_version: nil)
return unless ruby_version
options = { ruby_version: ruby_version }
puts RubyVersionCompatibility.new(options: options).generate
end
|