kapost-bootstrapper 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48e8b54eec082d2fa5143727675462ce8892f18f
4
- data.tar.gz: 8da354bc5d20bf8f6f64df870a4bc0723c3b300f
3
+ metadata.gz: 6304d8fd0b5d48b0aaa51f59d1486eaf6223ea75
4
+ data.tar.gz: 7968ffd2f955f975c0267bc88d85d3510fa0b3fe
5
5
  SHA512:
6
- metadata.gz: 20d387ab90761ce8008e2798ffe412e5a8cc2be2a10bc23abedef5fb3c4cbe251f14a7e2de443c16e03b3c7c232e2f542ae01914720f82a10785b740fb374b9a
7
- data.tar.gz: f8b88d86e2a17a31ce7962ac54cfccf6456c9757e7fc4a7792e3b13c7f1e8c1f8aa751d2dd780dc7ab225ae3e2c359682223a5023f27dd91605952e2ef3d308d
6
+ metadata.gz: 7a2068b5336aeb916b2099e84cce868c9a2a02dab73af0c4316f841f81afd04f76fa3d4e4b6c1d679a8ade2626d7298bc19bcb163e2cce1d54a77d819c009dff
7
+ data.tar.gz: 9a3085a9ab5b28058fb2be4058c2be08fe830d3768b82a0adbdfd91edd00d640ff74e0b6fd3c75e68649b35b5b5e0801d6c1401143f91851047115b2c25d1a5a
@@ -1,5 +1,5 @@
1
1
  module Kapost
2
2
  class Bootstrapper
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -4,14 +4,42 @@ module Kapost
4
4
  # Application dependency installer for this Rails application.
5
5
  class Bootstrapper
6
6
 
7
- class CommandFailedError < StandardError
8
- attr_reader :command, :status
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
- @command, @status = command, status
37
+ super(command)
38
+ @status = status
11
39
  end
12
40
 
13
41
  def message
14
- "Command `#{cmd}` failed with status #{status}"
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
- run(&block) if block_given?
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
- rescue CommandFailedError => ex
63
+ true
64
+ rescue CommandError => ex
36
65
  die help, exception: ex
37
66
  end
38
- end or die(help)
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, cmd.join(" "), status.exitstatus unless result
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kapost-bootstrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Sadauskas