anise 0.6.0 → 0.7.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.
Files changed (53) hide show
  1. data/.ruby +59 -38
  2. data/.yardopts +7 -0
  3. data/DEMO.md +242 -0
  4. data/{HISTORY.rdoc → HISTORY.md} +28 -7
  5. data/LICENSE.txt +27 -0
  6. data/README.md +129 -0
  7. data/demo/01_annotations.md +81 -0
  8. data/demo/03_attributes.md +14 -0
  9. data/demo/04_methods.md +50 -0
  10. data/demo/05_variables.md +45 -0
  11. data/{qed → demo}/applique/ae.rb +0 -0
  12. data/demo/applique/anise.rb +1 -0
  13. data/{qed/toplevel/01_annotations.qed → demo/toplevel/01_annotations.md} +5 -9
  14. data/demo/toplevel/03_attributes.md +20 -0
  15. data/lib/anise.rb +28 -45
  16. data/lib/anise.yml +59 -38
  17. data/lib/anise/annotations.rb +132 -0
  18. data/lib/anise/annotations/store.rb +136 -0
  19. data/lib/anise/annotative.rb +7 -0
  20. data/lib/anise/annotative/attributes.rb +147 -0
  21. data/lib/anise/annotative/methods.rb +131 -0
  22. data/lib/anise/annotative/variables.rb +99 -0
  23. data/lib/anise/{module.rb → core_ext.rb} +30 -0
  24. data/lib/anise/universal.rb +6 -0
  25. data/lib/anise/version.rb +17 -0
  26. data/test/case_annotations.rb +173 -0
  27. data/test/case_attributes.rb +46 -0
  28. data/test/case_combined_usage.rb +341 -0
  29. data/test/case_methods.rb +36 -0
  30. data/test/case_variables.rb +22 -0
  31. data/test/helper.rb +2 -0
  32. metadata +99 -98
  33. data/APACHE2.txt +0 -204
  34. data/COPYING.rdoc +0 -17
  35. data/README.rdoc +0 -107
  36. data/lib/anise/annotation.rb +0 -175
  37. data/lib/anise/annotator.rb +0 -82
  38. data/lib/anise/attribute.rb +0 -138
  39. data/qed/01_annotations.qed +0 -26
  40. data/qed/02_annotation_added.rdoc +0 -60
  41. data/qed/03_attributes.rdoc +0 -16
  42. data/qed/04_annotator.rdoc +0 -49
  43. data/qed/toplevel/03_attributes.rdoc +0 -20
  44. data/test/suite.rb +0 -8
  45. data/test/test_anise.rb +0 -193
  46. data/test/test_anise_toplevel.rb +0 -194
  47. data/test/test_annotations.rb +0 -136
  48. data/test/test_annotations_module.rb +0 -132
  49. data/test/test_annotations_toplevel.rb +0 -131
  50. data/test/test_annotator.rb +0 -26
  51. data/test/test_annotator_toplevel.rb +0 -28
  52. data/test/test_attribute.rb +0 -37
  53. data/test/test_attribute_toplevel.rb +0 -65
@@ -1,16 +0,0 @@
1
- = Annotated Attribute Methods
2
-
3
- Load the attributes library.
4
-
5
- require 'anise/attribute'
6
-
7
- Create a class that includes it.
8
-
9
- class X
10
- include Anise::Attribute
11
-
12
- attr :a, :count => 1
13
- end
14
-
15
- X.ann(:a, :count) #=> 1
16
-
@@ -1,49 +0,0 @@
1
- = Annotators
2
-
3
- Load the primary annotator library.
4
-
5
- require 'anise/annotator'
6
-
7
- Create a class that includes it.
8
-
9
- class X
10
- include Anise::Annotator
11
-
12
- annotator :doc
13
-
14
- doc "See what I mean?"
15
-
16
- def see
17
- puts "Yes, I see!"
18
- end
19
- end
20
-
21
- See that it is set.
22
-
23
- X.ann(:see, :doc).assert == "See what I mean?"
24
-
25
- Annotators can override the standard annotation procedure with a
26
- custom procedure.
27
-
28
- class Y
29
- include Anise::Annotator
30
-
31
- def self.list
32
- @list ||= []
33
- end
34
-
35
- annotator :doc do |method, argument|
36
- list << [method, argument]
37
- end
38
-
39
- doc "See here!"
40
-
41
- def see
42
- puts "Yes, I see!"
43
- end
44
- end
45
-
46
- See that it is set.
47
-
48
- Y.list #=> [[:see, "See here!"]]
49
-
@@ -1,20 +0,0 @@
1
- = Annotated Attribute Methods
2
-
3
- Load the attributes library.
4
-
5
- require 'anise/attribute'
6
-
7
- Including Anise::Attribute at the toplevel (same as Object).
8
-
9
- class ::Object
10
- include Anise::Attribute
11
- end
12
-
13
- Create a class that uses it.
14
-
15
- class X
16
- attr :a, :count=>1
17
- end
18
-
19
- X.ann(:a, :count) #=> 1
20
-
@@ -1,8 +0,0 @@
1
- $: << 'lib'
2
-
3
- tests = Dir[File.join(File.dirname(__FILE__), 'test_*')]
4
-
5
- tests.each do |t|
6
- require t
7
- end
8
-
@@ -1,193 +0,0 @@
1
- require 'anise'
2
-
3
- class Test_Anise_Annotation_0 < Test::Unit::TestCase
4
- class X
5
- include Anise
6
-
7
- attr :a
8
-
9
- ann :@a, :valid => lambda{ |x| x.is_a?(Integer) }
10
-
11
- ann :a, :class => Integer
12
-
13
- def initialize(a)
14
- @a = a
15
- end
16
-
17
- def validate
18
- instance_variables.each do |iv|
19
- if validator = self.class.ann(iv)[:valid]
20
- value = instance_variable_get(iv)
21
- unless validator.call(value)
22
- raise "Invalid value #{value} for #{iv}"
23
- end
24
- end
25
- end
26
- end
27
- end
28
-
29
- def test_annotation_class
30
- assert_equal(Integer, X.ann(:a, :class))
31
- end
32
-
33
- def test_annotation_validate
34
- x = X.new(1)
35
- assert_nothing_raised{ x.validate }
36
- end
37
- end
38
-
39
- class Test_Anise_Annotation_1 < Test::Unit::TestCase
40
- class X
41
- include Anise
42
- def x1 ; end
43
- ann :x1, :a=>1
44
- ann :x1, :b=>2
45
- end
46
-
47
- def test_1_01
48
- assert_equal( X.ann(:x1,:a), X.ann(:x1,:a) )
49
- assert_equal( X.ann(:x1,:a).object_id, X.ann(:x1,:a).object_id )
50
- end
51
- def test_1_02
52
- X.ann :x1, :a => 2
53
- assert_equal( 2, X.ann(:x1,:a) )
54
- end
55
- end
56
-
57
- class Test_Anise_Annotation_2 < Test::Unit::TestCase
58
- class X
59
- include Anise
60
- def x1 ; end
61
- ann :x1, :a=>1
62
- ann :x1, :b=>2
63
- end
64
- class Y < X ; end
65
-
66
- def test_2_01
67
- assert_equal( Y.ann(:x1,:a), Y.ann(:x1,:a) )
68
- assert_equal( Y.ann(:x1,:a).object_id, Y.ann(:x1,:a).object_id )
69
- end
70
- def test_2_02
71
- assert_equal( 1, Y.ann(:x1,:a) )
72
- assert_equal( 2, Y.ann(:x1,:b) )
73
- end
74
- def test_2_03
75
- Y.ann :x1,:a => 2
76
- assert_equal( 2, Y.ann(:x1,:a) )
77
- assert_equal( 2, Y.ann(:x1,:b) )
78
- end
79
- end
80
-
81
- class Test_Anise_Annotation_3 < Test::Unit::TestCase
82
- class X
83
- include Anise
84
- ann :foo, Integer
85
- end
86
- class Y < X
87
- ann :foo, String
88
- end
89
-
90
- def test_3_01
91
- assert_equal( Integer, X.ann(:foo, :class) )
92
- end
93
- def test_3_02
94
- assert_equal( String, Y.ann(:foo, :class) )
95
- end
96
- end
97
-
98
- class Test_Anise_Annotation_4 < Test::Unit::TestCase
99
- class X
100
- include Anise
101
- ann :foo, :doc => "hello"
102
- ann :foo, :bar => []
103
- end
104
- class Y < X
105
- ann :foo, :class => String, :doc => "bye"
106
- end
107
-
108
- def test_4_01
109
- assert_equal( "hello", X.ann(:foo,:doc) )
110
- end
111
- def test_4_02
112
- assert_equal( X.ann(:foo), { :doc => "hello", :bar => [] } )
113
- end
114
- def test_4_03
115
- X.ann(:foo,:bar) << "1"
116
- assert_equal( ["1"], X.ann(:foo,:bar) )
117
- end
118
- def test_4_04
119
- assert_equal( "bye", Y.ann(:foo,:doc) )
120
- end
121
- def test_4_05
122
- #assert_equal( nil, Y.ann(:foo,:bar) )
123
- assert_equal( ["1"], Y.ann(:foo,:bar) )
124
- end
125
- def test_4_06
126
- Y.ann(:foo, :doc => "cap")
127
- assert_equal( "cap", Y.ann(:foo, :doc) )
128
- end
129
- def test_4_07
130
- Y.ann!(:foo,:bar) << "2"
131
- assert_equal( ["1", "2"], Y.ann(:foo,:bar) )
132
- assert_equal( ["1", "2"], Y.ann(:foo,:bar) )
133
- assert_equal( ["1"], X.ann(:foo,:bar) )
134
- end
135
- end
136
-
137
- class Test_Anise_Annotator < Test::Unit::TestCase
138
- class X
139
- include Anise
140
-
141
- annotator :req
142
-
143
- req 'r'
144
- def a ; "a"; end
145
-
146
- req 's', 't'
147
- attr :b
148
- end
149
-
150
- def test_annotated
151
- assert_equal( {:req=>'r'}, X.ann(:a) )
152
- end
153
-
154
- def test_annotated
155
- assert_equal( {:req=>['s','t']}, X.ann(:b) )
156
- end
157
- end
158
-
159
- class Test_Anise_Attribute < Test::Unit::TestCase
160
- class X
161
- include Anise
162
- attr :q
163
- attr :a, :x => 1
164
- end
165
-
166
- def test_attr_a
167
- assert_equal( {:x=>1}, X.ann(:a) )
168
- end
169
- end
170
-
171
- class Test_Anise_Attribute_Using_Attr < Test::Unit::TestCase
172
- class A
173
- include Anise
174
- attr :x, :cast=>"to_s"
175
- end
176
-
177
- def test_01
178
- assert_equal( "to_s", A.ann(:x,:cast) )
179
- end
180
- end
181
-
182
- class Test_Anise_Attribute_Using_Attr_Accessor < Test::Unit::TestCase
183
- class A
184
- include Anise
185
- attr_accessor :x, :cast=>"to_s"
186
- end
187
-
188
- def test_instance_attributes
189
- a = A.new
190
- assert_equal( [:x], A.instance_attributes - [:taguri] )
191
- end
192
- end
193
-
@@ -1,194 +0,0 @@
1
- require 'anise'
2
-
3
- include Anise
4
-
5
- class Test_Anise_Toplevel_Annotation_0 < Test::Unit::TestCase
6
- class X
7
- attr :a
8
-
9
- ann :@a, :valid => lambda{ |x| x.is_a?(Integer) }
10
-
11
- ann :a, :class => Integer
12
-
13
- def initialize(a)
14
- @a = a
15
- end
16
-
17
- def validate
18
- instance_variables.each do |iv|
19
- if validator = self.class.ann(iv)[:valid]
20
- value = instance_variable_get(iv)
21
- unless validator.call(value)
22
- raise "Invalid value #{value} for #{iv}"
23
- end
24
- end
25
- end
26
- end
27
- end
28
-
29
- def test_annotation_class
30
- assert_equal(Integer, X.ann(:a, :class))
31
- end
32
-
33
- def test_annotation_validate
34
- x = X.new(1)
35
- assert_nothing_raised{ x.validate }
36
- end
37
- end
38
-
39
- class Test_Anise_Toplevel_Annotation_1 < Test::Unit::TestCase
40
- class X
41
- def x1 ; end
42
- ann :x1, :a=>1
43
- ann :x1, :b=>2
44
- end
45
-
46
- def test_1_01
47
- assert_equal( X.ann(:x1,:a), X.ann(:x1,:a) )
48
- assert_equal( X.ann(:x1,:a).object_id, X.ann(:x1,:a).object_id )
49
- end
50
- def test_1_02
51
- X.ann :x1, :a => 2
52
- assert_equal( 2, X.ann(:x1,:a) )
53
- end
54
- end
55
-
56
- class Test_Anise_Toplevel_Annotation_2 < Test::Unit::TestCase
57
- class X
58
- def x1 ; end
59
- ann :x1, :a=>1
60
- ann :x1, :b=>2
61
- end
62
- class Y < X ; end
63
-
64
- def test_2_01
65
- assert_equal( Y.ann(:x1,:a), Y.ann(:x1,:a) )
66
- assert_equal( Y.ann(:x1,:a).object_id, Y.ann(:x1,:a).object_id )
67
- end
68
- def test_2_02
69
- assert_equal( 1, Y.ann(:x1,:a) )
70
- assert_equal( 2, Y.ann(:x1,:b) )
71
- end
72
- def test_2_03
73
- Y.ann :x1,:a => 2
74
- assert_equal( 2, Y.ann(:x1,:a) )
75
- assert_equal( 2, Y.ann(:x1,:b) )
76
- end
77
- end
78
-
79
- class Test_Anise_Toplevel_Annotation_3 < Test::Unit::TestCase
80
- class X
81
- ann :foo, Integer
82
- end
83
- class Y < X
84
- ann :foo, String
85
- end
86
-
87
- def test_3_01
88
- assert_equal( Integer, X.ann(:foo, :class) )
89
- end
90
- def test_3_02
91
- assert_equal( String, Y.ann(:foo, :class) )
92
- end
93
- end
94
-
95
- class Test_Anise_Toplevel_Annotation_4 < Test::Unit::TestCase
96
- class X
97
- ann :foo, :doc => "hello"
98
- ann :foo, :bar => []
99
- end
100
- class Y < X
101
- ann :foo, :class => String, :doc => "bye"
102
- end
103
-
104
- def test_4_01
105
- assert_equal( "hello", X.ann(:foo,:doc) )
106
- end
107
- def test_4_02
108
- assert_equal( X.ann(:foo), { :doc => "hello", :bar => [] } )
109
- end
110
- def test_4_03
111
- X.ann(:foo,:bar) << "1"
112
- assert_equal( ["1"], X.ann(:foo,:bar) )
113
- end
114
- def test_4_04
115
- assert_equal( "bye", Y.ann(:foo,:doc) )
116
- end
117
- def test_4_05
118
- #assert_equal( nil, Y.ann(:foo,:bar) )
119
- assert_equal( ["1"], Y.ann(:foo,:bar) )
120
- end
121
- def test_4_06
122
- Y.ann(:foo, :doc => "cap")
123
- assert_equal( "cap", Y.ann(:foo, :doc) )
124
- end
125
- def test_4_07
126
- Y.ann!(:foo,:bar) << "2"
127
- assert_equal( ["1", "2"], Y.ann(:foo,:bar) )
128
- assert_equal( ["1", "2"], Y.ann(:foo,:bar) )
129
- assert_equal( ["1"], X.ann(:foo,:bar) )
130
- end
131
- end
132
-
133
- class Test_Anise_Toplevel_Annotator < Test::Unit::TestCase
134
- class X
135
- annotator :req
136
-
137
- req 'r'
138
- def a ; "a"; end
139
-
140
- req 's', 't'
141
- attr :b
142
-
143
- def initialize
144
- @b = "b"
145
- end
146
- end
147
-
148
- def test_normal
149
- x = X.new
150
- assert_equal("a", x.a)
151
- assert_equal("b", x.b)
152
- end
153
-
154
- def test_annotated_a
155
- assert_equal( {:req=>'r'}, X.ann(:a) )
156
- end
157
-
158
- def test_annotated_b
159
- assert_equal( {:req=>['s', 't']}, X.ann(:b) )
160
- end
161
- end
162
-
163
- class Test_Anise_Toplevel_Attribute < Test::Unit::TestCase
164
- class X
165
- attr :q
166
- attr :a, :x => 1
167
- end
168
-
169
- def test_attr_a
170
- assert_equal( {:x=>1}, X.ann(:a) )
171
- end
172
- end
173
-
174
- class Test_Anise_Toplevel_Attribute_Using_Attr < Test::Unit::TestCase
175
- class A
176
- attr :x, :cast=>"to_s"
177
- end
178
-
179
- def test_01
180
- assert_equal( "to_s", A.ann(:x,:cast) )
181
- end
182
- end
183
-
184
- class Test_Anise_Toplevel_Attribute_Using_Attr_Accessor < Test::Unit::TestCase
185
- class A
186
- attr_accessor :x, :cast=>"to_s"
187
- end
188
-
189
- def test_instance_attributes
190
- a = A.new
191
- assert_equal( [:x], A.instance_attributes - [:taguri] )
192
- end
193
- end
194
-