matholroyd-dbc 0.1.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.
- data/LICENSE +20 -0
- data/README.rdoc +22 -0
- data/Rakefile +48 -0
- data/VERSION.yml +4 -0
- data/lib/dbc.rb +35 -0
- data/spec/dbc_spec.rb +7 -0
- data/spec/spec_helper.rb +9 -0
- metadata +61 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Mat Holroyd
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
= dbc
|
2
|
+
|
3
|
+
Design By Contract implemented for Ruby.
|
4
|
+
|
5
|
+
== Philosophy
|
6
|
+
|
7
|
+
DBC, among other things, is a staple of the design concept, "Fail early, fail hard." That is, it is better to catch problems earlier on rather than later. DBC does this by specifying input/output requirements of code, typically functions. When these constraints are broken, the DBC library causes a hard-fail of the system.
|
8
|
+
|
9
|
+
A classic example of DBC in actions would be to checking the divisor in a division is non-zero. This would be written as
|
10
|
+
|
11
|
+
def division(a, b)
|
12
|
+
DBC.require(b != 0, "Divisor must be non-zero")
|
13
|
+
|
14
|
+
a / b
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
See http://en.wikipedia.org/wiki/Design_by_contract for more details.
|
19
|
+
|
20
|
+
== Copyright
|
21
|
+
|
22
|
+
Copyright (c) 2009 Mat Holroyd. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "dbc"
|
8
|
+
gem.summary = %Q{TODO}
|
9
|
+
gem.email = "matholroyd@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/matholroyd/dbc"
|
11
|
+
gem.authors = ["Mat Holroyd"]
|
12
|
+
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'spec/rake/spectask'
|
20
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
21
|
+
spec.libs << 'lib' << 'spec'
|
22
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
23
|
+
end
|
24
|
+
|
25
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
28
|
+
spec.rcov = true
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task :default => :spec
|
33
|
+
|
34
|
+
require 'rake/rdoctask'
|
35
|
+
Rake::RDocTask.new do |rdoc|
|
36
|
+
if File.exist?('VERSION.yml')
|
37
|
+
config = YAML.load(File.read('VERSION.yml'))
|
38
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
39
|
+
else
|
40
|
+
version = ""
|
41
|
+
end
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "dbc #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
48
|
+
|
data/VERSION.yml
ADDED
data/lib/dbc.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
class DBC
|
2
|
+
def self.require(condition, message = "")
|
3
|
+
unless condition
|
4
|
+
error('Pre', message, caller)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.require_not_blank(string, message = "")
|
9
|
+
if string.strip.blank?
|
10
|
+
error('Pre', message, caller)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.assert(condition, message = "")
|
15
|
+
unless condition
|
16
|
+
error('Assert', message, caller)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.ensure(condition, message = "")
|
21
|
+
unless condition
|
22
|
+
error('Post', message, caller)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.fail(message = "")
|
27
|
+
error('Fail', message, caller)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def self.error(type, message, caller)
|
33
|
+
raise RuntimeError.new("#{type}-condition failed: #{message}\nTrace was: #{caller.join("\n")}")
|
34
|
+
end
|
35
|
+
end
|
data/spec/dbc_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: matholroyd-dbc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mat Holroyd
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-13 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: matholroyd@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- LICENSE
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- VERSION.yml
|
30
|
+
- lib/dbc.rb
|
31
|
+
- spec/dbc_spec.rb
|
32
|
+
- spec/spec_helper.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/matholroyd/dbc
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --charset=UTF-8
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.2.0
|
56
|
+
signing_key:
|
57
|
+
specification_version: 2
|
58
|
+
summary: TODO
|
59
|
+
test_files:
|
60
|
+
- spec/dbc_spec.rb
|
61
|
+
- spec/spec_helper.rb
|