anise 0.1.1 → 0.2.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/COPYING +159 -161
- data/HISTORY +14 -12
- data/MANIFEST +10 -6
- data/README +9 -13
- data/RELEASE +13 -4
- data/VERSION +1 -1
- data/lib/anise/annotation.rb +160 -0
- data/lib/anise/annotator.rb +60 -0
- data/lib/anise/attribute.rb +135 -0
- data/lib/anise.rb +38 -1
- data/test/test_anise.rb +195 -0
- data/test/test_anise_toplevel.rb +196 -0
- data/test/test_annotations.rb +136 -0
- data/test/test_annotations_toplevel.rb +131 -0
- data/test/test_annotator.rb +28 -0
- data/test/test_annotator_toplevel.rb +30 -0
- data/test/test_attribute.rb +27 -6
- data/test/test_attribute_toplevel.rb +64 -0
- metadata +28 -21
- data/lib/anise/annotatable.rb +0 -60
- data/lib/anise/annotations.rb +0 -114
- data/lib/anise/attributes.rb +0 -122
- data/test/test_annotatable.rb +0 -28
- data/test/test_toplevel_annotatable.rb +0 -32
- data/test/test_toplevel_attribute.rb +0 -27
data/lib/anise/attributes.rb
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'facets/inheritor' # remove dependency?
|
2
|
-
|
3
|
-
module Anise
|
4
|
-
require 'anise/annotations'
|
5
|
-
|
6
|
-
module Annotatable
|
7
|
-
|
8
|
-
# = Annotated Attributes
|
9
|
-
#
|
10
|
-
# This framework modifies the major attr_* methods to allow easy addition of annotations.
|
11
|
-
# It modifies the built in attribute methods (attr, attr_reader, attr_writer and attr_accessor),
|
12
|
-
# to allow annotations to added to them directly rather than requireing a separate
|
13
|
-
# #ann statement.
|
14
|
-
#
|
15
|
-
# class X
|
16
|
-
# attr :a, :valid => lambda{ |x| x.is_a?(Integer) }
|
17
|
-
# end
|
18
|
-
#
|
19
|
-
# See annotation.rb for more information.
|
20
|
-
#
|
21
|
-
# NOTE This library was designed to be backward compatible with the standard versions of the
|
22
|
-
# same methods.
|
23
|
-
#
|
24
|
-
module Attributes
|
25
|
-
|
26
|
-
def self.append_features(base)
|
27
|
-
base.extend self
|
28
|
-
base.module_eval do
|
29
|
-
inheritor :instance_attributes, [], :|
|
30
|
-
|
31
|
-
annotatable_attribute_method(:attr_reader)
|
32
|
-
annotatable_attribute_method(:attr_writer)
|
33
|
-
annotatable_attribute_method(:attr_accessor)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
#
|
38
|
-
def annotatable_attribute_method(attr_method_name)
|
39
|
-
attr_method = method(attr_method_name)
|
40
|
-
|
41
|
-
(class << self; self; end).instance_eval do
|
42
|
-
|
43
|
-
define_method(attr_method_name) do |*args|
|
44
|
-
|
45
|
-
args.flatten!
|
46
|
-
|
47
|
-
harg={}; while args.last.is_a?(Hash)
|
48
|
-
harg.update(args.pop)
|
49
|
-
end
|
50
|
-
|
51
|
-
raise ArgumentError if args.empty? and harg.empty?
|
52
|
-
|
53
|
-
if args.empty? # hash mode
|
54
|
-
harg.each { |a,h| send(attr_method_name,a,h) }
|
55
|
-
else
|
56
|
-
klass = harg[:class] = args.pop if args.last.is_a?(Class)
|
57
|
-
|
58
|
-
attr_method.call(*args)
|
59
|
-
|
60
|
-
args.each { |a|
|
61
|
-
ann(a.to_sym,harg)
|
62
|
-
}
|
63
|
-
|
64
|
-
instance_attributes!.concat(args) #merge!
|
65
|
-
|
66
|
-
# Use this callback to customize for your needs.
|
67
|
-
if respond_to?(:attr_callback)
|
68
|
-
attr_callback(self, args, harg)
|
69
|
-
end
|
70
|
-
|
71
|
-
# return the names of the attributes created
|
72
|
-
return args
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
# Return list of attributes that have a :class annotation.
|
81
|
-
#
|
82
|
-
# class MyClass
|
83
|
-
# attr_accessor :test
|
84
|
-
# attr_accessor :name, String, :doc => 'Hello'
|
85
|
-
# attr_accessor :age, Fixnum
|
86
|
-
# end
|
87
|
-
#
|
88
|
-
# MyClass.instance_attributes # => [:test, :name, :age, :body]
|
89
|
-
# MyClass.classified_attributes # => [:name, :age]
|
90
|
-
#
|
91
|
-
def classified_attributes
|
92
|
-
instance_attributes.find_all do |a|
|
93
|
-
self.ann(a, :class)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
# This define a simple adjustment to #attr to allow it to handle the boolean argument and
|
98
|
-
# to be able to accept attributes. It's backward compatible and is not needed for Ruby 1.9
|
99
|
-
# which gets rid of the secondary argument.
|
100
|
-
#
|
101
|
-
def attr(*args)
|
102
|
-
args.flatten!
|
103
|
-
case args.last
|
104
|
-
when TrueClass
|
105
|
-
args.pop
|
106
|
-
attr_accessor(*args)
|
107
|
-
when FalseClass
|
108
|
-
args.pop
|
109
|
-
attr_reader(*args)
|
110
|
-
else
|
111
|
-
attr_reader(*args)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
# Copyright (c) 2005, 2008 TigerOps
|
122
|
-
|
data/test/test_annotatable.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'anise/annotatable'
|
2
|
-
|
3
|
-
class Test_Annotatable < Test::Unit::TestCase
|
4
|
-
|
5
|
-
include Anise::Annotatable
|
6
|
-
|
7
|
-
annotation :req
|
8
|
-
|
9
|
-
req 'r'
|
10
|
-
|
11
|
-
def a
|
12
|
-
"a"
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_annotated
|
16
|
-
assert_equal( {:req=>['r']}, self.class.ann(:a) )
|
17
|
-
end
|
18
|
-
|
19
|
-
req 's'
|
20
|
-
|
21
|
-
attr :b
|
22
|
-
|
23
|
-
def test_annotated
|
24
|
-
assert_equal( {:req=>['s']}, self.class.ann(:b) )
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
@@ -1,32 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
require 'annotable'
|
3
|
-
require 'test/unit'
|
4
|
-
|
5
|
-
include Annotatable
|
6
|
-
|
7
|
-
annotation :req
|
8
|
-
|
9
|
-
class Test_Annotatable < Test::Unit::TestCase
|
10
|
-
|
11
|
-
annotation :req
|
12
|
-
|
13
|
-
req 'r'
|
14
|
-
|
15
|
-
def a
|
16
|
-
"a"
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_annotated
|
20
|
-
assert_equal( {:req=>['r']}, self.class.ann(:a) )
|
21
|
-
end
|
22
|
-
|
23
|
-
req 's'
|
24
|
-
|
25
|
-
attr :b
|
26
|
-
|
27
|
-
def test_annotated
|
28
|
-
assert_equal( {:req=>['s']}, self.class.ann(:b) )
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
=end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
require 'annotable/attributes'
|
3
|
-
require 'test/unit'
|
4
|
-
|
5
|
-
include Annotatable::Attributes
|
6
|
-
|
7
|
-
$self = self
|
8
|
-
|
9
|
-
attr :b, :y => 1
|
10
|
-
|
11
|
-
class Test_Attribute_Toplevel < Test::Unit::TestCase
|
12
|
-
|
13
|
-
attr :q
|
14
|
-
|
15
|
-
attr :a, :x => 1
|
16
|
-
|
17
|
-
def test_attr_a
|
18
|
-
assert_equal( {:x=>1}, self.class.ann(:a) )
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_attr_b
|
22
|
-
assert_equal( {:y=>1}, $self.class.ann(:b) )
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
=end
|
27
|
-
|