doodle 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +24 -0
- data/Manifest.txt +26 -1
- data/README.txt +9 -8
- data/lib/doodle.rb +43 -1496
- data/lib/doodle/app.rb +6 -0
- data/lib/doodle/attribute.rb +165 -0
- data/lib/doodle/base.rb +180 -0
- data/lib/doodle/collector-1.9.rb +72 -0
- data/lib/doodle/collector.rb +191 -0
- data/lib/doodle/comparable.rb +8 -0
- data/lib/doodle/conversion.rb +80 -0
- data/lib/doodle/core.rb +42 -0
- data/lib/doodle/datatype-holder.rb +39 -0
- data/lib/doodle/debug.rb +20 -0
- data/lib/doodle/deferred.rb +13 -0
- data/lib/doodle/equality.rb +21 -0
- data/lib/doodle/exceptions.rb +29 -0
- data/lib/doodle/factory.rb +91 -0
- data/lib/doodle/getter-setter.rb +154 -0
- data/lib/doodle/info.rb +298 -0
- data/lib/doodle/inherit.rb +40 -0
- data/lib/doodle/json.rb +38 -0
- data/lib/doodle/marshal.rb +16 -0
- data/lib/doodle/normalized_array.rb +512 -0
- data/lib/doodle/normalized_hash.rb +356 -0
- data/lib/doodle/ordered-hash.rb +8 -0
- data/lib/doodle/singleton.rb +23 -0
- data/lib/doodle/smoke-and-mirrors.rb +23 -0
- data/lib/doodle/to_hash.rb +17 -0
- data/lib/doodle/utils.rb +173 -11
- data/lib/doodle/validation.rb +122 -0
- data/lib/doodle/version.rb +1 -1
- data/lib/molic_orderedhash.rb +24 -10
- data/spec/assigned_spec.rb +45 -0
- data/spec/attributes_spec.rb +7 -7
- data/spec/collector_spec.rb +100 -13
- data/spec/doodle_context_spec.rb +5 -5
- data/spec/from_spec.rb +43 -3
- data/spec/json_spec.rb +232 -0
- data/spec/member_init_spec.rb +11 -11
- data/spec/modules_spec.rb +4 -4
- data/spec/multi_collector_spec.rb +91 -0
- data/spec/must_spec.rb +32 -0
- data/spec/spec_helper.rb +14 -4
- data/spec/specialized_attribute_class_spec.rb +2 -2
- data/spec/typed_collector_spec.rb +57 -0
- data/spec/xml_spec.rb +8 -8
- metadata +33 -3
data/spec/must_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe 'Doodle', '#must' do
|
4
|
+
temporary_constant :Answer do
|
5
|
+
before :each do
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'can be specified has params' do
|
9
|
+
class Answer < Doodle
|
10
|
+
has :value, :must => { "equal 42" => proc {|i| i == 42 }}
|
11
|
+
end
|
12
|
+
name = Answer.new(42)
|
13
|
+
name.value.should_be 42
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'can combine with #must clause defined in block' do
|
17
|
+
class Answer < Doodle
|
18
|
+
has :value, :must => { "be greater than 41" => proc {|i| i > 41 }} do
|
19
|
+
must "be less than 43" do |i|
|
20
|
+
i < 43
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
name = Answer.new(42)
|
26
|
+
name.value.should_be 42
|
27
|
+
|
28
|
+
expect_error(/be greater than 41/) { Answer.new(41) }
|
29
|
+
expect_error(/be less than 43/) { Answer.new(43) }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -30,20 +30,26 @@ def undefine_const(*consts)
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def raise_if_defined(*args)
|
33
|
+
where = args.shift
|
33
34
|
defined = args.select{ |x| Object.const_defined?(x)}
|
34
|
-
raise "Namespace pollution: #{defined.join(', ')}" if defined.size > 0
|
35
|
+
raise "Namespace pollution #{where}: #{defined.join(', ')}" if defined.size > 0
|
35
36
|
end
|
36
37
|
|
37
38
|
def temporary_constants(*args, &block)
|
39
|
+
constants = Object.constants.dup
|
38
40
|
before :each do
|
39
|
-
raise_if_defined(*args)
|
41
|
+
raise_if_defined(:before, *args)
|
40
42
|
end
|
41
43
|
after :each do
|
42
44
|
undefine_const(*args)
|
43
45
|
end
|
44
|
-
|
46
|
+
crud = Object.constants - constants
|
47
|
+
if crud.size > 0
|
48
|
+
raise Exception, "Namespace crud: #{crud.map{ |x| x.to_s}.join(', ')}"
|
49
|
+
end
|
50
|
+
raise_if_defined(:begin, *args)
|
45
51
|
yield
|
46
|
-
raise_if_defined(*args)
|
52
|
+
raise_if_defined(:end, *args)
|
47
53
|
end
|
48
54
|
alias :temporary_constant :temporary_constants
|
49
55
|
|
@@ -56,3 +62,7 @@ end
|
|
56
62
|
def no_error(&block)
|
57
63
|
proc(&block).should_not raise_error
|
58
64
|
end
|
65
|
+
|
66
|
+
def expect_error(*args, &block)
|
67
|
+
proc(&block).should raise_error(*args)
|
68
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Doodle, 'typed collector' do
|
4
|
+
temporary_constants :Item, :List do
|
5
|
+
before :each do
|
6
|
+
#: definition
|
7
|
+
class ::Item < Doodle
|
8
|
+
has :name, :kind => String
|
9
|
+
end
|
10
|
+
class ::List < Doodle
|
11
|
+
has :items, :init => Doodle::TypedArray(Item), :collect => Item
|
12
|
+
#has :items, :collect => Item
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should accept convertible values in collector' do
|
17
|
+
list = nil
|
18
|
+
no_error {
|
19
|
+
list = List do
|
20
|
+
item "Hello"
|
21
|
+
item "World"
|
22
|
+
end
|
23
|
+
}
|
24
|
+
list.items.size.should_be 2
|
25
|
+
list.items[1].should_be Item("World")
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should accept correctly typed values in collector' do
|
29
|
+
list = nil
|
30
|
+
no_error {
|
31
|
+
list = List do
|
32
|
+
item Item("Hello")
|
33
|
+
item Item("World")
|
34
|
+
end
|
35
|
+
}
|
36
|
+
list.items.size.should_be 2
|
37
|
+
list.items[1].should_be Item("World")
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should prevent adding invalid values' do
|
41
|
+
list = List.new
|
42
|
+
expect_error(TypeError) {
|
43
|
+
list.items << "Hello"
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should accept valid values' do
|
48
|
+
list = List.new
|
49
|
+
no_error {
|
50
|
+
list.items << Item("Hello")
|
51
|
+
}
|
52
|
+
list.items.size.should_be 1
|
53
|
+
list.items[0].should_be Item("Hello")
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/spec/xml_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
require 'doodle/xml'
|
3
3
|
|
4
|
-
describe Doodle, '
|
4
|
+
describe Doodle, 'XML serialization within a module' do
|
5
5
|
temporary_constants :Container, :Base, :Slideshow, :Layout do
|
6
6
|
before(:each) do
|
7
7
|
@xml_source = '<Slideshow id="1" name="test"><Layout template="generic" /></Slideshow>'
|
@@ -43,7 +43,7 @@ describe Doodle, 'xml serialization within a module' do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
describe Doodle, '
|
46
|
+
describe Doodle, 'XML serialization at top level' do
|
47
47
|
temporary_constants :Base, :Slideshow, :Layout do
|
48
48
|
before(:each) do
|
49
49
|
@xml_source = '<Slideshow id="1" name="test"><Layout template="generic" /></Slideshow>'
|
@@ -83,7 +83,7 @@ describe Doodle, 'xml serialization at top level' do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
describe Doodle, '
|
86
|
+
describe Doodle, 'XML' do
|
87
87
|
temporary_constant :Address do
|
88
88
|
before :each do
|
89
89
|
class Address < Doodle
|
@@ -93,7 +93,7 @@ describe Doodle, 'if default specified before required attributes, they are igno
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
it 'should raise an error
|
96
|
+
it 'should not raise an error when supplying attribute values' do
|
97
97
|
proc {
|
98
98
|
Address do
|
99
99
|
city "London"
|
@@ -101,14 +101,14 @@ describe Doodle, 'if default specified before required attributes, they are igno
|
|
101
101
|
}.should_not raise_error
|
102
102
|
end
|
103
103
|
|
104
|
-
it 'should
|
104
|
+
it 'should accept attributes defined in block' do
|
105
105
|
a = Address do
|
106
106
|
city "London"
|
107
107
|
end
|
108
108
|
a.city.should_be "London"
|
109
109
|
end
|
110
110
|
|
111
|
-
it 'should output
|
111
|
+
it 'should output non-doodle attributes as XML attributes' do
|
112
112
|
a = Address do
|
113
113
|
city "London"
|
114
114
|
end
|
@@ -117,7 +117,7 @@ describe Doodle, 'if default specified before required attributes, they are igno
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
describe Doodle, '
|
120
|
+
describe Doodle, 'XML' do
|
121
121
|
temporary_constant :Base, :City, :Address do
|
122
122
|
before :each do
|
123
123
|
class Base < Doodle
|
@@ -160,7 +160,7 @@ describe Doodle, 'if default specified before required attributes, they are igno
|
|
160
160
|
|
161
161
|
end
|
162
162
|
|
163
|
-
describe Doodle, '
|
163
|
+
describe Doodle, 'XML' do
|
164
164
|
temporary_constant :Base, :City, :Address, :Country do
|
165
165
|
before :each do
|
166
166
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doodle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean O'Halpin
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-14 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -62,13 +62,38 @@ files:
|
|
62
62
|
- examples/test-datatypes.rb
|
63
63
|
- examples/yaml-example.rb
|
64
64
|
- examples/yaml-example2.rb
|
65
|
-
- lib/doodle.rb
|
66
65
|
- lib/doodle/app.rb
|
66
|
+
- lib/doodle/attribute.rb
|
67
|
+
- lib/doodle/base.rb
|
68
|
+
- lib/doodle/collector-1.9.rb
|
69
|
+
- lib/doodle/collector.rb
|
70
|
+
- lib/doodle/comparable.rb
|
71
|
+
- lib/doodle/conversion.rb
|
72
|
+
- lib/doodle/core.rb
|
73
|
+
- lib/doodle/datatype-holder.rb
|
67
74
|
- lib/doodle/datatypes.rb
|
75
|
+
- lib/doodle/debug.rb
|
76
|
+
- lib/doodle/deferred.rb
|
77
|
+
- lib/doodle/equality.rb
|
78
|
+
- lib/doodle/exceptions.rb
|
79
|
+
- lib/doodle/factory.rb
|
80
|
+
- lib/doodle/getter-setter.rb
|
81
|
+
- lib/doodle/info.rb
|
82
|
+
- lib/doodle/inherit.rb
|
83
|
+
- lib/doodle/json.rb
|
84
|
+
- lib/doodle/marshal.rb
|
85
|
+
- lib/doodle/normalized_array.rb
|
86
|
+
- lib/doodle/normalized_hash.rb
|
87
|
+
- lib/doodle/ordered-hash.rb
|
68
88
|
- lib/doodle/rfc822.rb
|
89
|
+
- lib/doodle/singleton.rb
|
90
|
+
- lib/doodle/smoke-and-mirrors.rb
|
91
|
+
- lib/doodle/to_hash.rb
|
69
92
|
- lib/doodle/utils.rb
|
93
|
+
- lib/doodle/validation.rb
|
70
94
|
- lib/doodle/version.rb
|
71
95
|
- lib/doodle/xml.rb
|
96
|
+
- lib/doodle.rb
|
72
97
|
- lib/molic_orderedhash.rb
|
73
98
|
- log/debug.log
|
74
99
|
- script/console
|
@@ -147,6 +172,7 @@ specification_version: 2
|
|
147
172
|
summary: "Doodle is a gem for simplifying the definition of Ruby classes by making attributes and their properties more declarative. Doodle is eco-friendly: it does not globally modify Object, Class or Module."
|
148
173
|
test_files:
|
149
174
|
- spec/arg_order_spec.rb
|
175
|
+
- spec/assigned_spec.rb
|
150
176
|
- spec/attributes_spec.rb
|
151
177
|
- spec/block_init_spec.rb
|
152
178
|
- spec/bugs_spec.rb
|
@@ -166,9 +192,12 @@ test_files:
|
|
166
192
|
- spec/has_spec.rb
|
167
193
|
- spec/inheritance_spec.rb
|
168
194
|
- spec/init_spec.rb
|
195
|
+
- spec/json_spec.rb
|
169
196
|
- spec/kind_spec.rb
|
170
197
|
- spec/member_init_spec.rb
|
171
198
|
- spec/modules_spec.rb
|
199
|
+
- spec/multi_collector_spec.rb
|
200
|
+
- spec/must_spec.rb
|
172
201
|
- spec/new_doodle_spec.rb
|
173
202
|
- spec/readonly_spec.rb
|
174
203
|
- spec/required_spec.rb
|
@@ -178,6 +207,7 @@ test_files:
|
|
178
207
|
- spec/superclass_spec.rb
|
179
208
|
- spec/symbolize_keys_spec.rb
|
180
209
|
- spec/to_hash_spec.rb
|
210
|
+
- spec/typed_collector_spec.rb
|
181
211
|
- spec/validation2_spec.rb
|
182
212
|
- spec/validation_spec.rb
|
183
213
|
- spec/xml_spec.rb
|