fattr 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/fattr.rb +18 -6
- metadata +2 -2
data/lib/fattr.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Fattr
|
2
|
-
Fattr::VERSION = '1.0.
|
2
|
+
Fattr::VERSION = '1.0.3' unless Fattr.const_defined?(:VERSION)
|
3
3
|
def self.version() Fattr::VERSION end
|
4
4
|
|
5
5
|
class List < ::Array
|
@@ -48,16 +48,25 @@ module Fattr
|
|
48
48
|
initializer_id = initializer.object_id
|
49
49
|
__fattrs__.initializers[name] = initializer
|
50
50
|
|
51
|
+
compile = lambda do |code|
|
52
|
+
begin
|
53
|
+
module_eval code
|
54
|
+
rescue SyntaxError
|
55
|
+
raise SyntaxError, "\n#{ code }\n"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
51
59
|
# setter, block invocation caches block
|
52
|
-
|
60
|
+
code = <<-code
|
53
61
|
def #{ name }=(*value, &block)
|
54
62
|
value.unshift block if block
|
55
63
|
@#{ name } = value.first
|
56
64
|
end
|
57
65
|
code
|
66
|
+
compile[code]
|
58
67
|
|
59
68
|
# getter, providing a value or block causes it to acts as setter
|
60
|
-
|
69
|
+
code = <<-code
|
61
70
|
def #{ name }(*value, &block)
|
62
71
|
value.unshift block if block
|
63
72
|
return self.send('#{ name }=', value.first) unless value.empty?
|
@@ -65,22 +74,25 @@ module Fattr
|
|
65
74
|
@#{ name }
|
66
75
|
end
|
67
76
|
code
|
77
|
+
compile[code]
|
68
78
|
|
69
79
|
# bang method re-calls any initializer given at declaration time
|
70
|
-
|
80
|
+
code = <<-code
|
71
81
|
def #{ name }!
|
72
82
|
initializer = ObjectSpace._id2ref #{ initializer_id }
|
73
83
|
self.#{ name } = initializer.call(self)
|
74
84
|
@#{ name }
|
75
85
|
end
|
76
86
|
code
|
87
|
+
compile[code]
|
77
88
|
|
78
89
|
# query simply defers to getter - cast to bool
|
79
|
-
|
90
|
+
code = <<-code
|
80
91
|
def #{ name }?
|
81
|
-
|
92
|
+
self.#{ name }
|
82
93
|
end
|
83
94
|
code
|
95
|
+
compile[code]
|
84
96
|
|
85
97
|
fattrs << name
|
86
98
|
returned[name] = initializer
|
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: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ara T. Howard
|
@@ -9,7 +9,7 @@ autorequire: fattr
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-03-
|
12
|
+
date: 2008-03-13 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|