casting 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41fa81d5c1ff0bf53479e39ac9f655156e405bb8
4
- data.tar.gz: 82daadbcd47eff9a0a3cf570a362b621e4e7227d
3
+ metadata.gz: 36b6f16e582747ee905c40b1880686d5507f6477
4
+ data.tar.gz: b6744f050563f49a8249d9f24c2e5ed44bc2721f
5
5
  SHA512:
6
- metadata.gz: 61173fac0029519e94f9554eb0c167682da7becc73aea8e53ca83323871d8640ad13e43c2dab48961183886f4cf58151c566c7efacc870a3c9dd8c18f4582ac8
7
- data.tar.gz: be0f1e72cf3267102c238cd11291169531b76ff867e42a4396ae98659507a5b10483b1236ac5006e61acc40abfa4ad1c7ec27603264758e4d1fb007fad934cf1
6
+ metadata.gz: 21d2c3c82fd8a0ae01c458ae0f03cdd26a14248cf04e9f87796f8f7e184b27587ce71d793e2ef7b8548848dd820b806f2de0ca8a9dc462e6c6c7d35ece0abd26
7
+ data.tar.gz: 246369ff76c6c5a3c03c5ac78a7c60ef3187354a3df01f1d614218ec22444a587409c73d1c357f686f4e05f0249c1468682624979595047f258fef09974fa06e
@@ -1,4 +1,14 @@
1
- require 'redcard'
1
+ # Some features are only available in versions of Ruby
2
+ # where this method is true
3
+ def module_method_rebinding?
4
+ return @__module_method_rebinding__ if defined?(@__module_method_rebinding__)
5
+ sample_method = Enumerable.instance_method(:to_a)
6
+ @__module_method_rebinding__ = begin
7
+ !!sample_method.bind(Object.new)
8
+ rescue TypeError
9
+ false
10
+ end
11
+ end
2
12
 
3
13
  module Casting
4
14
 
@@ -28,7 +38,7 @@ module Casting
28
38
  begin
29
39
  check_valid_type
30
40
  rescue TypeError
31
- raise unless RedCard.check '2.0'
41
+ raise unless module_method_rebinding?
32
42
  @attendant = method_module || raise
33
43
  end
34
44
  self
@@ -62,7 +72,7 @@ module Casting
62
72
 
63
73
  def method_carrier(object_or_module)
64
74
  if Module === object_or_module
65
- if RedCard.check '2.0'
75
+ if module_method_rebinding?
66
76
  object_or_module
67
77
  else
68
78
  client.clone.extend(object_or_module)
@@ -1,3 +1,3 @@
1
1
  module Casting
2
- VERSION = '0.6.3'
2
+ VERSION = '0.6.4'
3
3
  end
@@ -1,9 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
- unless RedCard.check '2.0'
4
-
5
3
  describe Casting, '.delegating' do
6
4
  it 'delegates missing methods to object delegates' do
5
+ skip 'extending objects not used in this version of Ruby' if test_rebinding_methods?
6
+
7
7
  client = test_person
8
8
  client.extend(Casting::Client)
9
9
  client.delegate_missing_methods
@@ -26,6 +26,8 @@ end
26
26
  describe Casting::Delegation do
27
27
 
28
28
  it 'calls a method defined on another object of the same type' do
29
+ skip 'extending objects not used in this version of Ruby' if test_rebinding_methods?
30
+
29
31
  client = test_person
30
32
  attendant = test_person
31
33
  attendant.extend(TestPerson::Greeter)
@@ -34,6 +36,8 @@ describe Casting::Delegation do
34
36
  end
35
37
 
36
38
  it 'passes arguments to a delegated method' do
39
+ skip 'extending objects not used in this version of Ruby' if test_rebinding_methods?
40
+
37
41
  client = test_person
38
42
  attendant = test_person
39
43
  attendant.extend(TestPerson::Verbose)
@@ -42,17 +46,19 @@ describe Casting::Delegation do
42
46
  end
43
47
 
44
48
  it 'delegates when given a module' do
49
+ skip 'extending objects not used in this version of Ruby' if test_rebinding_methods?
50
+
45
51
  client = test_person
46
52
  delegation = Casting::Delegation.new('greet', client).to(TestPerson::Greeter)
47
53
  assert_equal 'hello', delegation.call
48
54
  end
49
55
 
50
56
  it 'does not delegate when given a class' do
57
+ skip 'extending objects not used in this version of Ruby' if test_rebinding_methods?
58
+
51
59
  client = test_person
52
60
  assert_raises(TypeError){
53
61
  Casting::Delegation.new('class_defined', client).to(Unrelated)
54
62
  }
55
63
  end
56
- end
57
-
58
- end # RedCard
64
+ end
@@ -1,10 +1,10 @@
1
1
  require 'test_helper'
2
2
 
3
- if RedCard.check '2.0'
4
-
5
3
  describe Casting::Delegation do
6
4
 
7
5
  it 'finds the module defining a method and uses it to delegate' do
6
+ skip 'not able to bind module methods in this version of Ruby' unless test_rebinding_methods?
7
+
8
8
  client = test_person
9
9
  attendant = Unrelated.new
10
10
  delegation = Casting::Delegation.new('unrelated', client).to(attendant)
@@ -12,12 +12,12 @@ describe Casting::Delegation do
12
12
  end
13
13
 
14
14
  it 'does not delegate to methods defined in classes' do
15
+ skip 'not able to bind module methods in this version of Ruby' unless test_rebinding_methods?
16
+
15
17
  client = test_person
16
18
  attendant = Unrelated.new
17
19
  assert_raises(TypeError){
18
20
  Casting::Delegation.new('class_defined', client).to(attendant)
19
21
  }
20
22
  end
21
- end
22
-
23
- end # RedCard
23
+ end
data/test/test_helper.rb CHANGED
@@ -81,3 +81,18 @@ end
81
81
  def test_person
82
82
  TestPerson.new
83
83
  end
84
+
85
+
86
+
87
+ # This is a different implementation of module_method_rebinding?
88
+ # created in order to check that the behavior of the code is correct.
89
+ #
90
+ # This method is used in tests and module_method_rebinding? is used
91
+ # in the library code.
92
+ def test_rebinding_methods?
93
+ unbound = Enumerable.instance_method(:count)
94
+ unbound.bind(Object.new)
95
+ true
96
+ rescue TypeError
97
+ false
98
+ end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Gay
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-10 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: redcard
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: 1.1.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- version: 1.1.0
11
+ date: 2013-11-14 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description: |-
28
14
  Casting assists in method delegation which preserves the binding of 'self' to the object receiving a message.
29
15
 
@@ -85,4 +71,3 @@ test_files:
85
71
  - test/delegation_test.rb
86
72
  - test/method_consolidator_test.rb
87
73
  - test/missing_method_client_test.rb
88
- has_rdoc: