fail_fast 0.5.1 → 0.5.2
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.
- data/.gitignore +2 -0
- data/.rvmrc +1 -0
- data/CHANGELOG.txt +9 -0
- data/Gemfile +3 -0
- data/README.markdown +15 -1
- data/Rakefile +8 -36
- data/fail_fast.gemspec +22 -107
- data/lib/fail_fast/base/base.rb +1 -1
- data/lib/fail_fast/base/messaging.rb +1 -1
- data/lib/fail_fast/base/utils.rb +3 -2
- data/lib/fail_fast/base/z_only_for_tests.rb +2 -2
- data/lib/fail_fast/extensions/directory_exists.rb +41 -0
- data/lib/fail_fast/extensions/file_exists.rb +41 -0
- data/lib/fail_fast/extensions/{check_active_record_db.rb → has_active_record_db.rb} +4 -2
- data/lib/fail_fast/extensions/{check_email.rb → has_email.rb} +7 -5
- data/lib/fail_fast/extensions/{check_mongo_db.rb → has_mongo_db.rb} +13 -9
- data/lib/fail_fast/extensions/{check_url.rb → has_url.rb} +8 -6
- data/lib/fail_fast/extensions/{check_value.rb → has_value.rb} +3 -3
- data/lib/fail_fast/extensions/{check_is_on_path.rb → is_on_path.rb} +10 -6
- data/lib/fail_fast/main.rb +1 -1
- data/lib/fail_fast/support/error_db.rb +1 -1
- data/lib/fail_fast/support/error_details.rb +2 -2
- data/lib/fail_fast/support/z_only_for_tests.rb +1 -1
- data/spec/base/base_commands/fail_spec.rb +7 -0
- data/spec/base/base_commands/failed_spec.rb +19 -0
- data/spec/base/base_commands/only_if_spec.rb +15 -0
- data/spec/base/base_commands/skip_if_spec.rb +29 -0
- data/spec/base/errors_storage_spec.rb +1 -1
- data/spec/base/multiple_blocks_support_spec.rb +3 -3
- data/spec/base/{not_linked_to_a_file_spec.rb → not_linked_to_a_config_file_spec.rb} +3 -3
- data/spec/base/{file_is_empty_spec.rb → when_config_file_is_empty_spec.rb} +3 -3
- data/spec/base/{file_is_missing_spec.rb → when_config_file_is_missing_spec.rb} +2 -2
- data/spec/extensions/{check_file_system_spec.rb → file_or_directory_exists_spec.rb} +18 -2
- data/spec/extensions/{check_active_record_db_spec.rb → has_active_record_db_spec.rb} +11 -6
- data/spec/extensions/{check_email_spec.rb → has_email_spec.rb} +11 -6
- data/spec/extensions/{check_mongo_db_spec.rb → has_mongoDB_spec.rb} +28 -9
- data/spec/extensions/{check_url_spec.rb → has_url_spec.rb} +4 -1
- data/spec/extensions/{check_value_spec.rb → has_value_spec.rb} +15 -11
- data/spec/extensions/{check_is_on_path_spec.rb → is_on_path_spec.rb} +9 -5
- data/spec/spec_helper.rb +39 -4
- metadata +78 -55
- data/VERSION +0 -1
- data/lib/fail_fast/extensions/check_file_system.rb +0 -67
- data/spec/base/base_commands_spec.rb +0 -67
data/.gitignore
CHANGED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.2@failfast
|
data/CHANGELOG.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
0.5.2
|
2
|
+
- changed: replace Jeweler & Rubygems by Bundler
|
3
|
+
- add: all checkers methods return a success status (true/false)
|
4
|
+
ex:
|
5
|
+
...
|
6
|
+
unless directory_exists_for '/log' # now returns true/false
|
7
|
+
puts "The /log directory is missing" # ...
|
8
|
+
puts "create it with $ mkdir /log" # ...
|
9
|
+
end # ...
|
1
10
|
0.5.1
|
2
11
|
- fixed .failed? bug
|
3
12
|
- fixed key prefixes (broken in 0.5.0)
|
data/Gemfile
ADDED
data/README.markdown
CHANGED
@@ -135,7 +135,21 @@ If it fails, you'll get a report like this :
|
|
135
135
|
| * fail a custom failure message
|
136
136
|
+------------------------------------------------------------------------------------------
|
137
137
|
|
138
|
-
### Example 3 :
|
138
|
+
### Example 3 : capture - and handle - individual errors
|
139
|
+
|
140
|
+
FailFast().check_now.but_fail_later do
|
141
|
+
directory_exists_for '/cache' # default error handling/message
|
142
|
+
|
143
|
+
unless directory_exists_for '/log' # custom error handling
|
144
|
+
puts "The /log directory is missing" # ...
|
145
|
+
puts "create it with $ mkdir /log" # ...
|
146
|
+
end # ...
|
147
|
+
end
|
148
|
+
|
149
|
+
FailFast.fail_now # exit it an error was detected in any of the 3 blocks above.
|
150
|
+
|
151
|
+
|
152
|
+
### Example 4 : print an additional custom message if errors were detected
|
139
153
|
|
140
154
|
... # code like in the cases above.
|
141
155
|
|
data/Rakefile
CHANGED
@@ -1,47 +1,19 @@
|
|
1
|
-
|
2
|
-
require '
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'bundler'
|
3
|
+
Bundler::GemHelper.install_tasks
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "fail_fast"
|
8
|
-
gem.summary = %Q{raises an error if the yaml contents of a config file does pass a test script.}
|
9
|
-
gem.description = %Q{raises an error if the yaml contents of a config file does not pass a test script.}
|
10
|
-
gem.email = "alainravet@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/alainravet/fail_fast"
|
12
|
-
gem.authors = ["Alain Ravet"]
|
13
|
-
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
-
gem.add_development_dependency "activerecord"
|
15
|
-
gem.add_development_dependency "mongo"
|
16
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
-
end
|
18
|
-
Jeweler::GemcutterTasks.new
|
19
|
-
rescue LoadError
|
20
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
-
end
|
5
|
+
require 'rake'
|
6
|
+
require 'rake/rdoctask'
|
22
7
|
|
23
8
|
require 'spec/rake/spectask'
|
24
9
|
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
10
|
spec.libs << 'lib' << 'spec'
|
26
11
|
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
12
|
end
|
13
|
+
task :default => :spec
|
28
14
|
|
29
15
|
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
-
spec.libs
|
16
|
+
spec.libs << 'lib' << 'spec'
|
31
17
|
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
-
spec.rcov
|
33
|
-
end
|
34
|
-
|
35
|
-
task :spec => :check_dependencies
|
36
|
-
|
37
|
-
task :default => :spec
|
38
|
-
|
39
|
-
require 'rake/rdoctask'
|
40
|
-
Rake::RDocTask.new do |rdoc|
|
41
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
42
|
-
|
43
|
-
rdoc.rdoc_dir = 'rdoc'
|
44
|
-
rdoc.title = "config_file_check #{version}"
|
45
|
-
rdoc.rdoc_files.include('README*')
|
46
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
18
|
+
spec.rcov = true
|
47
19
|
end
|
data/fail_fast.gemspec
CHANGED
@@ -1,114 +1,29 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
5
2
|
|
3
|
+
$:.push File.expand_path("../lib", __FILE__)
|
4
|
+
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
6
|
+
s.name = 'fail_fast'
|
7
|
+
s.version = '0.5.2'
|
9
8
|
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.date = %q{2010-07-29}
|
13
|
-
s.description = %q{raises an error if the yaml contents of a config file does not pass a test script.}
|
14
|
-
s.email = %q{alainravet@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.markdown"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"CHANGELOG.txt",
|
23
|
-
"LICENSE",
|
24
|
-
"README.markdown",
|
25
|
-
"Rakefile",
|
26
|
-
"VERSION",
|
27
|
-
"fail_fast.gemspec",
|
28
|
-
"lib/fail_fast.rb",
|
29
|
-
"lib/fail_fast/base/base.rb",
|
30
|
-
"lib/fail_fast/base/messaging.rb",
|
31
|
-
"lib/fail_fast/base/utils.rb",
|
32
|
-
"lib/fail_fast/base/z_only_for_tests.rb",
|
33
|
-
"lib/fail_fast/extensions/base_commands.rb",
|
34
|
-
"lib/fail_fast/extensions/check_active_record_db.rb",
|
35
|
-
"lib/fail_fast/extensions/check_email.rb",
|
36
|
-
"lib/fail_fast/extensions/check_file_system.rb",
|
37
|
-
"lib/fail_fast/extensions/check_is_on_path.rb",
|
38
|
-
"lib/fail_fast/extensions/check_mongo_db.rb",
|
39
|
-
"lib/fail_fast/extensions/check_url.rb",
|
40
|
-
"lib/fail_fast/extensions/check_value.rb",
|
41
|
-
"lib/fail_fast/main.rb",
|
42
|
-
"lib/fail_fast/report.txt.erb",
|
43
|
-
"lib/fail_fast/support/error_db.rb",
|
44
|
-
"lib/fail_fast/support/error_details.rb",
|
45
|
-
"lib/fail_fast/support/z_only_for_tests.rb",
|
46
|
-
"show_all_errors.rb",
|
47
|
-
"spec/base/base_commands_spec.rb",
|
48
|
-
"spec/base/error_details_spec.rb",
|
49
|
-
"spec/base/errors_storage_spec.rb",
|
50
|
-
"spec/base/file_is_empty_spec.rb",
|
51
|
-
"spec/base/file_is_missing_spec.rb",
|
52
|
-
"spec/base/multiple_blocks_support_spec.rb",
|
53
|
-
"spec/base/not_linked_to_a_file_spec.rb",
|
54
|
-
"spec/base/report_printing_spec.rb",
|
55
|
-
"spec/extensions/check_active_record_db_spec.rb",
|
56
|
-
"spec/extensions/check_email_spec.rb",
|
57
|
-
"spec/extensions/check_file_system_spec.rb",
|
58
|
-
"spec/extensions/check_is_on_path_spec.rb",
|
59
|
-
"spec/extensions/check_mongo_db_spec.rb",
|
60
|
-
"spec/extensions/check_url_spec.rb",
|
61
|
-
"spec/extensions/check_value_spec.rb",
|
62
|
-
"spec/extensions/key_prefix_spec.rb",
|
63
|
-
"spec/fixtures/empty.yml",
|
64
|
-
"spec/fixtures/simple.yml",
|
65
|
-
"spec/how_to_use_spec.rb",
|
66
|
-
"spec/spec.opts",
|
67
|
-
"spec/spec_helper.rb"
|
68
|
-
]
|
69
|
-
s.homepage = %q{http://github.com/alainravet/fail_fast}
|
70
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
71
|
-
s.require_paths = ["lib"]
|
72
|
-
s.rubygems_version = %q{1.3.7}
|
73
|
-
s.summary = %q{raises an error if the yaml contents of a config file does pass a test script.}
|
74
|
-
s.test_files = [
|
75
|
-
"spec/base/base_commands_spec.rb",
|
76
|
-
"spec/base/error_details_spec.rb",
|
77
|
-
"spec/base/errors_storage_spec.rb",
|
78
|
-
"spec/base/file_is_empty_spec.rb",
|
79
|
-
"spec/base/file_is_missing_spec.rb",
|
80
|
-
"spec/base/multiple_blocks_support_spec.rb",
|
81
|
-
"spec/base/not_linked_to_a_file_spec.rb",
|
82
|
-
"spec/base/report_printing_spec.rb",
|
83
|
-
"spec/extensions/check_active_record_db_spec.rb",
|
84
|
-
"spec/extensions/check_email_spec.rb",
|
85
|
-
"spec/extensions/check_file_system_spec.rb",
|
86
|
-
"spec/extensions/check_is_on_path_spec.rb",
|
87
|
-
"spec/extensions/check_mongo_db_spec.rb",
|
88
|
-
"spec/extensions/check_url_spec.rb",
|
89
|
-
"spec/extensions/check_value_spec.rb",
|
90
|
-
"spec/extensions/key_prefix_spec.rb",
|
91
|
-
"spec/how_to_use_spec.rb",
|
92
|
-
"spec/spec_helper.rb"
|
93
|
-
]
|
9
|
+
s.date = Time.now.utc.strftime("%Y-%m-%d")
|
10
|
+
s.homepage = 'http://github.com/alainravet/fail_fast'
|
94
11
|
|
95
|
-
|
96
|
-
|
97
|
-
s.specification_version = 3
|
12
|
+
s.summary = 'raises an error if the yaml contents of a config file does pass a test script.'
|
13
|
+
s.description = 'raises an error if the yaml contents of a config file does pass a test script.'
|
98
14
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
else
|
104
|
-
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
105
|
-
s.add_dependency(%q<activerecord>, [">= 0"])
|
106
|
-
s.add_dependency(%q<mongo>, [">= 0"])
|
107
|
-
end
|
108
|
-
else
|
109
|
-
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
110
|
-
s.add_dependency(%q<activerecord>, [">= 0"])
|
111
|
-
s.add_dependency(%q<mongo>, [">= 0"])
|
112
|
-
end
|
113
|
-
end
|
15
|
+
s.authors = 'Alain Ravet'
|
16
|
+
s.email = 'alain.ravet@gmail.com'
|
17
|
+
s.extra_rdoc_files = %w(LICENSE README.markdown)
|
18
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
114
19
|
|
20
|
+
s.platform = Gem::Platform::RUBY
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.require_paths = %w(lib)
|
24
|
+
|
25
|
+
s.add_development_dependency 'rspec', '= 1.3.2'
|
26
|
+
s.add_development_dependency 'activerecord', '>= 0'
|
27
|
+
s.add_development_dependency 'mongo', '>= 0'
|
28
|
+
s.add_development_dependency 'fakeweb'
|
29
|
+
end
|
data/lib/fail_fast/base/base.rb
CHANGED
data/lib/fail_fast/base/utils.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
class FailFast
|
2
2
|
|
3
|
-
class Params < Struct.new(:key, :value, :regexp, :options)
|
3
|
+
class Params < Struct.new(:key, :value, :regexp, :options) #:nodoc:
|
4
|
+
end
|
4
5
|
|
5
|
-
module Utils
|
6
|
+
module Utils #:nodoc:
|
6
7
|
|
7
8
|
def blank?(value)
|
8
9
|
value.nil? || (value.is_a?(String) && '' == value.strip)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class FailFast
|
2
|
+
module DirectoryExists
|
3
|
+
|
4
|
+
# Ensure the value is an existing directory
|
5
|
+
#
|
6
|
+
# Usage
|
7
|
+
# directory_exists '/tmp'
|
8
|
+
# directory_exists '/tmp', :message => 'custom message'
|
9
|
+
#
|
10
|
+
def directory_exists(path, options={})
|
11
|
+
success = File.exists?(path) && File.directory?(path)
|
12
|
+
unless success
|
13
|
+
add_error ErrorDetails.new(nil, :directory_not_found, path, options[:message])
|
14
|
+
end
|
15
|
+
success
|
16
|
+
end
|
17
|
+
|
18
|
+
# Ensure the key value is an existing directory
|
19
|
+
#
|
20
|
+
# Usage
|
21
|
+
# directory_exists_for 'foo/config'
|
22
|
+
# directory_exists_for 'foo/config', :message => 'custom message'
|
23
|
+
#
|
24
|
+
def directory_exists_for(raw_key, *params)
|
25
|
+
p = key_value_regexp_options(raw_key, params)
|
26
|
+
key, options = p.key, p.options
|
27
|
+
|
28
|
+
return false unless has_value_for raw_key, :message => options[:message]
|
29
|
+
|
30
|
+
path = value_for_deep_key(key)
|
31
|
+
success = File.exists?(path) && File.directory?(path)
|
32
|
+
unless success
|
33
|
+
add_error ErrorDetails.new(key, :directory_not_found, p.value, options[:message])
|
34
|
+
end
|
35
|
+
success
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
FailFast.send :include, FailFast::DirectoryExists
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class FailFast
|
2
|
+
module FileExists
|
3
|
+
|
4
|
+
# Ensure the value is an existing file
|
5
|
+
#
|
6
|
+
# Usage
|
7
|
+
# file_exists '~/.bash_profile'
|
8
|
+
# file_exists '~/.bash_profile', :message => 'custom message'
|
9
|
+
#
|
10
|
+
def file_exists(path, options={})
|
11
|
+
success = File.exists?(path) && File.file?(path)
|
12
|
+
unless success
|
13
|
+
add_error ErrorDetails.new(nil, :file_not_found, path, options[:message])
|
14
|
+
end
|
15
|
+
success
|
16
|
+
end
|
17
|
+
|
18
|
+
# Ensure the key value is an existing file exists
|
19
|
+
#
|
20
|
+
# Usage
|
21
|
+
# file_exists_for 'foo/config/app.yml'
|
22
|
+
# file_exists_for 'foo/config/app.yml', :message => 'custom message'
|
23
|
+
#
|
24
|
+
def file_exists_for(raw_key, *params)
|
25
|
+
p = key_value_regexp_options(raw_key, params)
|
26
|
+
key, options = p.key, p.options
|
27
|
+
|
28
|
+
return false unless has_value_for raw_key, :message => options[:message]
|
29
|
+
|
30
|
+
path = value_for_deep_key(key)
|
31
|
+
success = File.exists?(path) && File.file?(path)
|
32
|
+
unless success
|
33
|
+
add_error ErrorDetails.new(key, :file_not_found, p.value, options[:message])
|
34
|
+
end
|
35
|
+
success
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
FailFast.send :include, FailFast::FileExists
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
|
3
3
|
class FailFast
|
4
|
-
module
|
4
|
+
module HasActiveRecordDB
|
5
5
|
|
6
6
|
# Ensure the ActiveRecord connection can be established :
|
7
7
|
#
|
@@ -22,6 +22,7 @@ class FailFast
|
|
22
22
|
unless @success
|
23
23
|
add_error ErrorDetails.new(nil, :active_record_db_connection_error, @error_message, options[:message])
|
24
24
|
end
|
25
|
+
@success
|
25
26
|
end
|
26
27
|
|
27
28
|
# Ensure the ActiveRecord connection can be established :
|
@@ -49,12 +50,13 @@ class FailFast
|
|
49
50
|
unless @success
|
50
51
|
add_error ErrorDetails.new(key, :active_record_db_connection_error, @error_message, options[:message])
|
51
52
|
end
|
53
|
+
@success
|
52
54
|
end
|
53
55
|
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
|
-
FailFast.send :include, FailFast::
|
59
|
+
FailFast.send :include, FailFast::HasActiveRecordDB
|
58
60
|
|
59
61
|
# ActiveRecord::Base.establish_connection(
|
60
62
|
# :adapter => "mysql",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class FailFast
|
2
2
|
|
3
|
-
module
|
3
|
+
module HasEmail
|
4
4
|
# Usage
|
5
5
|
# has_email_for 'test/admin_email'
|
6
6
|
#
|
@@ -8,16 +8,18 @@ class FailFast
|
|
8
8
|
p = key_value_regexp_options(raw_key, params)
|
9
9
|
key, options = p.key, p.options
|
10
10
|
|
11
|
-
return unless has_value_for raw_key, :message => options[:message]
|
11
|
+
return false unless has_value_for raw_key, :message => options[:message]
|
12
12
|
|
13
13
|
value = value_for_deep_key(key)
|
14
|
-
|
14
|
+
failure = EmailValidator.invalid_email_address?(value)
|
15
|
+
if failure
|
15
16
|
add_error ErrorDetails.new(key, :not_an_email, value, options[:message])
|
16
17
|
end
|
18
|
+
!failure
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
module EmailValidator
|
22
|
+
module EmailValidator #:nodoc:
|
21
23
|
VALID_EMAIL_ADDRESS_REGEXP = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
|
22
24
|
|
23
25
|
def self.valid_email_address?(email)
|
@@ -31,4 +33,4 @@ class FailFast
|
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
FailFast.send :include, FailFast::
|
36
|
+
FailFast.send :include, FailFast::HasEmail
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class FailFast
|
2
|
-
module
|
2
|
+
module HasMongoDB
|
3
3
|
|
4
4
|
# Ensure the mongoDB server can be reached, and the db could be opened :
|
5
5
|
#
|
@@ -18,12 +18,14 @@ class FailFast
|
|
18
18
|
@conn = Mongo::Connection.new(host, port, options)
|
19
19
|
rescue Mongo::ConnectionFailure
|
20
20
|
add_error ErrorDetails.new(nil, :mongoDB_server_not_found, host, options[:message])
|
21
|
-
return
|
21
|
+
return false
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
failure = db && !@conn.database_names.include?(db)
|
25
|
+
if failure
|
25
26
|
add_error ErrorDetails.new(nil, :mongoDB_db_not_found, db, options[:message])
|
26
27
|
end
|
28
|
+
!failure
|
27
29
|
end
|
28
30
|
|
29
31
|
# Ensure the mongoDB server can be reached, and the db could be opened :
|
@@ -35,9 +37,9 @@ class FailFast
|
|
35
37
|
def has_mongoDB_for(key, *params)
|
36
38
|
p = key_value_regexp_options(key, params)
|
37
39
|
key, options = p.key, p.options
|
38
|
-
return unless has_value_for key , :message => options[:message]
|
39
|
-
return unless has_value_for "#{key}/host" , :message => options[:message]
|
40
|
-
return unless has_value_for "#{key}/database", :message => options[:message]
|
40
|
+
return false unless has_value_for key , :message => options[:message]
|
41
|
+
return false unless has_value_for "#{key}/host" , :message => options[:message]
|
42
|
+
return false unless has_value_for "#{key}/database", :message => options[:message]
|
41
43
|
|
42
44
|
|
43
45
|
value = value_for_deep_key(key)
|
@@ -47,16 +49,18 @@ class FailFast
|
|
47
49
|
@conn = Mongo::Connection.new(host, port)
|
48
50
|
rescue Mongo::ConnectionFailure
|
49
51
|
add_error ErrorDetails.new(key, :mongoDB_server_not_found, host, options[:message])
|
50
|
-
return
|
52
|
+
return false
|
51
53
|
end
|
52
54
|
|
53
55
|
must_check_db = !(false == options[:check_database])
|
54
|
-
|
56
|
+
failure = must_check_db && !@conn.database_names.include?(db)
|
57
|
+
if failure
|
55
58
|
add_error ErrorDetails.new(key, :mongoDB_db_not_found, db, options[:message])
|
56
59
|
end
|
60
|
+
!failure
|
57
61
|
end
|
58
62
|
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
62
|
-
FailFast.send :include, FailFast::
|
66
|
+
FailFast.send :include, FailFast::HasMongoDB
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class FailFast
|
2
2
|
|
3
|
-
module
|
3
|
+
module HasUrl
|
4
4
|
# Usage
|
5
5
|
# test if the url is valid :
|
6
6
|
# has_url_for 'test/server_url'
|
@@ -13,20 +13,22 @@ class FailFast
|
|
13
13
|
def has_url_for(raw_key, *params)
|
14
14
|
p = key_value_regexp_options(raw_key, params)
|
15
15
|
key, options = p.key, p.options
|
16
|
-
return unless has_value_for raw_key, :message => options[:message]
|
16
|
+
return false unless has_value_for raw_key, :message => options[:message]
|
17
17
|
|
18
18
|
value = value_for_deep_key(key)
|
19
19
|
if UrlValidator.invalid_url?(value)
|
20
20
|
add_error ErrorDetails.new(key, :not_a_url, value, options[:message])
|
21
|
-
return
|
21
|
+
return false
|
22
22
|
end
|
23
|
-
|
23
|
+
failure = true==options.delete(:reachable) && UrlValidator.unreachable_url?(value, options)
|
24
|
+
if failure
|
24
25
|
add_error ErrorDetails.new(key, :url_not_reachable, value, options[:message])
|
25
26
|
end
|
27
|
+
!failure
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
module UrlValidator
|
31
|
+
module UrlValidator #:nodoc:
|
30
32
|
IPv4_PART = /\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]/ # 0-255
|
31
33
|
VALID_URL_REGEXP = %r{
|
32
34
|
\A
|
@@ -69,4 +71,4 @@ class FailFast
|
|
69
71
|
end
|
70
72
|
end
|
71
73
|
|
72
|
-
FailFast.send :include, FailFast::
|
74
|
+
FailFast.send :include, FailFast::HasUrl
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class FailFast
|
2
|
-
module
|
2
|
+
module HasValue
|
3
3
|
|
4
4
|
# Usage
|
5
5
|
# nda_file = value_of(:nda_file)
|
@@ -40,10 +40,10 @@ class FailFast
|
|
40
40
|
elsif options.is_a?(Hash) && options[:in].is_a?(Array)
|
41
41
|
add_error ErrorDetails.new(key, :value_not_in_array, p.value, message) unless options[:in].include?(p.value)
|
42
42
|
end
|
43
|
-
no_new_error = nof_errors == errors.size
|
43
|
+
success = no_new_error = nof_errors == errors.size
|
44
44
|
end
|
45
45
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
FailFast.send :include, FailFast::
|
49
|
+
FailFast.send :include, FailFast::HasValue
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class FailFast
|
2
|
-
module
|
2
|
+
module IsOnPath
|
3
3
|
|
4
4
|
# Ensure the application is on the path
|
5
5
|
#
|
@@ -8,9 +8,11 @@ class FailFast
|
|
8
8
|
# is_on_path 'jruby', :message => 'custom message'
|
9
9
|
#
|
10
10
|
def is_on_path(app, options = {})
|
11
|
-
|
11
|
+
success = found_on_the_path(app)
|
12
|
+
unless success
|
12
13
|
add_error ErrorDetails.new(nil, :not_on_path, app, options[:message])
|
13
14
|
end
|
15
|
+
success
|
14
16
|
end
|
15
17
|
|
16
18
|
# Ensure the key value can be found on the path
|
@@ -20,19 +22,21 @@ class FailFast
|
|
20
22
|
# is_on_path_for 'file_compressor', :message => 'custom message'
|
21
23
|
#
|
22
24
|
def is_on_path_for(key, options = {})
|
23
|
-
return unless has_value_for key, :message => options[:message]
|
25
|
+
return false unless has_value_for key, :message => options[:message]
|
24
26
|
app = value_for_deep_key(key)
|
25
27
|
|
26
|
-
|
28
|
+
success = found_on_the_path(app)
|
29
|
+
unless success
|
27
30
|
add_error ErrorDetails.new(key, :not_on_path, app, options[:message])
|
28
31
|
end
|
32
|
+
success
|
29
33
|
end
|
30
34
|
|
31
35
|
private
|
32
36
|
def found_on_the_path(app)
|
33
|
-
`which #{app}` =~ /#{app}$/
|
37
|
+
!!(`which #{app}` =~ /#{app}$/)
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
37
41
|
|
38
|
-
FailFast.send :include, FailFast::
|
42
|
+
FailFast.send :include, FailFast::IsOnPath
|
data/lib/fail_fast/main.rb
CHANGED
@@ -6,11 +6,11 @@ class FailFast::ErrorDetails < Struct.new(:key, :kind, :value, :message)
|
|
6
6
|
@key, @kind, @value, @message = key, kind, value, message
|
7
7
|
end
|
8
8
|
|
9
|
-
def has_key_and_kind?(akey, akind)
|
9
|
+
def has_key_and_kind?(akey, akind) #:nodoc:
|
10
10
|
(key.to_s == akey.to_s) && kind.to_sym == akind.to_sym
|
11
11
|
end
|
12
12
|
|
13
|
-
def has_value_and_kind?(avalue, akind)
|
13
|
+
def has_value_and_kind?(avalue, akind) #:nodoc:
|
14
14
|
(value.to_s == avalue.to_s) && kind.to_sym == akind.to_sym
|
15
15
|
end
|
16
16
|
end
|