anise 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -1,3 +1,7 @@
1
+ 2009-05-28 trans <transfire@gmail.com>
2
+
3
+ * added annotation_added callback
4
+
1
5
  2008-10-23 trans <transfire@gmail.com>
2
6
 
3
7
  * cleaned up work directory
data/MANIFEST CHANGED
@@ -30,4 +30,6 @@ test/test_attribute_toplevel.rb
30
30
  test/test_anise.rb
31
31
  test/test_annotations_module.rb
32
32
  test/test_anise_toplevel.rb
33
- test/test_annotations_toplevel.rb
33
+ test/test_annotations_toplevel.rb
34
+ spec/04_callbacks.rd
35
+ spec/01_annotations.rd
data/VERSION CHANGED
@@ -1 +1 @@
1
- anise 0.3.0 beta (2009-02-15)
1
+ anise 0.4.0 beta (2009-02-15)
@@ -134,6 +134,8 @@ module Anise
134
134
  keys = keys.inject({}){ |h,(k,v)| h[k.to_sym] = v; h} #rekey
135
135
  annotations[ref] ||= {}
136
136
  annotations[ref].update(keys)
137
+ # callback
138
+ annotation_added(ref)
137
139
  else
138
140
  key = keys.to_sym
139
141
  annotation(ref)[key]
@@ -162,6 +164,8 @@ module Anise
162
164
  keys = keys.inject({}){ |h,(k,v)| h[k.to_sym] = v; h} #rekey
163
165
  annotations[ref] ||= {}
164
166
  annotations[ref].update(keys)
167
+ # callback
168
+ annotation_added(ref) if method_defined?(:annotation_added)
165
169
  else
166
170
  key = keys.to_sym
167
171
  annotations[ref] ||= {}
@@ -173,6 +177,11 @@ module Anise
173
177
  end
174
178
  end
175
179
 
180
+ # callback method
181
+ def annotation_added(name)
182
+ super if defined?(super)
183
+ end
184
+
176
185
  end
177
186
 
178
187
  end
@@ -0,0 +1,25 @@
1
+ = Creating and Reading Annotations
2
+
3
+ Load the primary annotations library.
4
+
5
+ require 'anise/annotation'
6
+
7
+ Given a example class X we can apply annotations to it using the #ann method.
8
+
9
+ class X
10
+ include Anise::Annotation
11
+ ann :x1, :a=>1
12
+ ann :x1, :b=>2
13
+ end
14
+
15
+ We can then use #ann to lookup the set annotations.
16
+
17
+ X.ann(:x1,:a).should == 1
18
+
19
+ The #ann method is a public interface, so we can define annotation externally as well.
20
+
21
+ X.ann :x1, :a => 2
22
+ X.ann(:x1, :a).should == 2
23
+
24
+ QED.
25
+
@@ -0,0 +1,60 @@
1
+ = Callbacks
2
+
3
+ Load the annotations, which supports callbacks out of the box.
4
+
5
+ require 'anise/annotation'
6
+
7
+ Given a sample class X, we can use a standard callback method #annotation_added().
8
+
9
+ class X
10
+ include Anise::Annotation
11
+
12
+ class << self
13
+ attr :last_callback
14
+
15
+ def annotation_added(name)
16
+ @last_callback = [name, ann(name)]
17
+ end
18
+ end
19
+ end
20
+
21
+ Now if we add an annotation, we will see the callback catches it.
22
+
23
+ X.ann :x1, :a=>1
24
+ X.last_callback.should == [:x1, {:a => 1}]
25
+
26
+ We'll do it again to be sure.
27
+
28
+ X.ann :x1, :b=>2
29
+ X.last_callback.should == [:x1, {:a => 1, :b => 2}]
30
+
31
+ == Using Callbacks for Attribute Defaults
32
+
33
+ class ::Module
34
+ def annotation_added(key)
35
+ base = self
36
+ if value = ann(key, :default)
37
+ define_method(key) do
38
+ instance_variable_set("@#{key}", value) unless instance_variable_defined?("@#{key}")
39
+ base.module_eval{ attr key }
40
+ instance_variable_get("@#{key}")
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ Try it out.
47
+
48
+ class Y
49
+ include Anise::Annotation
50
+
51
+ attr :a
52
+ ann :a, :default => 10
53
+ end
54
+
55
+ x = Y.new
56
+ x.a.should == 10
57
+ x.a.should == 10
58
+
59
+ QED.
60
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tigerops-community@rubyforge.org
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-02-15 00:00:00 -05:00
13
+ date: 2009-05-28 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -70,6 +70,8 @@ files:
70
70
  - test/test_annotations_module.rb
71
71
  - test/test_anise_toplevel.rb
72
72
  - test/test_annotations_toplevel.rb
73
+ - spec/04_callbacks.rd
74
+ - spec/01_annotations.rd
73
75
  has_rdoc: true
74
76
  homepage: http://
75
77
  post_install_message: