mvcli 0.0.10 → 0.0.11
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/mvcli/app.rb +2 -0
- data/lib/mvcli/middleware/exception_logger/validation_summary.rb +28 -9
- data/lib/mvcli/middleware/exception_logger.rb +5 -2
- data/lib/mvcli/middleware/exit_status.rb +84 -3
- data/lib/mvcli/version.rb +1 -1
- data/spec/mvcli/middleware/exception_logger/validation_summary_spec.rb +27 -4
- data/spec/mvcli/middleware/exception_logger_spec.rb +4 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3899bbf5f7652090fcc016d3f09850b2012745a
|
4
|
+
data.tar.gz: ae467b67ff7b3f4a3c3a452b1173d4a6bb37fbd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc657dac474ae27bdaf9145da35b8355b03be14896424fd1b3eefcb1548780b6ef72057f31ad9cc8957d521eb590dd12dee70c41c1136346d8fd9346ae7165cd
|
7
|
+
data.tar.gz: fd93d3d430ecdb9c386ffa76a7fce15276ea81c62bae0548a558164761d8c04433dc62be293171a2e35d2f765e4a747f05ee8a5170805feb836811b8b92f52b8
|
data/lib/mvcli/app.rb
CHANGED
@@ -16,6 +16,8 @@ module MVCLI
|
|
16
16
|
ActiveSupport::Dependencies.autoload_paths << root.join('app', path.to_s)
|
17
17
|
end
|
18
18
|
@middleware = Middleware.new
|
19
|
+
@middleware << MVCLI::Middleware::ExitStatus.new
|
20
|
+
@middleware << MVCLI::Middleware::ExceptionLogger.new
|
19
21
|
@middleware << Provisioning::Middleware.new
|
20
22
|
@middleware << @router
|
21
23
|
end
|
@@ -1,21 +1,40 @@
|
|
1
1
|
module MVCLI
|
2
2
|
class Middleware
|
3
3
|
class ExceptionLogger
|
4
|
-
class ValidationSummary
|
4
|
+
class ValidationSummary < Enumerator
|
5
5
|
def initialize(validation)
|
6
|
+
super &method(:yield)
|
6
7
|
@validation = validation
|
7
8
|
end
|
8
9
|
|
9
|
-
def
|
10
|
-
@validation.violations.
|
10
|
+
def yield(output)
|
11
|
+
@validation.violations.each do |key, messages|
|
12
|
+
output << [key, messages]
|
13
|
+
end
|
14
|
+
@validation.errors.each do |key, exceptions|
|
15
|
+
output << [key, exceptions.map {|ex| "#{ex.class}: #{ex.message}"}]
|
16
|
+
end
|
17
|
+
@validation.each do |name, child|
|
18
|
+
if child.length > 1
|
19
|
+
child.each_with_index do |c, i|
|
20
|
+
ValidationSummary.new(c).each do |key, messages|
|
21
|
+
output << ["#{name}[#{i}].#{key}", messages]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
elsif first = child.first
|
25
|
+
ValidationSummary.new(first).each do |key, messages|
|
26
|
+
output << ["#{name}.#{key}", messages]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
11
30
|
end
|
12
31
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
32
|
+
def write(stream)
|
33
|
+
each do |key, messages|
|
34
|
+
messages.each do |msg|
|
35
|
+
stream.puts "#{key}: #{msg}"
|
36
|
+
end
|
37
|
+
end
|
19
38
|
end
|
20
39
|
end
|
21
40
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "mvcli/erb"
|
2
|
+
require "mvcli/validatable"
|
2
3
|
require "mvcli/middleware/exception_logger/validation_summary"
|
3
4
|
|
4
5
|
module MVCLI
|
@@ -7,9 +8,11 @@ module MVCLI
|
|
7
8
|
def call(command)
|
8
9
|
yield command
|
9
10
|
rescue MVCLI::Validatable::ValidationError => e
|
10
|
-
ValidationSummary.new(e).write command.log
|
11
|
+
ValidationSummary.new(e.validation).write command.log
|
12
|
+
raise e
|
11
13
|
rescue Exception => e
|
12
|
-
command.log << e.message
|
14
|
+
command.log << "#{e.class}: #{e.message}\n"
|
15
|
+
command.log << "\n#{e.backtrace.join("\n")}\n" if ENV['backtrace']
|
13
16
|
raise e
|
14
17
|
end
|
15
18
|
end
|
@@ -1,10 +1,91 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require "mvcli/router"
|
2
|
+
require "mvcli/validatable"
|
3
3
|
|
4
|
+
class MVCLI::Middleware
|
4
5
|
class ExitStatus
|
6
|
+
# <b>:ok,</b> <b>:success</b> - Successful termination
|
7
|
+
EX_OK = 0
|
8
|
+
|
9
|
+
# <b>:_base</b> - The base value for sysexit codes
|
10
|
+
EX__BASE = 64
|
11
|
+
|
12
|
+
# <b>:usage</b> - The command was used incorrectly, e.g., with the wrong
|
13
|
+
# number of arguments, a bad flag, a bad syntax in a parameter, or whatever.
|
14
|
+
EX_USAGE = 64
|
15
|
+
|
16
|
+
# <b>:dataerr,</b> <b>:data_error</b> - The input data was incorrect in
|
17
|
+
# some way. This should only be used for user data, not system files.
|
18
|
+
EX_DATAERR = 65
|
19
|
+
|
20
|
+
# <b>:noinput,</b> <b>:input_missing</b> - An input file (not a system
|
21
|
+
# file) did not exist or was not readable. This could also include errors
|
22
|
+
# like "No message" to a mailer (if it cared to catch it).
|
23
|
+
EX_NOINPUT = 66
|
24
|
+
|
25
|
+
# <b>:nouser,</b> <b>:no_such_user</b> - The user specified did not exist.
|
26
|
+
# This might be used for mail addresses or remote logins.
|
27
|
+
EX_NOUSER = 67
|
28
|
+
|
29
|
+
# <b>:nohost,</b> <b>:no_such_host</b> - The host specified did not exist.
|
30
|
+
# This is used in mail addresses or network requests.
|
31
|
+
EX_NOHOST = 68
|
32
|
+
|
33
|
+
# <b>:unavailable,</b> <b>:service_unavailable</b> - A service is
|
34
|
+
# unavailable. This can occur if a support program or file does not exist.
|
35
|
+
# This can also be used as a catchall message when something you wanted to
|
36
|
+
# do doesn't work, but you don't know why.
|
37
|
+
EX_UNAVAILABLE = 69
|
38
|
+
|
39
|
+
# <b>:software,</b> <b>:software_error</b> - An internal software error has
|
40
|
+
# been detected. This should be limited to non-operating system related
|
41
|
+
# errors.
|
42
|
+
EX_SOFTWARE = 70
|
43
|
+
|
44
|
+
# <b>:oserr,</b> <b>:operating_system_error</b> - An operating system error
|
45
|
+
# has been detected. This is intended to be used for such things as
|
46
|
+
# "cannot fork", "cannot create pipe", or the like. It includes things
|
47
|
+
# like getuid returning a user that does not exist in the passwd file.
|
48
|
+
EX_OSERR = 71
|
49
|
+
|
50
|
+
# <b>:osfile,</b> <b>:operating_system_file_error</b> - Some system file
|
51
|
+
# (e.g., /etc/passwd, /etc/utmp, etc.) does not exist, cannot be opened, or
|
52
|
+
# has some sort of error (e.g., syntax error).
|
53
|
+
EX_OSFILE = 72
|
54
|
+
|
55
|
+
# <b>:cantcreat,</b> <b>:cant_create_output</b> - A (user specified) output
|
56
|
+
# file cannot be created.
|
57
|
+
EX_CANTCREAT = 73
|
58
|
+
|
59
|
+
# <b>:ioerr</b> - An error occurred while doing I/O on a file.
|
60
|
+
EX_IOERR = 74
|
61
|
+
|
62
|
+
# <b>:tempfail,</b> <b>:temporary_failure,</b> <b>:try_again</b> - Temporary
|
63
|
+
# failure, indicating something that is not really a serious error. In
|
64
|
+
# sendmail, this means that a mailer (e.g.) could not create a connection,
|
65
|
+
# and the request should be reattempted later.
|
66
|
+
EX_TEMPFAIL = 75
|
67
|
+
|
68
|
+
# <b>:protocol,</b> <b>:protocol_error</b> - The remote system returned
|
69
|
+
# something that was "not possible" during a protocol exchange.
|
70
|
+
EX_PROTOCOL = 76
|
71
|
+
|
72
|
+
# <b>:noperm,</b> <b>:permission_denied</b> - You did not have sufficient
|
73
|
+
# permission to perform the operation. This is not intended for file
|
74
|
+
# system problems, which should use NOINPUT or CANTCREAT, but rather
|
75
|
+
# for higher level permissions.
|
76
|
+
EX_NOPERM = 77
|
77
|
+
|
78
|
+
# <b>:config,</b> <b>:config_error</b> - There was an error in a
|
79
|
+
# user-specified configuration value.
|
80
|
+
EX_CONFIG = 78
|
81
|
+
|
5
82
|
def call(command)
|
6
83
|
result = yield command
|
7
|
-
result.is_a?(Integer) ? result :
|
84
|
+
result.is_a?(Integer) ? result : EX_OK
|
85
|
+
rescue MVCLI::Validatable::ValidationError
|
86
|
+
return EX_DATAERR
|
87
|
+
rescue MVCLI::Router::RoutingError => e
|
88
|
+
return EX_USAGE
|
8
89
|
rescue Exception => e
|
9
90
|
return EX_SOFTWARE
|
10
91
|
end
|
data/lib/mvcli/version.rb
CHANGED
@@ -8,16 +8,39 @@ describe "ValidationSummary" do
|
|
8
8
|
Given(:object) { Object.new }
|
9
9
|
Given(:validation) { validator.validate object }
|
10
10
|
Given(:summary) { MVCLI::Middleware::ExceptionLogger::ValidationSummary.new validation }
|
11
|
-
|
11
|
+
Given(:rollup) { summary.each }
|
12
|
+
|
13
|
+
context "with a simple validation" do
|
12
14
|
Given do
|
13
15
|
validator.validates(:foo, "You dun goofed", nil: true) {|foo| foo != nil}
|
14
16
|
validator.validate object
|
15
17
|
end
|
16
18
|
|
17
|
-
context "
|
19
|
+
context "when validation fails" do
|
18
20
|
When { object.stub(:foo) }
|
19
|
-
Then {
|
20
|
-
|
21
|
+
Then { rollup.first == ["foo", ["You dun goofed"]] }
|
22
|
+
end
|
23
|
+
context "when there is an access error" do
|
24
|
+
When { object.stub(:foo) {fail "bad access"}}
|
25
|
+
Then { rollup.first == ["foo", ["RuntimeError: bad access"]] }
|
26
|
+
end
|
27
|
+
context "when the validation fails on an array property" do
|
28
|
+
When {object.stub(:foo) {[nil]}}
|
29
|
+
Then {rollup.first == ["foo[0]", ["You dun goofed"]]}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
context "with a nested validation" do
|
33
|
+
Given(:child) { double(:Child) }
|
34
|
+
Given(:child_validator) { MVCLI::Validatable::Validator.new }
|
35
|
+
Given do
|
36
|
+
object.stub(:bars) {[child, child]}
|
37
|
+
validator.validates_child :bars
|
38
|
+
child_validator.validates(:bazzes, "bad baz") {|baz| not baz.nil? }
|
39
|
+
child.stub(:validation) {child_validator.validate child}
|
40
|
+
end
|
41
|
+
context "with an invalid nested associtaion" do
|
42
|
+
When { child.stub(:bazzes) {['valid', nil, 'valid']} }
|
43
|
+
Then { rollup.first == ["bars[0].bazzes[1]", ["bad baz"]] }
|
21
44
|
end
|
22
45
|
end
|
23
46
|
end
|
@@ -11,8 +11,9 @@ describe "MVCLI::Middleware::ExceptionLogger" do
|
|
11
11
|
Then {result == 0}
|
12
12
|
end
|
13
13
|
context "with an app that raises an exception" do
|
14
|
-
When(:result) {logger.call(command) {fail "boom!"}}
|
15
|
-
Then {
|
16
|
-
And {
|
14
|
+
When(:result) { logger.call(command) { fail "boom!" } }
|
15
|
+
Then { result.should have_failed StandardError, "boom!" }
|
16
|
+
And { command.log =~ /boom!/ }
|
17
|
+
|
17
18
|
end
|
18
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mvcli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charles Lowell
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
UgImJlChAzCoDP9zi9tdm6jAr7ttF25R9PPYr11ILb7dYe3qUzlNlM6zJx/nb31b
|
30
30
|
IhdyRVup4qLcqYSTPsm6u7VA
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2013-07-
|
32
|
+
date: 2013-07-11 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: map
|