Class: Jack::VersionChecker

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/jack/version_checker.rb

Constant Summary collapse

REQUIRED_VERSION =
"3.1.2"

Instance Method Summary collapse

Methods included from Util

#app_name_convention, #aws_bin, #check_aws_setup, #confirm, #eb, #eb_base_flags, #eb_bin, #ensure_folder_exist, #get_answer, #get_region, #prerequisites, #settings, #sh

Instance Method Details

#checkObject



11
12
13
14
15
16
17
# File 'lib/jack/version_checker.rb', line 11

def check
  major, minor, patch = version_parts(parsed_version)
  r_major, r_minor, r_patch = version_parts(REQUIRED_VERSION)
  (major > r_major) ||
  (major == r_major && minor > r_minor) ||
  (major == r_major && minor == r_minor && patch >= r_patch)
end

#get_versionObject



19
20
21
# File 'lib/jack/version_checker.rb', line 19

def get_version
  `#{eb_bin} --version`
end

#install_instructionsObject



51
52
53
54
55
56
57
# File 'lib/jack/version_checker.rb', line 51

def install_instructions
  if RUBY_PLATFORM =~ /darwin/
    "You can install the eb tool via homebrew:\n\nbrew install awsebcli"
  else
    "Installation instructions: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html"
  end
end

#leave(message) ⇒ Object

for specs



60
61
62
63
# File 'lib/jack/version_checker.rb', line 60

def leave(message)
  puts(message)
  exit 0
end

#not_installedObject



36
37
38
39
40
# File 'lib/jack/version_checker.rb', line 36

def not_installed
  message = "Unable to detect an installation of the eb cli tool. Please install the eb tool.\n\n"
  message << install_instructions
  message
end

#parse_version(version) ⇒ Object



27
28
29
# File 'lib/jack/version_checker.rb', line 27

def parse_version(version)
  parsed = version.match(/EB CLI (\d+\.\d+\.\d+)/)[1]
end

#parsed_versionObject



23
24
25
# File 'lib/jack/version_checker.rb', line 23

def parsed_version
  @parsed_version ||= parse_version(get_version)
end

#runObject



6
7
8
9
# File 'lib/jack/version_checker.rb', line 6

def run
  leave(not_installed) if eb_bin == ""
  leave(version_too_low) unless check
end

#version_parts(parsed) ⇒ Object



32
33
34
# File 'lib/jack/version_checker.rb', line 32

def version_parts(parsed)
  parsed.split('.').collect(&:to_i)
end

#version_too_lowObject



42
43
44
45
46
47
48
49
# File 'lib/jack/version_checker.rb', line 42

def version_too_low
  <<~EOS
    Unable to detect a version of the eb cli tool that works with jack.
    Detected version #{parsed_version}.

    #{install_instructions}
  EOS
end