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
data/.ruby CHANGED
@@ -1,41 +1,62 @@
1
- ---
2
- spec_version: 1.0.0
3
- replaces: []
4
-
5
- loadpath:
6
- - lib
7
- name: anise
8
- repositories: {}
9
-
10
- conflicts: []
11
-
12
- engine_check: []
13
-
14
- title: Anise
15
- contact: trans <transfire@gmail.com>
16
- resources:
17
- code: http://github.com/rubyworks/anise
18
- mail: http://groups.google.com/group/rubyworks-mailinglist
19
- home: http://rubyworks.github.com/anise
20
- maintainers: []
21
-
22
- requires:
23
- - group:
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:
24
22
  - test
25
- name: qed
26
- version: 0+
27
- - group:
23
+ development: true
24
+ - name: detroit
25
+ groups:
28
26
  - build
29
- name: redline
30
- version: 0+
31
- manifest: MANIFEST
32
- version: 0.6.0
33
- licenses:
34
- - Apache 2.0
35
- copyright: Copyright (c) 2008 Thomas Sawyer
36
- authors:
37
- - Thomas Sawyer
38
- organization: Rubyworks
39
- description: Anise is an Annotation System for the Ruby programming language. Unlike most other annotations systems it is not a comment-based or macro-based system that sits over-and-above the rest of the code. Rather, Anise is a dynamic annotations system operating at runtime.
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'
40
56
  summary: Dynamic Annotation System
41
- created: "2008-02-21"
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'
@@ -0,0 +1,7 @@
1
+ --title "Anise"
2
+ --output-dir doc
3
+ --private
4
+ --protected
5
+ lib/
6
+ -
7
+ [A-Z][A-Z]*.*
data/DEMO.md ADDED
@@ -0,0 +1,242 @@
1
+ # Annotations
2
+
3
+ ## Creating and Reading Annotations
4
+
5
+ Load the Anise library.
6
+
7
+ require 'anise'
8
+
9
+ Given an example class X we can apply annotations to it using the #ann method.
10
+
11
+ class X
12
+ extend Anise::Annotations
13
+
14
+ ann :x1, :a=>1
15
+ ann :x1, :b=>2
16
+ end
17
+
18
+ We can then use #ann to lookup the set annotations.
19
+
20
+ X.ann(:x1,:a).should == 1
21
+
22
+ The #ann method is a public interface, so we can define annotation externally as well.
23
+
24
+ X.ann :x1, :a => 2
25
+ X.ann(:x1, :a).should == 2
26
+
27
+ ## Annotation Added Callback
28
+
29
+ Given a sample class Y, we can use a standard callback method #annotation_added().
30
+
31
+ class Y
32
+ extend Anise::Annotations
33
+
34
+ class << self
35
+ attr :last_callback
36
+
37
+ def annotation_added(ref, ns)
38
+ @last_callback = [ns, ref, ann(ref/ns)]
39
+ end
40
+ end
41
+ end
42
+
43
+ Now if we add an annotation, we will see the callback catches it.
44
+
45
+ Y.ann :x1, :a=>1
46
+ Y.last_callback.should == [:ann, :x1, {:a => 1}]
47
+
48
+ We will do it again to be sure.
49
+
50
+ Y.ann :x1, :b=>2
51
+ Y.last_callback.should == [:ann, :x1, {:a => 1, :b => 2}]
52
+
53
+ ## Using Callbacks for Attribute Defaults
54
+
55
+ class ::Module
56
+ def annotation_added(key, ns)
57
+ return unless ns == :ann
58
+ base = self
59
+ if value = ann(key, :default)
60
+ define_method(key) do
61
+ instance_variable_set("@#{key}", value) unless instance_variable_defined?("@#{key}")
62
+ base.module_eval{ attr key }
63
+ instance_variable_get("@#{key}")
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ Try it out.
70
+
71
+ class Z
72
+ extend Anise::Annotations
73
+
74
+ attr :a
75
+ ann :a, :default => 10
76
+ end
77
+
78
+ z = Z.new
79
+ z.a.should == 10
80
+ z.a.should == 10
81
+
82
+
83
+ # Annotative Attributes
84
+
85
+ Create a class that uses the `Annotative::Attributes` mixin.
86
+
87
+ class X
88
+ extend Anise::Annotative::Attributes
89
+
90
+ attr :a, :count => 1
91
+ end
92
+
93
+ Then we can see tht the attribute method `:a` has an annotation entry.
94
+
95
+ X.ann(:a, :count) #=> 1
96
+
97
+
98
+ # Method Annotations
99
+
100
+ Create a class that uses the `Annotative::Methods` mixin.
101
+
102
+ class X
103
+ extend Anise::Annotative::Methods
104
+
105
+ def self.doc(string)
106
+ method_annotation(:doc=>string.to_s)
107
+ end
108
+
109
+ doc "See what I mean?"
110
+
111
+ def see
112
+ puts "Yes, I see!"
113
+ end
114
+ end
115
+
116
+ See that it is set.
117
+
118
+ X.ann(:see, :doc) #=> "See what I mean?"
119
+
120
+ Method Annotators can override the standard annotation procedure
121
+ with a custom procedure. In such case no annotations will actually
122
+ be created unless the `#ann` is called in the procedure.
123
+
124
+ class Y
125
+ extend Anise::Annotative::Methods
126
+
127
+ def self.list
128
+ @list ||= []
129
+ end
130
+
131
+ def self.doc(string)
132
+ method_annotation do |method|
133
+ list << [method, string]
134
+ end
135
+ end
136
+
137
+ doc "See here!"
138
+
139
+ def see
140
+ puts "Yes, I see!"
141
+ end
142
+ end
143
+
144
+ See that it is set.
145
+
146
+ Y.list #=> [[:see, "See here!"]]
147
+
148
+
149
+ # Variable Annotations
150
+
151
+ Create a class that uses the `Annotative::Variables` mixin.
152
+
153
+ class X
154
+ extend Anise::Annotative::Variables
155
+
156
+ variable_annotator :@doc
157
+
158
+ @doc = "See what I mean?"
159
+
160
+ def see
161
+ puts "Yes, I see!"
162
+ end
163
+ end
164
+
165
+ See that it is set.
166
+
167
+ X.ann(:see, :@doc).should == "See what I mean?"
168
+
169
+ Variable annotations can override the standard annotation procedure with a
170
+ custom procedure.
171
+
172
+ class Y
173
+ extend Anise::Annotative::Variables
174
+
175
+ def self.list
176
+ @list ||= []
177
+ end
178
+
179
+ variable_annotator :@doc do |method, value|
180
+ list << [method, value]
181
+ end
182
+
183
+ @doc = "See here!"
184
+
185
+ def see
186
+ puts "Yes, I see!"
187
+ end
188
+ end
189
+
190
+ See that it is set.
191
+
192
+ Y.list #=> [[:see, "See here!"]]
193
+
194
+
195
+ = TOPLEVEL Annotations
196
+
197
+ Extending Object with `Annotations` should make them available to all classes.
198
+
199
+ class ::Object
200
+ extend Anise::Annotations
201
+ end
202
+
203
+ Given a example class X we can apply annotations to it using the #ann method.
204
+
205
+ class X
206
+ ann :x1, :a=>1
207
+ ann :x1, :b=>2
208
+ end
209
+
210
+ We can then use #ann to lookup the set annotations.
211
+
212
+ X.ann(:x1,:a).should == 1
213
+
214
+ The #ann method is a public interface, so we can define annotation externally as well.
215
+
216
+ X.ann :x1, :a => 2
217
+ X.ann(:x1, :a).should == 2
218
+
219
+ Alternatively the `Annotations` module could be included into the `Module` class.
220
+
221
+
222
+ = TOPLEVEL Annotated Attributes
223
+
224
+ Including `AnnotatedAttributes` at the toplevel, i.e. Object, will make
225
+ annotated attributes univerally available.
226
+
227
+ class ::Object
228
+ extend Anise::Annotative::Attributes
229
+ end
230
+
231
+ Create a class that uses it.
232
+
233
+ class X
234
+ attr :a, :count=>1
235
+ end
236
+
237
+ X.ann(:a, :count) #=> 1
238
+
239
+ Alternatively the `Annotative::Attributes` module could be included into
240
+ the `Module` class.
241
+
242
+
@@ -1,6 +1,27 @@
1
- = RELEASE HISTORY
1
+ # RELEASE HISTORY
2
2
 
3
- == 0.6.0 / 2011-05-16
3
+ ## 0.7.0 / 2012-03-26
4
+
5
+ This release has some major API changes. Most significantly a number
6
+ of modules have been renamed. The `Method` module has been renamed to
7
+ `Annotative::Methods`. Likewise the `Attribute` module has been ranamed
8
+ to `Annotative::Attributes`, and so on. These have been renamed so that
9
+ including `Anise` in the toplevel will not cause conflicts with any
10
+ other modules or classes an application or library might be using.
11
+ In addition these modules now must use `extend` rather then `include`
12
+ to be mixed into a class or module, since they conatin only class methods.
13
+
14
+ Changes:
15
+
16
+ * Rename Annotations module to Annotations::Store.
17
+ * Rename Annotation module to Annotations.
18
+ * Rename Method module to Annotative::Methods.
19
+ * Rename Attribute module to Annotative::Attributes.
20
+ * Add #method_annotation for use in custom class method.
21
+ * Discourage #method_annotator in favor of #method_annotation.
22
+
23
+
24
+ ## 0.6.0 / 2011-05-16
4
25
 
5
26
  This release fixes an bug in which append_features cant be called b/c
6
27
  it is a private method. This release also renames `ClassMethods`
@@ -12,7 +33,7 @@ Changes:
12
33
  * Rename ClassMethods to Aid.
13
34
 
14
35
 
15
- == 0.5.0 / 2011-04-30
36
+ ## 0.5.0 / 2011-04-30
16
37
 
17
38
  The primary changes in this release are behind the scenes implementation
18
39
  improvements. The most significant of which is the simplification of
@@ -28,7 +49,7 @@ Changes:
28
49
  * Annotators can override method_added callback.
29
50
 
30
51
 
31
- == 0.4.0 / 2009-05-28
52
+ ## 0.4.0 / 2009-05-28
32
53
 
33
54
  This version adds a callback method called #annotation_added
34
55
  --a striaght-forward callback method patterned after Ruby's
@@ -40,7 +61,7 @@ Changes:
40
61
  * Added annotation_added callback.
41
62
 
42
63
 
43
- == 0.2.1 / 2008-10-31
64
+ ## 0.2.1 / 2008-10-31
44
65
 
45
66
  Project reorganization release --mostly some file names have changed.
46
67
 
@@ -49,7 +70,7 @@ Changes:
49
70
  * Renamed some lib files.
50
71
 
51
72
 
52
- == 0.2.0 / 2008-10-28
73
+ ## 0.2.0 / 2008-10-28
53
74
 
54
75
  By making Annotations a module, it can not be used in only the clases
55
76
  it is needed.
@@ -59,7 +80,7 @@ Changes:
59
80
  * Annotations is a module rather than a core extenstion to Module.
60
81
 
61
82
 
62
- == 0.1.1 / 2008-10-17
83
+ ## 0.1.1 / 2008-10-17
63
84
 
64
85
  Ahoy, mate! This is the first release of Anise.
65
86
 
@@ -0,0 +1,27 @@
1
+ Anise - Dynamic Annotations for Ruby (http://rubyworks.github.com/anise)
2
+
3
+ Copyright (c) 2008 Rubyworks, Thomas Sawyer
4
+
5
+ (spdx) BSD-2-Clause License
6
+
7
+ Redistribution and use in source and binary forms, with or without
8
+ modification, are permitted provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice,
11
+ this list of conditions and the following disclaimer.
12
+
13
+ * Redistributions in binary form must reproduce the above copyright notice,
14
+ this list of conditions and the following disclaimer in the documentation
15
+ and/or other materials provided with the distribution.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY Thomas Sawyer ``AS IS'' AND ANY EXPRESS
18
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20
+ NO EVENT SHALL Thomas Sawyer OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+