Class: Lolipop::Mc::Starter::Rails::CheckItem::EnvRuby

Inherits:
Base
  • Object
show all
Defined in:
lib/lolipop/mc/starter/rails/check_item/env_ruby.rb

Constant Summary

Constants inherited from Base

Base::NOCHECK, Base::SKIPCHECK

Instance Method Summary collapse

Methods inherited from Base

#desc, #dump_config, #initialize, #item_name, #load_config

Constructor Details

This class inherits a constructor from Lolipop::Mc::Starter::Rails::CheckItem::Base

Instance Method Details

#checkObject



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
# File 'lib/lolipop/mc/starter/rails/check_item/env_ruby.rb', line 7

def check
  config = load_config
  ssh_command = config['ssh']
  if ssh_command == NOCHECK
    raise 'SSHコマンドの実行に失敗しました。SSH接続の設定を確認してください'
  end
  begin
    stdout = `#{ssh_command} env`
  rescue => e
    raise "SSHコマンドの実行に失敗しました。SSH接続の設定を確認してください #{e.message}"
  end
  version = '0.0.0'
  md = stdout.match(/RUBY_VERSION=(\d\.\d\.\d)/)
  if md
    version = md[1]
  else
    raise '環境変数 `RUBY_VERSION` が設定されていません。マネージドクラウドのプロジェクトがRailsプロジェクトではない可能性があります'
  end
  local_version = config['ruby']
  raise "マネージドクラウドのRailsプロジェクトのRubyのバージョンとローカルのRubyのバージョンが同じでないようです\nマネージドクラウド:#{version} ローカル:#{local_version}" unless local_version.include?(version)

  gemfile_path = "#{Dir.pwd}/Gemfile"
  raise 'Gemfileがありません' unless File.exist?(gemfile_path)
  content = File.read(gemfile_path)
  raise 'Gemfileに指定してあるRubyのバージョンとマネージドクラウドのRubyのバージョンが同じでないようです' unless content.include?("ruby '#{version}'")

  'マネージドクラウドのRailsプロジェクトのRubyのバージョンとローカルのRubyのバージョンが同じです'
end

#hintObject



36
37
38
39
# File 'lib/lolipop/mc/starter/rails/check_item/env_ruby.rb', line 36

def hint
  puts 'ローカルのRubyのバージョンとマネージドクラウドのRailsプロジェクトのRubyのバージョンを合わせる必要があります'
  puts 'マネージドクラウドのプロジェクト詳細でRubyのバージョンを確認して、同じRubyをインストールしてください'
end