rubysl-delegate 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -3
- data/lib/rubysl/delegate/delegate.rb +35 -10
- data/lib/rubysl/delegate/version.rb +1 -1
- data/rubysl-delegate.gemspec +1 -0
- metadata +27 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32a72677c8916a5d20eaaa8833b7db5df034580d
|
4
|
+
data.tar.gz: 1af2b0d39b67dec79a7684ee0c542f371c3ddb76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb3f4bad019d173c1130fda7c41663d425275fafaa368879a4666e53d0c69d651b588a02a73c1ce800822ddf95a9032b8c8836badfd5ef4ddf91ab91a9feebb7
|
7
|
+
data.tar.gz: 8663a6e30af98ccafc864f254f6ea3ac8451ad34b0c291869d477257831fc6f5814dadc9324f4acb53b553714af50170034313f0da2ecfefd089db2247a53413
|
data/.travis.yml
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
language: ruby
|
2
2
|
env:
|
3
3
|
- RUBYLIB=lib
|
4
|
-
|
4
|
+
- RUBYLIB=
|
5
|
+
script: mspec spec
|
5
6
|
rvm:
|
6
|
-
-
|
7
|
-
- rbx-
|
7
|
+
- 2.0.0
|
8
|
+
- rbx-2.1.1
|
9
|
+
matrix:
|
10
|
+
exclude:
|
11
|
+
- rvm: 2.0.0
|
12
|
+
env: RUBYLIB=lib
|
13
|
+
- rvm: rbx-2.1.1
|
14
|
+
env: RUBYLIB=
|
@@ -93,11 +93,7 @@ class Delegator < BasicObject
|
|
93
93
|
# of this object's and \_\_getobj\_\_ methods.
|
94
94
|
#
|
95
95
|
def methods(all=true)
|
96
|
-
|
97
|
-
__getobj__.methods | super
|
98
|
-
else
|
99
|
-
__getobj__.singleton_methods | singleton_methods
|
100
|
-
end
|
96
|
+
__getobj__.methods(all) | super
|
101
97
|
end
|
102
98
|
|
103
99
|
#
|
@@ -134,6 +130,9 @@ class Delegator < BasicObject
|
|
134
130
|
__getobj__ != obj
|
135
131
|
end
|
136
132
|
|
133
|
+
#
|
134
|
+
# Delegates ! to the \_\_getobj\_\_
|
135
|
+
#
|
137
136
|
def !
|
138
137
|
!__getobj__
|
139
138
|
end
|
@@ -158,7 +157,7 @@ class Delegator < BasicObject
|
|
158
157
|
# Serialization support for the object returned by \_\_getobj\_\_.
|
159
158
|
#
|
160
159
|
def marshal_dump
|
161
|
-
ivars = instance_variables.reject {|var| /\A@delegate_/ =~ var
|
160
|
+
ivars = instance_variables.reject {|var| /\A@delegate_/ =~ var}
|
162
161
|
[
|
163
162
|
:__v2__,
|
164
163
|
ivars, ivars.map{|var| instance_variable_get(var)},
|
@@ -231,6 +230,34 @@ end
|
|
231
230
|
# and even to change the object being delegated to at a later time with
|
232
231
|
# #__setobj__.
|
233
232
|
#
|
233
|
+
# class User
|
234
|
+
# def born_on
|
235
|
+
# Date.new(1989, 09, 10)
|
236
|
+
# end
|
237
|
+
# end
|
238
|
+
#
|
239
|
+
# class UserDecorator < SimpleDelegator
|
240
|
+
# def birth_year
|
241
|
+
# born_on.year
|
242
|
+
# end
|
243
|
+
# end
|
244
|
+
#
|
245
|
+
# decorated_user = UserDecorator.new(User.new)
|
246
|
+
# decorated_user.birth_year #=> 1989
|
247
|
+
# decorated_user.__getobj__ #=> #<User: ...>
|
248
|
+
#
|
249
|
+
# A SimpleDelegator instance can take advantage of the fact that SimpleDelegator
|
250
|
+
# is a subclass of +Delegator+ to call <tt>super</tt> to have methods called on
|
251
|
+
# the object being delegated to.
|
252
|
+
#
|
253
|
+
# class SuperArray < SimpleDelegator
|
254
|
+
# def [](*args)
|
255
|
+
# super + 1
|
256
|
+
# end
|
257
|
+
# end
|
258
|
+
#
|
259
|
+
# SuperArray.new([1])[0] #=> 2
|
260
|
+
#
|
234
261
|
# Here's a simple example that takes advantage of the fact that
|
235
262
|
# SimpleDelegator's delegation object can be changed at any time.
|
236
263
|
#
|
@@ -289,8 +316,7 @@ class SimpleDelegator<Delegator
|
|
289
316
|
end
|
290
317
|
end
|
291
318
|
|
292
|
-
# :
|
293
|
-
def Delegator.delegating_block(mid)
|
319
|
+
def Delegator.delegating_block(mid) # :nodoc:
|
294
320
|
lambda do |*args, &block|
|
295
321
|
target = self.__getobj__
|
296
322
|
begin
|
@@ -300,7 +326,6 @@ def Delegator.delegating_block(mid)
|
|
300
326
|
end
|
301
327
|
end
|
302
328
|
end
|
303
|
-
# :startdoc:
|
304
329
|
|
305
330
|
#
|
306
331
|
# The primary interface to this library. Use to setup delegation when defining
|
@@ -393,4 +418,4 @@ if __FILE__ == $0
|
|
393
418
|
p foo.test == foo2.test # => true
|
394
419
|
p foo2.iter{[55,true]} # => true
|
395
420
|
foo2.error # raise error!
|
396
|
-
end
|
421
|
+
end
|
data/rubysl-delegate.gemspec
CHANGED
metadata
CHANGED
@@ -1,57 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysl-delegate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Shirai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: mspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.5'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubysl-prettyprint
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
55
69
|
description: Ruby standard library delegate.
|
56
70
|
email:
|
57
71
|
- brixen@gmail.com
|
@@ -59,8 +73,8 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .travis.yml
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
64
78
|
- Gemfile
|
65
79
|
- LICENSE
|
66
80
|
- README.md
|
@@ -108,12 +122,12 @@ require_paths:
|
|
108
122
|
- lib
|
109
123
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
124
|
requirements:
|
111
|
-
- - ~>
|
125
|
+
- - "~>"
|
112
126
|
- !ruby/object:Gem::Version
|
113
127
|
version: '2.0'
|
114
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
129
|
requirements:
|
116
|
-
- -
|
130
|
+
- - ">="
|
117
131
|
- !ruby/object:Gem::Version
|
118
132
|
version: '0'
|
119
133
|
requirements: []
|
@@ -151,3 +165,4 @@ test_files:
|
|
151
165
|
- spec/delegator/untaint_spec.rb
|
152
166
|
- spec/delegator/untrust_spec.rb
|
153
167
|
- spec/fixtures/classes.rb
|
168
|
+
has_rdoc:
|