safe-me 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -37,7 +37,11 @@ The DSL ist very simple. Let me explain on an example:
37
37
  #for each argument the method takes, you have to call argument
38
38
  #with the type as parameter
39
39
  argument Integer
40
- end
40
+
41
+ #there is also a method called arguments, which takes multiple types
42
+ #so you don't have to call argument for every single arg
43
+ arguments String, Array.ofType(Integer), unchecked
44
+ end
41
45
  end
42
46
 
43
47
  For now there are 5 kinds of possible argument types.
@@ -24,6 +24,12 @@ module SafeMe
24
24
  def argument type
25
25
  @types << type
26
26
  end
27
+
28
+ def arguments *types
29
+ types.each do |t|
30
+ argument t
31
+ end
32
+ end
27
33
 
28
34
  def quacks_like type
29
35
  DuckType.new type
@@ -1,6 +1,6 @@
1
1
  module SafeMe
2
2
  unless defined?(SafeMe::VERSION)
3
- VERSION = '0.9.2'
3
+ VERSION = '0.9.3'
4
4
  LIBDIR = File.expand_path(File.dirname(__FILE__) + '/../../lib')
5
5
  end
6
6
  end
data/safe/foo_safe.rb CHANGED
@@ -23,4 +23,8 @@ safe Foo do
23
23
  argument Integer
24
24
  argument unchecked
25
25
  end
26
+
27
+ for_method :test_arguments do
28
+ arguments Integer, Integer, String, nilable(Array.ofType(String))
29
+ end
26
30
  end
data/spec/classes/foo.rb CHANGED
@@ -18,4 +18,8 @@ class Foo
18
18
  def unchecked_method a,b
19
19
  "#{b} should be unchecked"
20
20
  end
21
+
22
+ def test_arguments a,b,c,d
23
+ "works"
24
+ end
21
25
  end
@@ -44,5 +44,13 @@ describe SafeMe do
44
44
  lambda{Foo.new.unchecked_method 1, [1,2,3,"a"]}.should_not raise_error(ArgumentError)
45
45
  end
46
46
  end
47
+
48
+ describe "adding typechecking to a method with only one call of arguments for several args" do
49
+ it "should only allow those types as args" do
50
+ lambda{Foo.new.test_arguments 1, 2, "foo", nil}.should_not raise_error(ArgumentError)
51
+ lambda{Foo.new.test_arguments "1", "2", 1, [1,2,3]}.should raise_error(ArgumentError)
52
+ end
53
+ end
54
+
47
55
  end
48
56
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safe-me
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 9
9
- - 2
10
- version: 0.9.2
8
+ - 3
9
+ version: 0.9.3
11
10
  platform: ruby
12
11
  authors:
13
12
  - Dario Rexin
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-10-24 00:00:00 +02:00
17
+ date: 2010-11-09 00:00:00 +01:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 0
32
30
  version: "0"
@@ -78,7 +76,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
76
  requirements:
79
77
  - - ">="
80
78
  - !ruby/object:Gem::Version
81
- hash: 3
82
79
  segments:
83
80
  - 0
84
81
  version: "0"
@@ -87,7 +84,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
84
  requirements:
88
85
  - - ">="
89
86
  - !ruby/object:Gem::Version
90
- hash: 3
91
87
  segments:
92
88
  - 0
93
89
  version: "0"