pedant 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/pedant.rb +30 -0
  2. metadata +53 -0
@@ -0,0 +1,30 @@
1
+ module Pedant
2
+ class TypeError < StandardError; end
3
+ class GuardError < StandardError; end
4
+
5
+ module Dummy
6
+ def returns(*args, &block); end
7
+ end
8
+
9
+ module Returns
10
+ def returns(sym, *klasses, &block)
11
+ old_method = instance_method(sym)
12
+ self.send(:define_method, sym) do |*args|
13
+ ret = old_method.bind(self).call(*args)
14
+
15
+ # Type check
16
+ unless klasses.empty? or klasses.any?{|klass| ret.is_a?(klass) }
17
+ raise Pedant::TypeError, "Bad return value! Got #{ret.inspect}, " \
18
+ "expected instance of #{klasses.inspect}."
19
+ end
20
+
21
+ # User-defined guard
22
+ unless block.nil? or block.call(ret)
23
+ raise Pedant::GuardError, "Did not pass user-defined guard."
24
+ end
25
+
26
+ ret
27
+ end
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pedant
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.5"
5
+ platform: ruby
6
+ authors:
7
+ - Jared Kuolt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-24 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: In defining your classes, you can define allowable return values for your methods by type and with user-defined guards.
17
+ email: me@superjared.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/pedant.rb
26
+ has_rdoc: false
27
+ homepage: http://github.com/JaredKuolt/pedant/tree/master
28
+ post_install_message:
29
+ rdoc_options: []
30
+
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: "0"
38
+ version:
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ requirements: []
46
+
47
+ rubyforge_project: pedant
48
+ rubygems_version: 1.3.1
49
+ signing_key:
50
+ specification_version: 2
51
+ summary: "Pedant: Enforcing return values... annoying yet handy!"
52
+ test_files: []
53
+