class Spout::Commands::Update
Command to check if there is an updated version of the gem available.
Public Class Methods
new(argv)
click to toggle source
# File lib/spout/commands/update.rb, line 18 def initialize(argv) @full_path = File.join(".") end
start(*args)
click to toggle source
# File lib/spout/commands/update.rb, line 13 def start(*args) new(*args).start end
Public Instance Methods
check_file_presence()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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