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.
- data/.ruby +59 -38
- data/.yardopts +7 -0
- data/DEMO.md +242 -0
- data/{HISTORY.rdoc → HISTORY.md} +28 -7
- data/LICENSE.txt +27 -0
- data/README.md +129 -0
- data/demo/01_annotations.md +81 -0
- data/demo/03_attributes.md +14 -0
- data/demo/04_methods.md +50 -0
- data/demo/05_variables.md +45 -0
- data/{qed → demo}/applique/ae.rb +0 -0
- data/demo/applique/anise.rb +1 -0
- data/{qed/toplevel/01_annotations.qed → demo/toplevel/01_annotations.md} +5 -9
- data/demo/toplevel/03_attributes.md +20 -0
- data/lib/anise.rb +28 -45
- data/lib/anise.yml +59 -38
- data/lib/anise/annotations.rb +132 -0
- data/lib/anise/annotations/store.rb +136 -0
- data/lib/anise/annotative.rb +7 -0
- data/lib/anise/annotative/attributes.rb +147 -0
- data/lib/anise/annotative/methods.rb +131 -0
- data/lib/anise/annotative/variables.rb +99 -0
- data/lib/anise/{module.rb → core_ext.rb} +30 -0
- data/lib/anise/universal.rb +6 -0
- data/lib/anise/version.rb +17 -0
- data/test/case_annotations.rb +173 -0
- data/test/case_attributes.rb +46 -0
- data/test/case_combined_usage.rb +341 -0
- data/test/case_methods.rb +36 -0
- data/test/case_variables.rb +22 -0
- data/test/helper.rb +2 -0
- metadata +99 -98
- data/APACHE2.txt +0 -204
- data/COPYING.rdoc +0 -17
- data/README.rdoc +0 -107
- data/lib/anise/annotation.rb +0 -175
- data/lib/anise/annotator.rb +0 -82
- data/lib/anise/attribute.rb +0 -138
- data/qed/01_annotations.qed +0 -26
- data/qed/02_annotation_added.rdoc +0 -60
- data/qed/03_attributes.rdoc +0 -16
- data/qed/04_annotator.rdoc +0 -49
- data/qed/toplevel/03_attributes.rdoc +0 -20
- data/test/suite.rb +0 -8
- data/test/test_anise.rb +0 -193
- data/test/test_anise_toplevel.rb +0 -194
- data/test/test_annotations.rb +0 -136
- data/test/test_annotations_module.rb +0 -132
- data/test/test_annotations_toplevel.rb +0 -131
- data/test/test_annotator.rb +0 -26
- data/test/test_annotator_toplevel.rb +0 -28
- data/test/test_attribute.rb +0 -37
- data/test/test_attribute_toplevel.rb +0 -65
data/.ruby
CHANGED
@@ -1,41 +1,62 @@
|
|
1
|
-
---
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
23
|
+
development: true
|
24
|
+
- name: detroit
|
25
|
+
groups:
|
28
26
|
- build
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
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'
|
data/.yardopts
ADDED
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
|
+
|
data/{HISTORY.rdoc → HISTORY.md}
RENAMED
@@ -1,6 +1,27 @@
|
|
1
|
-
|
1
|
+
# RELEASE HISTORY
|
2
2
|
|
3
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
83
|
+
## 0.1.1 / 2008-10-17
|
63
84
|
|
64
85
|
Ahoy, mate! This is the first release of Anise.
|
65
86
|
|
data/LICENSE.txt
ADDED
@@ -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
|
+
|