fattr 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/a.rb +42 -0
- data/fattr.gemspec +2 -2
- data/lib/fattr.rb +12 -12
- data/test/fattr.rb +6 -0
- metadata +3 -2
data/a.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'fattr'
|
3
|
+
|
4
|
+
class A
|
5
|
+
class << A
|
6
|
+
fattr(:x, :inheritable => true){ 42 }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class B < A; end
|
11
|
+
|
12
|
+
class C < B; end
|
13
|
+
|
14
|
+
|
15
|
+
p C.x
|
16
|
+
p B.x
|
17
|
+
p A.x
|
18
|
+
puts
|
19
|
+
|
20
|
+
B.x = 42.0
|
21
|
+
|
22
|
+
p C.x
|
23
|
+
p B.x
|
24
|
+
p A.x
|
25
|
+
puts
|
26
|
+
|
27
|
+
C.x! # force re-initialization from parent(s)
|
28
|
+
|
29
|
+
p C.x
|
30
|
+
p B.x
|
31
|
+
p A.x
|
32
|
+
puts
|
33
|
+
|
34
|
+
|
35
|
+
class K
|
36
|
+
end
|
37
|
+
module M
|
38
|
+
fattr(:x, :inheritable => true){ 42 }
|
39
|
+
end
|
40
|
+
K.extend(M)
|
41
|
+
|
42
|
+
p K.x
|
data/fattr.gemspec
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
Gem::Specification::new do |spec|
|
5
5
|
spec.name = "fattr"
|
6
6
|
spec.description = 'fattr.rb is a "fatter attr" for ruby'
|
7
|
-
spec.version = "2.
|
7
|
+
spec.version = "2.1.0"
|
8
8
|
spec.platform = Gem::Platform::RUBY
|
9
9
|
spec.summary = "fattr"
|
10
10
|
|
11
|
-
spec.files = ["fattr.gemspec", "lib", "lib/fattr.rb", "Rakefile", "README", "README.erb", "samples", "samples/a.rb", "samples/b.rb", "samples/c.rb", "samples/d.rb", "samples/e.rb", "samples/f.rb", "samples/g.rb", "samples/h.rb", "test", "test/fattr.rb"]
|
11
|
+
spec.files = ["a.rb", "fattr.gemspec", "lib", "lib/fattr.rb", "Rakefile", "README", "README.erb", "samples", "samples/a.rb", "samples/b.rb", "samples/c.rb", "samples/d.rb", "samples/e.rb", "samples/f.rb", "samples/g.rb", "samples/h.rb", "test", "test/fattr.rb"]
|
12
12
|
spec.executables = []
|
13
13
|
|
14
14
|
|
data/lib/fattr.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Fattr
|
2
|
-
Fattr::Version = '2.
|
2
|
+
Fattr::Version = '2.1.0' unless Fattr.const_defined?(:Version)
|
3
3
|
def self.version() Fattr::Version end
|
4
4
|
|
5
5
|
class List < ::Array
|
@@ -65,25 +65,25 @@ module Fattr
|
|
65
65
|
default = config['default'] if config.has_key?('default')
|
66
66
|
|
67
67
|
inheritable = false
|
68
|
-
if
|
68
|
+
if Module===self
|
69
69
|
inheritable = config[:inheritable] if config.has_key?(:inheritable)
|
70
70
|
inheritable = config['inheritable'] if config.has_key?('inheritable')
|
71
71
|
end
|
72
72
|
|
73
73
|
initialize = (
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
ancestors[1].send(name)
|
81
|
-
else
|
82
|
-
default
|
74
|
+
if inheritable
|
75
|
+
lambda do
|
76
|
+
parents = ancestors[1..-1]
|
77
|
+
catch(:value) do
|
78
|
+
parents.each do |parent|
|
79
|
+
throw(:value, parent.send(name)) if parent.respond_to?(name)
|
83
80
|
end
|
81
|
+
block ? block.call : default
|
84
82
|
end
|
85
83
|
end
|
86
|
-
|
84
|
+
else
|
85
|
+
block || lambda{ default }
|
86
|
+
end
|
87
87
|
)
|
88
88
|
|
89
89
|
initializer = lambda do |this|
|
data/test/fattr.rb
CHANGED
@@ -65,21 +65,27 @@ Testing Fattr do
|
|
65
65
|
a = Class.new{ Fattr :x, :default => 42, :inheritable => true }
|
66
66
|
b = Class.new(a)
|
67
67
|
c = Class.new(b)
|
68
|
+
|
68
69
|
def a.name() 'a' end
|
69
70
|
def b.name() 'b' end
|
70
71
|
def c.name() 'c' end
|
72
|
+
|
71
73
|
assert{ c.x==42 }
|
72
74
|
assert{ b.x==42 }
|
73
75
|
assert{ a.x==42 }
|
76
|
+
|
74
77
|
assert{ b.x=42.0 }
|
75
78
|
assert{ b.x==42.0 }
|
76
79
|
assert{ a.x==42 }
|
80
|
+
|
77
81
|
assert{ a.x='forty-two' }
|
78
82
|
assert{ a.x=='forty-two' }
|
79
83
|
assert{ b.x==42.0 }
|
84
|
+
|
80
85
|
assert{ b.x! }
|
81
86
|
assert{ b.x=='forty-two' }
|
82
87
|
assert{ b.x='FORTY-TWO' }
|
88
|
+
|
83
89
|
assert{ c.x! }
|
84
90
|
assert{ c.x=='FORTY-TWO' }
|
85
91
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fattr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ara T. Howard
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-12 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,6 +22,7 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
+
- a.rb
|
25
26
|
- fattr.gemspec
|
26
27
|
- lib/fattr.rb
|
27
28
|
- Rakefile
|