contracts 0.2.3 → 0.2.4

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/decorators.rb +10 -5
  2. metadata +38 -20
data/lib/decorators.rb CHANGED
@@ -39,11 +39,11 @@ module MethodDecorators
39
39
  if is_class_method
40
40
  decorator = klass.new(self, method(name), *args)
41
41
  @decorated_methods[:class_methods][name] = decorator
42
- is_private = self.private_methods.include?(name)
42
+ is_private = self.private_methods.include?(name.to_s)
43
43
  else
44
44
  decorator = klass.new(self, instance_method(name), *args)
45
45
  @decorated_methods[:instance_methods][name] = decorator
46
- is_private = self.private_instance_methods.include?(name)
46
+ is_private = self.private_instance_methods.include?(name.to_s)
47
47
  end
48
48
  end
49
49
 
@@ -53,11 +53,16 @@ module MethodDecorators
53
53
  # on its own, after doing it's decorating of course.
54
54
  class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
55
55
  def #{is_class_method ? "self." : ""}#{name}(*args, &blk)
56
- this = self#{is_class_method ? "" : ".class"}
57
- unless this.respond_to?(:decorated_methods) && !this.decorated_methods.nil?
56
+ current = self#{is_class_method ? "" : ".class"}
57
+ ancestors = current.ancestors
58
+ ancestors.shift # first one is just the class itself
59
+ while current && !current.respond_to?(:decorated_methods) || current.decorated_methods.nil?
60
+ current = ancestors.shift
61
+ end
62
+ if !current.respond_to?(:decorated_methods) || current.decorated_methods.nil?
58
63
  raise "Couldn't find decorator for method " + self.class.name + ":#{name}.\nDoes this method look correct to you? If you are using contracts from rspec, rspec wraps classes in it's own class.\nLook at the specs for contracts.ruby as an example of how to write contracts in this case."
59
64
  end
60
- this.decorated_methods[#{is_class_method ? ":class_methods" : ":instance_methods"}][#{name.inspect}].call_with(self, *args, &blk)
65
+ current.decorated_methods[#{is_class_method ? ":class_methods" : ":instance_methods"}][#{name.inspect}].call_with(self, *args, &blk)
61
66
  end
62
67
  #{is_private ? "private #{name.inspect}" : ""}
63
68
  ruby_eval
metadata CHANGED
@@ -1,50 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: contracts
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 4
10
+ version: 0.2.4
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Aditya Bhargava
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-06-07 00:00:00.000000000 Z
17
+
18
+ date: 2012-06-07 00:00:00 Z
13
19
  dependencies: []
14
- description: This library provides contracts for Ruby. Contracts let you clearly express
15
- how your code behaves, and free you from writing tons of boilerplate, defensive
16
- code.
20
+
21
+ description: This library provides contracts for Ruby. Contracts let you clearly express how your code behaves, and free you from writing tons of boilerplate, defensive code.
17
22
  email: bluemangroupie@gmail.com
18
23
  executables: []
24
+
19
25
  extensions: []
26
+
20
27
  extra_rdoc_files: []
21
- files:
28
+
29
+ files:
22
30
  - lib/builtin_contracts.rb
23
31
  - lib/contracts.rb
24
32
  - lib/decorators.rb
25
33
  - lib/testable.rb
26
34
  homepage: http://github.com/egonSchiele/contracts.ruby
27
35
  licenses: []
36
+
28
37
  post_install_message:
29
38
  rdoc_options: []
30
- require_paths:
39
+
40
+ require_paths:
31
41
  - lib
32
- required_ruby_version: !ruby/object:Gem::Requirement
42
+ required_ruby_version: !ruby/object:Gem::Requirement
33
43
  none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 3
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
52
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
44
60
  requirements: []
61
+
45
62
  rubyforge_project:
46
63
  rubygems_version: 1.8.25
47
64
  signing_key:
48
65
  specification_version: 3
49
66
  summary: Contracts for Ruby.
50
67
  test_files: []
68
+