kapost-bootstrapper 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kapost/bootstrapper/version.rb +1 -1
- data/lib/kapost/bootstrapper.rb +46 -12
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6304d8fd0b5d48b0aaa51f59d1486eaf6223ea75
         | 
| 4 | 
            +
              data.tar.gz: 7968ffd2f955f975c0267bc88d85d3510fa0b3fe
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7a2068b5336aeb916b2099e84cce868c9a2a02dab73af0c4316f841f81afd04f76fa3d4e4b6c1d679a8ade2626d7298bc19bcb163e2cce1d54a77d819c009dff
         | 
| 7 | 
            +
              data.tar.gz: 9a3085a9ab5b28058fb2be4058c2be08fe830d3768b82a0adbdfd91edd00d640ff74e0b6fd3c75e68649b35b5b5e0801d6c1401143f91851047115b2c25d1a5a
         | 
    
        data/lib/kapost/bootstrapper.rb
    CHANGED
    
    | @@ -4,14 +4,42 @@ module Kapost | |
| 4 4 | 
             
              # Application dependency installer for this Rails application.
         | 
| 5 5 | 
             
              class Bootstrapper
         | 
| 6 6 |  | 
| 7 | 
            -
                class  | 
| 8 | 
            -
                  attr_reader :command | 
| 7 | 
            +
                class CommandError < StandardError
         | 
| 8 | 
            +
                  attr_reader :command
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def initialize(command)
         | 
| 11 | 
            +
                    @command = command
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                class CommandNotFoundError < CommandError
         | 
| 16 | 
            +
                  def message
         | 
| 17 | 
            +
                    "command `%s` not found" % command
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                class CommandVersionMismatchError < CommandError
         | 
| 22 | 
            +
                  attr_reader :expected_version, :actual_version
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  def initialize(command, expected_version, actual_version)
         | 
| 25 | 
            +
                    super(command)
         | 
| 26 | 
            +
                    @expected_version, @actual_version = expected_version, actual_version
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  def message
         | 
| 30 | 
            +
                    "command `%s` has incorrect version. I expected %s, but you have %s" % [command, expected_version, actual_version]
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                class CommandFailedError < CommandError
         | 
| 35 | 
            +
                  attr_reader :status
         | 
| 9 36 | 
             
                  def initialize(command, status)
         | 
| 10 | 
            -
                     | 
| 37 | 
            +
                    super(command)
         | 
| 38 | 
            +
                    @status = status
         | 
| 11 39 | 
             
                  end
         | 
| 12 40 |  | 
| 13 41 | 
             
                  def message
         | 
| 14 | 
            -
                    "Command `#{ | 
| 42 | 
            +
                    "Command `#{command}` failed with status #{status}"
         | 
| 15 43 | 
             
                  end
         | 
| 16 44 | 
             
                end
         | 
| 17 45 |  | 
| @@ -21,7 +49,7 @@ module Kapost | |
| 21 49 | 
             
                  @platform = platform
         | 
| 22 50 | 
             
                  @shell    = shell
         | 
| 23 51 |  | 
| 24 | 
            -
                   | 
| 52 | 
            +
                  instance_eval(&block) if block_given?
         | 
| 25 53 | 
             
                end
         | 
| 26 54 |  | 
| 27 55 | 
             
                def default_check(command, version)
         | 
| @@ -32,10 +60,12 @@ module Kapost | |
| 32 60 | 
             
                  say(label(command, version)) do
         | 
| 33 61 | 
             
                    begin
         | 
| 34 62 | 
             
                      block_given? ? yield : default_check(command, version)
         | 
| 35 | 
            -
             | 
| 63 | 
            +
                      true
         | 
| 64 | 
            +
                    rescue CommandError => ex
         | 
| 36 65 | 
             
                      die help, exception: ex
         | 
| 37 66 | 
             
                    end
         | 
| 38 | 
            -
                  end | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
                  true
         | 
| 39 69 | 
             
                end
         | 
| 40 70 |  | 
| 41 71 | 
             
                def check_bundler
         | 
| @@ -52,12 +82,16 @@ module Kapost | |
| 52 82 |  | 
| 53 83 | 
             
                def installed?(command)
         | 
| 54 84 | 
             
                  _, status = cli.capture2e "bash -c 'type #{command}'"
         | 
| 55 | 
            -
                  status.success?
         | 
| 85 | 
            +
                  raise CommandNotFoundError, command unless status.success?
         | 
| 86 | 
            +
                  true
         | 
| 56 87 | 
             
                end
         | 
| 57 88 |  | 
| 58 89 | 
             
                def right_version?(command, expected_version)
         | 
| 59 90 | 
             
                  version, status = cli.capture2e "#{command} --version"
         | 
| 60 | 
            -
                  status.success? && version.include?(expected_version)
         | 
| 91 | 
            +
                  unless status.success? && version.include?(expected_version)
         | 
| 92 | 
            +
                    raise CommandVersionMismatchError, command, expected_version, version
         | 
| 93 | 
            +
                  end
         | 
| 94 | 
            +
                  true
         | 
| 61 95 | 
             
                end
         | 
| 62 96 |  | 
| 63 97 | 
             
                def say(message)
         | 
| @@ -76,9 +110,9 @@ module Kapost | |
| 76 110 | 
             
                def sh(*cmd)
         | 
| 77 111 | 
             
                  options = (Hash === cmd.last) ? cmd.pop : {}
         | 
| 78 112 | 
             
                  say(cmd.join(" ")) if options[:verbose]
         | 
| 79 | 
            -
                  result = system(*cmd)
         | 
| 113 | 
            +
                  result = cli.system(*cmd)
         | 
| 80 114 | 
             
                  status = $?
         | 
| 81 | 
            -
                  raise CommandFailedError | 
| 115 | 
            +
                  raise CommandFailedError.new(cmd.join(" "), status.exitstatus) unless result
         | 
| 82 116 | 
             
                  result
         | 
| 83 117 | 
             
                end
         | 
| 84 118 |  | 
| @@ -101,7 +135,7 @@ module Kapost | |
| 101 135 | 
             
                end
         | 
| 102 136 |  | 
| 103 137 | 
             
                def run(&code)
         | 
| 104 | 
            -
                  instance_eval(&code)
         | 
| 138 | 
            +
                  instance_eval(&code) or raise CommandError, code
         | 
| 105 139 | 
             
                end
         | 
| 106 140 |  | 
| 107 141 | 
             
                private
         |