Class: Spout::Commands::Update
Overview
Command to check if there is an updated version of the gem available.
Class Method Summary
collapse
Instance Method Summary
collapse
#copy_file, #directory, #evaluate_file
Constructor Details
#initialize(argv) ⇒ Update
Returns a new instance of Update.
18
19
20
|
# File 'lib/spout/commands/update.rb', line 18
def initialize(argv)
@full_path = File.join(".")
end
|
Class Method Details
.start(*args) ⇒ Object
13
14
15
|
# File 'lib/spout/commands/update.rb', line 13
def start(*args)
new(*args).start
end
|
Instance Method Details
#check_file_presence ⇒ Object
91
92
93
94
95
96
|
# File 'lib/spout/commands/update.rb', line 91
def check_file_presence
@project_name = File.basename(Dir.pwd)
evaluate_file "CHANGELOG.md.erb", "CHANGELOG.md" unless File.exist?("CHANGELOG.md")
evaluate_file "README.md.erb", "README.md" unless File.exist?("README.md")
copy_file "VERSION" unless File.exist?("VERSION")
end
|
#check_folder_presence ⇒ Object
98
99
100
101
102
103
104
|
# File 'lib/spout/commands/update.rb', line 98
def check_folder_presence
folders = %w(domains forms variables).reject { |f| Dir.exist?(f) }
folders.each do |folder|
directory folder
copy_file "keep", "#{folder}/.keep"
end
end
|
#check_framework ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/spout/commands/update.rb', line 46
def check_framework
check_gitignore_file
check_ruby_version
check_file_presence
check_folder_presence
check_test_folder
end
|
#check_gitignore_file ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/spout/commands/update.rb', line 54
def check_gitignore_file
if File.exist?(".gitignore")
lines = IO.readlines(".gitignore").collect(&:strip)
addables = ["/coverage", "/csvs", "/exports", "/graphs"]
removables = ["/dd", "/images"]
unless ((removables & lines) | (addables - lines)).empty?
puts "File: " + ".gitignore".white
puts "----------------"
(removables & lines).each do |removable|
puts "REMOVE LINE ".red + removable.white
end
(addables - lines).each do |addable|
puts " ADD LINE ".green + addable.white
end
puts
end
else
copy_file "gitignore", ".gitignore"
end
end
|
#check_ruby_version ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/spout/commands/update.rb', line 75
def check_ruby_version
if File.exist?(".ruby-version")
lines = IO.readlines(".ruby-version").collect(&:strip)
template_lines = IO.readlines(File.expand_path("../../templates/ruby-version", __FILE__)).collect(&:strip)
if template_lines.first != lines.first
puts "File: " + ".ruby-version".white
puts "-------------------"
print "Update Ruby from " + lines.first.to_s.red
print " to " + template_lines.first.to_s.green
puts "\n\n"
end
else
copy_file "ruby-version", ".ruby-version"
end
end
|
#check_test_folder ⇒ Object
106
107
108
109
110
111
|
# File 'lib/spout/commands/update.rb', line 106
def check_test_folder
return if Dir.exist?("test")
directory "test"
copy_file "test/dictionary_test.rb"
copy_file "test/test_helper.rb"
end
|
#start ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/spout/commands/update.rb', line 22
def start
(json, _status) = Spout::Helpers::JsonRequest.get("https://rubygems.org/api/v1/gems/spout.json")
if json
if json["version"] == Spout::VERSION::STRING
puts "The spout gem is " + "up-to-date".green + "!"
check_framework if File.exist?("Gemfile") || File.exist?("gems.rb")
else
puts "A newer version (v#{json["version"]}) is available!\n\n"
if File.exist?("gems.rb")
puts "Add the following to gems.rb and run " + "bundle update".green + ".\n\n"
puts " gem \"spout\", \"~> #{json["version"]}\"\n".white
elsif File.exist?("Gemfile")
puts "Add the following to Gemfile and run " + "bundle update".green + ".\n\n"
puts " gem \"spout\", \"~> #{json["version"]}\"\n".white
else
puts "Type the following command to update:\n\n"
puts " gem install spout --no-document".white + "\n\n"
end
end
else
puts "Unable to connect to RubyGems.org. Please try again later."
end
end
|