anise 0.7.0 → 0.8.0

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/demo/05_variables.md DELETED
@@ -1,45 +0,0 @@
1
- # Variable Annotations
2
-
3
- Create a class that uses the `Annotative::Variables` mixin.
4
-
5
- class X
6
- extend Anise::Annotative::Variables
7
-
8
- variable_annotator :@doc
9
-
10
- @doc = "See what I mean?"
11
-
12
- def see
13
- puts "Yes, I see!"
14
- end
15
- end
16
-
17
- See that it is set.
18
-
19
- X.ann(:see, :@doc).should == "See what I mean?"
20
-
21
- Variable annotations can override the standard annotation procedure with a
22
- custom procedure.
23
-
24
- class Y
25
- extend Anise::Annotative::Variables
26
-
27
- def self.list
28
- @list ||= []
29
- end
30
-
31
- variable_annotator :@doc do |method, value|
32
- list << [method, value]
33
- end
34
-
35
- @doc = "See here!"
36
-
37
- def see
38
- puts "Yes, I see!"
39
- end
40
- end
41
-
42
- See that it is set.
43
-
44
- Y.list #=> [[:see, "See here!"]]
45
-
data/demo/applique/ae.rb DELETED
@@ -1 +0,0 @@
1
- require 'ae/should'
@@ -1 +0,0 @@
1
- require 'anise'
@@ -1,26 +0,0 @@
1
- = TOPLEVEL Annotations
2
-
3
- Extending Object with `Annotations` should make them available to all classes.
4
-
5
- class ::Object
6
- extend Anise::Annotations
7
- end
8
-
9
- Given a example class X we can apply annotations to it using the #ann method.
10
-
11
- class X
12
- ann :x1, :a=>1
13
- ann :x1, :b=>2
14
- end
15
-
16
- We can then use #ann to lookup the set annotations.
17
-
18
- X.ann(:x1,:a).should == 1
19
-
20
- The #ann method is a public interface, so we can define annotation externally as well.
21
-
22
- X.ann :x1, :a => 2
23
- X.ann(:x1, :a).should == 2
24
-
25
- Alternatively the `Annotations` module could be included into the `Module` class.
26
-
@@ -1,20 +0,0 @@
1
- = TOPLEVEL Annotated Attributes
2
-
3
- Including `AnnotatedAttributes` at the toplevel, i.e. Object, will make
4
- annotated attributes univerally available.
5
-
6
- class ::Object
7
- extend Anise::Annotative::Attributes
8
- end
9
-
10
- Create a class that uses it.
11
-
12
- class X
13
- attr :a, :count=>1
14
- end
15
-
16
- X.ann(:a, :count) #=> 1
17
-
18
- Alternatively the `Annotative::Attributes` module could be included into
19
- the `Module` class.
20
-
data/lib/anise.yml DELETED
@@ -1,62 +0,0 @@
1
- ---
2
- source:
3
- - meta
4
- authors:
5
- - name: trans
6
- email: transfire@gmail.com
7
- copyrights:
8
- - holder: Rubyworks
9
- year: '2008'
10
- license: BSD-2-Clause
11
- requirements:
12
- - name: qed
13
- groups:
14
- - test
15
- development: true
16
- - name: ae
17
- groups:
18
- - test
19
- development: true
20
- - name: citron
21
- groups:
22
- - test
23
- development: true
24
- - name: detroit
25
- groups:
26
- - build
27
- development: true
28
- dependencies: []
29
- alternatives: []
30
- conflicts: []
31
- repositories:
32
- - uri: http://github.com/rubyworks/anise.git
33
- scm: git
34
- name: public
35
- resources:
36
- - uri: http://rubyworks.githuib.com/anise
37
- name: home
38
- type: home
39
- - uri: http://github.com/rubyworks/anise
40
- name: code
41
- type: code
42
- - uri: http://github.com/rubyworks/anise/issues
43
- name: bugs
44
- type: bugs
45
- - uri: http://chat.us.freenode.net/rubyworks
46
- name: chat
47
- type: chat
48
- - uri: http://groups.google.com/groups/rubyworks-mailinglist
49
- name: mail
50
- type: mail
51
- extra: {}
52
- load_path:
53
- - lib
54
- revision: 0
55
- created: '2008-02-21'
56
- summary: Dynamic Annotation System
57
- title: Anise
58
- version: 0.7.0
59
- name: anise
60
- description: Anise is an annotations systems for the Ruby programming lanaguage.
61
- organization: Rubyworks
62
- date: '2012-04-20'
@@ -1,173 +0,0 @@
1
- testcase Anise::Annotations do
2
-
3
- context "annotations can be defined" do
4
-
5
- cX = Class.new do
6
- extend Anise::Annotations
7
- def x1 ; end
8
- ann :x1, :a=>1
9
- ann :x1, :b=>2
10
- end
11
-
12
- test "01" do
13
- cX.ann(:x1,:a) == cX.ann(:x1,:a)
14
- end
15
-
16
- test "02" do
17
- cX.ann(:x1,:a).object_id == cX.ann(:x1,:a).object_id
18
- end
19
-
20
- test "03" do
21
- cX.ann(:x1,:a) == 1
22
- end
23
-
24
- test "04" do
25
- cX.ann :x1, :a => 2
26
- cX.ann(:x1,:a) == 2
27
- end
28
-
29
- end
30
-
31
- context "parent annotations pass to subclass" do
32
-
33
- cX = Class.new do
34
- extend Anise::Annotations
35
- def x1 ; end
36
- ann :x1, :a=>1
37
- ann :x1, :b=>2
38
- end
39
-
40
- cY = Class.new(cX)
41
-
42
- test "01" do
43
- cY.ann(:x1,:a) == cY.ann(:x1,:a)
44
- end
45
-
46
- test "02" do
47
- cY.ann(:x1,:a).object_id == cY.ann(:x1,:a).object_id
48
- end
49
-
50
- test "03" do
51
- cY.ann(:x1,:a) == 1
52
- end
53
-
54
- test "04" do
55
- cY.ann(:x1,:b) == 2
56
- end
57
-
58
- test "05" do
59
- cY.ann :x1,:a => 2
60
- cY.ann(:x1,:a) == 2 &&
61
- cY.ann(:x1,:b) == 2
62
- end
63
-
64
- end
65
-
66
- context "subclass can override parent annotation" do
67
-
68
- cX = Class.new do
69
- extend Anise::Annotations
70
- ann :foo, Integer
71
- end
72
-
73
- cY = Class.new(cX) do
74
- ann :foo, String
75
- end
76
-
77
- test "01" do
78
- cX.ann(:foo, :class) == Integer
79
- end
80
-
81
- test "02" do
82
- cY.ann(:foo, :class) == String
83
- end
84
-
85
- end
86
-
87
- context "subclass can override while parent also passes thru" do
88
-
89
- cX = Class.new do
90
- extend Anise::Annotations
91
- ann :foo, :doc => "hello"
92
- ann :foo, :bar => []
93
- end
94
-
95
- cY = Class.new(cX) do
96
- ann :foo, :class=>String, :doc=>"bye"
97
- end
98
-
99
- test "01" do
100
- cX.ann(:foo,:doc) == "hello"
101
- end
102
-
103
- test "02" do
104
- cX.ann(:foo) == {:doc=>"hello", :bar=>[]}
105
- end
106
-
107
- test "03" do
108
- cX.ann(:foo,:bar) << "1"
109
- cX.ann(:foo,:bar) == ["1"]
110
- end
111
-
112
- test "04" do
113
- cY.ann(:foo,:doc) == "bye"
114
- end
115
-
116
- test "05" do
117
- #Y.ann(:foo,:bar) == nil
118
- cY.ann(:foo,:bar) == ["1"]
119
- end
120
-
121
- test "06" do
122
- cY.ann(:foo, :doc => "cap")
123
- cY.ann(:foo, :doc) == "cap"
124
- end
125
-
126
- test "07" do
127
- cY.ann!(:foo,:bar) << "2"
128
-
129
- cY.ann(:foo,:bar) == ["1", "2"] &&
130
- cY.ann(:foo,:bar) == ["1", "2"] &&
131
- cX.ann(:foo,:bar) == ["1"]
132
- end
133
-
134
- end
135
-
136
- context "example of using annotations for validation" do
137
-
138
- cX = Class.new do
139
- extend Anise::Annotations
140
-
141
- attr :a
142
-
143
- ann :@a, :valid => lambda{ |x| x.is_a?(Integer) }
144
- ann :a, :class => Integer
145
-
146
- def initialize(a)
147
- @a = a
148
- end
149
-
150
- def validate
151
- instance_variables.each do |iv|
152
- if validator = self.class.ann(iv)[:valid]
153
- value = instance_variable_get(iv)
154
- unless validator.call(value)
155
- raise "Invalid value #{value} for #{iv}"
156
- end
157
- end
158
- end
159
- end
160
- end
161
-
162
- test "annotation class" do
163
- cX.ann(:a, :class) == Integer
164
- end
165
-
166
- test "annotation validate" do
167
- r = cX.new(1)
168
- r.validate
169
- end
170
-
171
- end
172
-
173
- end
@@ -1,46 +0,0 @@
1
- testcase Anise::Annotative::Attributes do
2
-
3
- context "general" do
4
-
5
- cX = Class.new do
6
- extend Anise::Annotative::Attributes
7
- attr :q
8
- attr :a, :x => 1
9
- end
10
-
11
- test "attr :a" do
12
- cX.ann(:a) == {:x=>1}
13
- end
14
-
15
- end
16
-
17
- context "attr" do
18
-
19
- cA = Class.new do
20
- extend Anise::Annotative::Attributes
21
- attr :x, :cast=>"to_s"
22
- end
23
-
24
- test do
25
- cA.ann(:x,:cast) == "to_s"
26
- end
27
-
28
- end
29
-
30
- context "attr_accessor" do
31
-
32
- cA = Class.new do
33
- extend Anise::Annotative::Attributes
34
- attr_accessor :x, :cast=>"to_s"
35
- end
36
-
37
- test do
38
- a = cA.new
39
- r = cA.instance_attributes - [:taguri]
40
- r == [:x]
41
- end
42
-
43
- end
44
-
45
- end
46
-
@@ -1,341 +0,0 @@
1
- # The intent of this testcase is test the variant annotaiton modules
2
- # in conjunction, to make sure they can all be used together without
3
- # conflict.
4
- #
5
- # All good intentions aside these cases need some *love*, as they are
6
- # really just other cases thrown together and not really thought out
7
- # as such. Still, something is better than nothing.
8
-
9
- testcase "Combined Usage" do
10
-
11
- context "simple co-existence of annotated methods and attributes" do
12
-
13
- cX = Class.new do
14
- extend Anise::Annotative::Methods
15
- extend Anise::Annotative::Attributes
16
- end
17
-
18
- test "initialize" do
19
- cX.new
20
- end
21
-
22
- end
23
-
24
- context "method annotations work" do
25
-
26
- cX = Class.new do
27
- extend Anise::Annotative::Methods
28
- extend Anise::Annotative::Attributes
29
-
30
- method_annotator :doc
31
-
32
- doc "a-okay captain"
33
- def x; end
34
- end
35
-
36
- test "doc is defined for method" do
37
- cX.ann(:x,:doc) == "a-okay captain"
38
- end
39
-
40
- end
41
-
42
- context "attribute annotations work" do
43
-
44
- cX = Class.new do
45
- extend Anise::Annotative::Methods
46
- extend Anise::Annotative::Attributes
47
-
48
- attr :x, :doc => "still okay"
49
- end
50
-
51
- test "annotation defined for attribute" do
52
- cX.ann(:x,:doc) == "still okay"
53
- end
54
-
55
- end
56
-
57
- context "both method and attribute annotations work" do
58
-
59
- cX = Class.new do
60
- extend Anise::Annotative::Methods
61
- extend Anise::Annotative::Attributes
62
-
63
- method_annotator :doc
64
-
65
- attr :x, :doc => "still okay"
66
-
67
- doc "sure does"
68
- def y; end
69
- end
70
-
71
- test "annotation defined for attribute" do
72
- cX.ann(:x,:doc) == "still okay"
73
- end
74
-
75
- test "doc is defined for method" do
76
- cX.ann(:y,:doc) == "sure does"
77
- end
78
-
79
- end
80
-
81
- context "using an annotation for attribute validation" do
82
-
83
- cX = Class.new do
84
- extend Anise::Annotations
85
- extend Anise::Annotative::Methods
86
- extend Anise::Annotative::Attributes
87
-
88
- attr :a
89
-
90
- ann :@a, :valid => lambda{ |x| x.is_a?(Integer) }
91
- ann :a, :class => Integer
92
-
93
- def initialize(a)
94
- @a = a
95
- end
96
-
97
- def validate
98
- instance_variables.each do |iv|
99
- if validator = self.class.ann(iv)[:valid]
100
- value = instance_variable_get(iv)
101
- unless validator.call(value)
102
- raise "Invalid value #{value} for #{iv}"
103
- end
104
- end
105
- end
106
- end
107
- end
108
-
109
- test "class" do
110
- cX.ann(:a, :class) == Integer
111
- end
112
-
113
- test "validate" do
114
- x = cX.new(1)
115
- x.validate
116
- end
117
-
118
- end
119
-
120
- context "2" do
121
-
122
- cX = Class.new do
123
- extend Anise::Annotations
124
- extend Anise::Annotative::Methods
125
- extend Anise::Annotative::Attributes
126
-
127
- def x1 ; end
128
-
129
- #annotator :ann
130
- ann :x1, :a=>1
131
- ann :x1, :b=>2
132
- end
133
-
134
- test "01" do
135
- cX.ann(:x1,:a) == cX.ann(:x1,:a)
136
- end
137
-
138
- test "02" do
139
- cX.ann(:x1,:a).object_id == cX.ann(:x1,:a).object_id
140
- end
141
-
142
- test "03" do
143
- cX.ann :x1, :a => 2
144
- cX.ann(:x1,:a) == 2
145
- end
146
-
147
- end
148
-
149
- context "3" do
150
-
151
- cX = Class.new do
152
- extend Anise::Annotations
153
- extend Anise::Annotative::Methods
154
- extend Anise::Annotative::Attributes
155
-
156
- def x1 ; end
157
-
158
- #annotator :ann
159
- ann :x1, :a=>1
160
- ann :x1, :b=>2
161
- end
162
-
163
- cY = Class.new(cX)
164
-
165
- test "01" do
166
- cY.ann(:x1,:a) == cY.ann(:x1,:a)
167
- end
168
-
169
- test "02" do
170
- cY.ann(:x1,:a).object_id == cY.ann(:x1,:a).object_id
171
- end
172
-
173
- test "03" do
174
- cY.ann(:x1,:a) == 1
175
- end
176
-
177
- test "04" do
178
- cY.ann(:x1,:b) == 2
179
- end
180
-
181
- test "05" do
182
- cY.ann :x1,:a => 2
183
- cY.ann(:x1,:a) == 2 &&
184
- cY.ann(:x1,:b) == 2
185
- end
186
-
187
- end
188
-
189
- context "4" do
190
-
191
- cX = Class.new do
192
- extend Anise::Annotations
193
- extend Anise::Annotative::Methods
194
- extend Anise::Annotative::Attributes
195
-
196
- #annotator :ann
197
- ann :foo, Integer
198
- end
199
-
200
- cY = Class.new(cX) do
201
- ann :foo, String
202
- end
203
-
204
- test "01" do
205
- cX.ann(:foo, :class) == Integer
206
- end
207
-
208
- test "02" do
209
- cY.ann(:foo, :class) == String
210
- end
211
-
212
- end
213
-
214
- context "5" do
215
-
216
- cX = Class.new do
217
- extend Anise::Annotations
218
- extend Anise::Annotative::Methods
219
- extend Anise::Annotative::Attributes
220
-
221
- #annotator :ann
222
- ann :foo, :doc => "hello"
223
- ann :foo, :bar => []
224
- end
225
-
226
- cY = Class.new(cX) do
227
- ann :foo, :class => String, :doc => "bye"
228
- end
229
-
230
- test "01" do
231
- cX.ann(:foo,:doc) == "hello"
232
- end
233
-
234
- test "02" do
235
- cX.ann(:foo) == {:doc=>"hello", :bar=>[]}
236
- end
237
-
238
- test "03" do
239
- cX.ann(:foo,:bar) << "1"
240
- cX.ann(:foo,:bar) == ["1"]
241
- end
242
-
243
- test "04" do
244
- cY.ann(:foo,:doc) == "bye"
245
- end
246
-
247
- test "05" do
248
- #cY.ann(:foo,:bar) == nil
249
- cY.ann(:foo,:bar) == ["1"]
250
- end
251
-
252
- test "06" do
253
- cY.ann(:foo, :doc => "cap")
254
- cY.ann(:foo, :doc) == "cap"
255
- end
256
-
257
- test "07" do
258
- cY.ann!(:foo,:bar) << "2"
259
- cY.ann(:foo,:bar) == ["1", "2"] &&
260
- cX.ann(:foo,:bar) == ["1"]
261
- end
262
-
263
- end
264
-
265
- context "6" do
266
-
267
- cX = Class.new do
268
- extend Anise::Annotations
269
- extend Anise::Annotative::Methods
270
- extend Anise::Annotative::Attributes
271
-
272
- method_annotator :req
273
-
274
- req 'r'
275
- def a ; "a"; end
276
-
277
- req 's', 't'
278
- attr :b
279
- end
280
-
281
- test "annotated" do
282
- cX.ann(:a) == {:req=>'r'}
283
- end
284
-
285
- test "annotated" do
286
- cX.ann(:b) == {:req=>['s','t']}
287
- end
288
-
289
- end
290
-
291
- context "attribute" do
292
-
293
- cX = Class.new do
294
- extend Anise::Annotations
295
- extend Anise::Annotative::Methods
296
- extend Anise::Annotative::Attributes
297
-
298
- attr :q
299
- attr :a, :x => 1
300
- end
301
-
302
- test "a" do
303
- cX.ann(:a) == {:x=>1}
304
- end
305
-
306
- end
307
-
308
- context "attribute using attr" do
309
-
310
- cA = Class.new do
311
- extend Anise::Annotations
312
- extend Anise::Annotative::Methods
313
- extend Anise::Annotative::Attributes
314
-
315
- attr :x, :cast=>"to_s"
316
- end
317
-
318
- test "cast" do
319
- cA.ann(:x,:cast) == "to_s"
320
- end
321
-
322
- end
323
-
324
- context "attribute using attr_accessor" do
325
-
326
- cA = Class.new do
327
- extend Anise::Annotations
328
- extend Anise::Annotative::Methods
329
- extend Anise::Annotative::Attributes
330
-
331
- attr_accessor :x, :cast=>"to_s"
332
- end
333
-
334
- test "instance_attributes" do
335
- iv = cA.instance_attributes - [:taguri]
336
- iv == [:x]
337
- end
338
-
339
- end
340
-
341
- end