doodle 0.0.10 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/CREDITS +22 -0
  2. data/{ChangeLog → History.txt} +22 -3
  3. data/License.txt +20 -0
  4. data/Manifest.txt +61 -0
  5. data/README.txt +166 -0
  6. data/Rakefile +4 -0
  7. data/config/hoe.rb +77 -0
  8. data/config/requirements.rb +15 -0
  9. data/examples/doodle-errors.rb +25 -0
  10. data/examples/event-location.rb +3 -7
  11. data/examples/example-01.rb +1 -1
  12. data/examples/example-01.rdoc +3 -3
  13. data/examples/example-02.rb +15 -4
  14. data/examples/example-02.rdoc +17 -5
  15. data/examples/mail-datatypes.rb +104 -0
  16. data/examples/mail.rb +85 -0
  17. data/examples/parent.rb +40 -0
  18. data/examples/profile-options.rb +67 -0
  19. data/examples/smtp_tls.rb +65 -0
  20. data/examples/test-datatypes.rb +55 -0
  21. data/examples/yaml-example.rb +40 -0
  22. data/examples/yaml-example2.rb +42 -0
  23. data/lib/doodle.rb +364 -301
  24. data/lib/doodle/datatypes.rb +148 -0
  25. data/lib/doodle/rfc822.rb +31 -0
  26. data/lib/doodle/utils.rb +13 -0
  27. data/lib/doodle/version.rb +9 -0
  28. data/log/debug.log +0 -0
  29. data/script/console +10 -0
  30. data/script/destroy +14 -0
  31. data/script/generate +14 -0
  32. data/script/txt2html +82 -0
  33. data/setup.rb +1585 -0
  34. data/spec/arg_order_spec.rb +5 -5
  35. data/spec/attributes_spec.rb +66 -24
  36. data/spec/bugs_spec.rb +109 -6
  37. data/spec/class_spec.rb +7 -4
  38. data/spec/class_validation_spec.rb +46 -0
  39. data/spec/class_var_spec.rb +76 -0
  40. data/spec/collector_spec.rb +16 -30
  41. data/spec/conversion_spec.rb +8 -3
  42. data/spec/defaults_spec.rb +4 -4
  43. data/spec/doodle_context_spec.rb +3 -4
  44. data/spec/doodle_spec.rb +25 -15
  45. data/spec/extra_args_spec.rb +1 -1
  46. data/spec/factory_spec.rb +3 -3
  47. data/spec/init_spec.rb +11 -11
  48. data/spec/new_doodle_spec.rb +19 -0
  49. data/spec/required_spec.rb +1 -1
  50. data/spec/serialization_spec.rb +3 -6
  51. data/spec/singleton_spec.rb +5 -5
  52. data/spec/spec.opts +1 -0
  53. data/spec/spec_helper.rb +44 -0
  54. data/spec/superclass_spec.rb +6 -5
  55. data/spec/validation2_spec.rb +248 -0
  56. data/spec/validation_spec.rb +26 -37
  57. data/tasks/deployment.rake +34 -0
  58. data/tasks/environment.rake +7 -0
  59. data/tasks/rspec.rake +21 -0
  60. data/tasks/website.rake +17 -0
  61. metadata +76 -20
  62. data/COPYING +0 -18
  63. data/README +0 -57
  64. data/examples/event.rb +0 -39
  65. data/examples/example-03.rb +0 -45
  66. data/examples/example-03.rdoc +0 -55
  67. data/lib/semantic.cache +0 -8
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
3
3
  describe 'arg_order' do
4
4
  temporary_constant :Foo do
5
5
  before :each do
6
- class Foo < Doodle::Base
6
+ class Foo < Doodle
7
7
  has :name
8
8
  has :extra
9
9
  has :value
@@ -33,7 +33,7 @@ end
33
33
  describe 'arg_order' do
34
34
  temporary_constants :Foo, :Bar do
35
35
  before :each do
36
- class Foo < Doodle::Base
36
+ class Foo < Doodle
37
37
  has :name
38
38
  end
39
39
  class Bar < Foo
@@ -51,7 +51,7 @@ end
51
51
  describe 'arg_order' do
52
52
  temporary_constants :Foo, :Bar do
53
53
  before :each do
54
- class Foo < Doodle::Base
54
+ class Foo < Doodle
55
55
  has :name
56
56
  end
57
57
  class Bar < Foo
@@ -70,7 +70,7 @@ end
70
70
  describe 'arg_order' do
71
71
  temporary_constants :Foo, :Bar do
72
72
  before :each do
73
- class Foo < Doodle::Base
73
+ class Foo < Doodle
74
74
  has :name, :default => proc { self.class.to_s.downcase }
75
75
  end
76
76
  class Bar < Foo
@@ -90,7 +90,7 @@ end
90
90
  describe 'arg_order' do
91
91
  temporary_constants :Foo, :Bar do
92
92
  before :each do
93
- class Foo < Doodle::Base
93
+ class Foo < Doodle
94
94
  has :name
95
95
  end
96
96
  class Bar < Foo
@@ -4,29 +4,40 @@ describe Doodle::Attribute, 'basics' do
4
4
  temporary_constants :Foo, :Bar do
5
5
  before(:each) do
6
6
  class Foo
7
- include Doodle::Helper
8
- has :name, :default => 'Hello'
7
+ include Doodle::Core
8
+ has :ivar1, :default => 'Hello'
9
9
  class << self
10
- has :metadata
10
+ has :cvar1
11
11
  end
12
12
  end
13
13
  class Bar < Foo
14
- has :info
14
+ has :ivar2
15
15
  class << self
16
- has :doc
16
+ has :cvar2
17
17
  end
18
18
  end
19
19
 
20
20
  @foo = Foo.new
21
- @bar = Bar.new :info => 'Hi'
21
+ class << @foo
22
+ has :svar1
23
+ end
24
+ @bar = Bar.new :ivar2 => 'Hi'
25
+ class << @bar
26
+ has :svar2
27
+ end
22
28
  end
23
29
 
24
- it 'should have attribute :name with default defined' do
25
- @foo.attributes[:name].default.should == 'Hello'
30
+ after :each do
31
+ @bar = nil
32
+ @foo = nil
33
+ end
34
+
35
+ it 'should have attribute :ivar1 with default defined' do
36
+ @foo.attributes[:ivar1].default.should == 'Hello'
26
37
  end
27
38
 
28
39
  it 'should have default name' do
29
- @foo.name.should == 'Hello'
40
+ @foo.ivar1.should == 'Hello'
30
41
  end
31
42
 
32
43
  it 'should not have an instance variable for a default' do
@@ -34,47 +45,77 @@ describe Doodle::Attribute, 'basics' do
34
45
  end
35
46
 
36
47
  it 'should have name required == false (because has default)' do
37
- @foo.attributes[:name].required?.should == false
48
+ @foo.attributes[:ivar1].required?.should == false
38
49
  end
39
50
 
40
- it 'should have info required == true' do
41
- @bar.attributes[:info].required?.should == true
51
+ it 'should have ivar2 required == true' do
52
+ @bar.attributes[:ivar2].required?.should == true
42
53
  end
43
54
 
44
55
  it 'should have name.optional? == true (because has default)' do
45
- @foo.attributes[:name].optional?.should == true
56
+ @foo.attributes[:ivar1].optional?.should == true
46
57
  end
47
58
 
48
59
  it 'should inherit attribute from parent' do
49
- @bar.attributes[:name].should == @foo.attributes[:name]
60
+ @bar.attributes[:ivar1].should == @foo.attributes[:ivar1]
50
61
  end
51
62
 
52
- it 'should have info.optional? == false' do
53
- @bar.attributes[:info].optional?.should == false
63
+ it 'should have ivar2.optional? == false' do
64
+ @bar.attributes[:ivar2].optional?.should == false
54
65
  end
55
66
 
56
67
  it "should have parents in correct order" do
57
- Bar.parents.should == [Foo, Object]
68
+ expected_parents = RUBY_VERSION <= "1.8.6" ? [Foo, Object] : [Foo, Object, BasicObject]
69
+ Bar.parents.should == expected_parents
58
70
  end
59
71
 
60
72
  it "should have Bar's singleton parents in reverse order of definition" do
61
- @bar.singleton_class.parents.should == [Bar.singleton_class.singleton_class, Bar.singleton_class, Foo.singleton_class]
73
+ @bar.singleton_class.parents.should == []
74
+ end
75
+
76
+ it 'should have singleton_class attributes in order of definition' do
77
+ Bar.singleton_class.attributes.keys.should == [:cvar2]
78
+ end
79
+
80
+ it 'should have inherited class_attributes in order of definition' do
81
+ Bar.class_attributes.keys.should == [:cvar1, :cvar2]
62
82
  end
63
83
 
64
- it 'should have inherited singleton local_attributes in order of definition' do
65
- @bar.singleton_class.class_eval { collect_inherited(:local_attributes).map { |x| x[0]} }.should == [:metadata, :doc]
84
+ it 'should have inherited class_attributes in order of definition' do
85
+ @bar.class_attributes.keys.should == [:cvar1, :cvar2]
86
+ end
87
+
88
+ it 'should have local class attributes in order of definition' do
89
+ Bar.singleton_class.attributes(false).keys.should == [:cvar2]
66
90
  end
67
91
 
68
- it 'should have inherited singleton attributes in order of definition' do
69
- @bar.singleton_class.attributes.keys.should == [:metadata, :doc]
92
+ it 'should not inherit singleton local_attributes' do
93
+ @bar.singleton_class.class_eval { collect_inherited(:local_attributes).map { |x| x[0]} }.should == []
70
94
  end
95
+
96
+ it 'should not inherit singleton attributes#1' do
97
+ @bar.singleton_class.attributes.map { |x| x[0]} .should == [:svar2]
98
+ end
99
+
100
+ it 'should not inherit singleton attributes#2' do
101
+ @bar.singleton_class.attributes.keys.should == [:svar2]
102
+ end
103
+
104
+ it 'should not inherit singleton attributes#3' do
105
+ @bar.singleton_class.attributes(false).keys.should == [:svar2]
106
+ end
107
+
108
+ it 'should show singleton attributes in attributes' do
109
+ @bar.attributes.keys.should == [:ivar1, :ivar2, :svar2]
110
+ end
111
+
71
112
  end
72
113
  end
73
114
 
74
115
  describe Doodle::Attribute, 'attribute order' do
75
116
  temporary_constants :A, :B, :C do
76
117
  before :each do
77
- class A < Doodle::Base
118
+ class A < Doodle
78
119
  has :a
79
120
  end
80
121
 
@@ -88,7 +129,8 @@ describe Doodle::Attribute, 'attribute order' do
88
129
  end
89
130
 
90
131
  it 'should keep order of inherited attributes' do
91
- C.parents.should == [B, A, Doodle::Base, Object]
132
+ expected_parents = RUBY_VERSION <= "1.8.6" ? [B, A, Doodle, Object] : [B, A, Doodle, Object, BasicObject]
133
+ C.parents.should == expected_parents
92
134
  end
93
135
 
94
136
  it 'should keep order of inherited attributes' do
@@ -4,7 +4,7 @@ require 'yaml'
4
4
  describe 'Doodle', 'parents' do
5
5
  temporary_constant :Foo do
6
6
  before :each do
7
- class Foo < Doodle::Base
7
+ class Foo < Doodle
8
8
  has :var1, :kind => Integer
9
9
  has :var2, :kind => Integer, :default => 1
10
10
  must 'have var1 != var2' do
@@ -24,7 +24,7 @@ end
24
24
  describe 'Doodle', ' loading good data from yaml' do
25
25
  temporary_constant :Foo do
26
26
  before :each do
27
- class Foo < Doodle::Base
27
+ class Foo < Doodle
28
28
  has :date, :kind => Date do
29
29
  from String do |s|
30
30
  Date.parse(s)
@@ -45,7 +45,7 @@ describe 'Doodle', ' loading good data from yaml' do
45
45
  it 'should validate ok' do
46
46
  proc { foo = YAML::load(@str).validate! }.should_not raise_error
47
47
  end
48
-
48
+
49
49
  it 'should apply conversions' do
50
50
  foo = YAML::load(@str).validate!
51
51
  foo.date.should == Date.new(2000, 7, 1)
@@ -57,7 +57,7 @@ end
57
57
  describe 'Doodle', ' loading bad data from yaml' do
58
58
  temporary_constant :Foo do
59
59
  before :each do
60
- class Foo < Doodle::Base
60
+ class Foo < Doodle
61
61
  has :date, :kind => Date do
62
62
  from String do |s|
63
63
  Date.parse(s)
@@ -81,9 +81,9 @@ describe 'Doodle', ' loading bad data from yaml' do
81
81
  end
82
82
 
83
83
  describe Doodle, 'class attributes:' do
84
- temporary_constant :Foo do
84
+ temporary_constant :Foo do
85
85
  before :each do
86
- class Foo < Doodle::Base
86
+ class Foo < Doodle
87
87
  has :ivar
88
88
  class << self
89
89
  has :cvar
@@ -96,3 +96,106 @@ describe Doodle, 'class attributes:' do
96
96
  end
97
97
  end
98
98
  end
99
+
100
+ describe Doodle, 'initializing from hashes and yaml' do
101
+ temporary_constants :AddressLine, :Person do
102
+ before :each do
103
+ class AddressLine < Doodle
104
+ has :text, :kind => String
105
+ end
106
+
107
+ class Person < Doodle
108
+ has :name, :kind => String
109
+ has :address, :collect => { :line => AddressLine }
110
+ end
111
+ end
112
+
113
+ it 'should validate ouput from to_yaml' do
114
+
115
+ yaml = %[
116
+ ---
117
+ :address:
118
+ - Henry Wood House
119
+ - London
120
+ :name: Sean
121
+ ]
122
+
123
+ person = Person(YAML.load(yaml))
124
+ yaml = person.to_yaml
125
+ # be careful here - Ruby yaml is finicky (spaces after class names)
126
+ yaml = yaml.gsub(/\s*\n/m, "\n")
127
+ yaml.should == %[--- !ruby/object:Person
128
+ address:
129
+ - !ruby/object:AddressLine
130
+ text: Henry Wood House
131
+ - !ruby/object:AddressLine
132
+ text: London
133
+ name: Sean
134
+ ]
135
+ person = YAML.load(yaml)
136
+ proc { person.validate! }.should_not raise_error
137
+ person.address.all?{ |x| x.kind_of? AddressLine }.should == true
138
+
139
+ end
140
+ end
141
+ end
142
+
143
+ describe 'Doodle', 'hiding @__doodle__' do
144
+ temporary_constant :Foo, :Bar, :DString, :DHash, :DArray do
145
+ before :each do
146
+ class Foo < Doodle
147
+ has :var1, :kind => Integer
148
+ end
149
+ class Bar
150
+ include Doodle::Core
151
+ has :var2, :kind => Integer
152
+ end
153
+ class DString < String
154
+ include Doodle::Core
155
+ end
156
+ class DHash < Hash
157
+ include Doodle::Core
158
+ end
159
+ class DArray < Array
160
+ include Doodle::Core
161
+ end
162
+ end
163
+
164
+ it 'should not reveal @__doodle__ in inspect string' do
165
+ foo = Foo 2
166
+ foo.inspect.should_not =~ /@__doodle__/
167
+ end
168
+ it 'should not include @__doodle__ in instance_variables' do
169
+ foo = Foo 2
170
+ foo.instance_variables.size.should == 1
171
+ foo.instance_variables.first.should =~ /^@var1$/
172
+ end
173
+ it 'should not reveal @__doodle__ in inspect string' do
174
+ foo = Bar 2
175
+ foo.inspect.should_not =~ /@__doodle__/
176
+ end
177
+ it 'should not include @__doodle__ in instance_variables' do
178
+ foo = Bar 2
179
+ foo.instance_variables.size.should == 1
180
+ foo.instance_variables.first.should =~ /^@var2$/
181
+ end
182
+ it 'should correctly inspect when using included module' do
183
+ foo = Bar 2
184
+ foo.inspect.should =~ /#<Bar:0x[a-z0-9]+ @var2=2>/
185
+ end
186
+ it 'should correctly inspect string' do
187
+ foo = DString("Hello")
188
+ foo.inspect.should == '"Hello"'
189
+ end
190
+ it 'should correctly inspect hash' do
191
+ foo = DHash.new(2)
192
+ foo[:a] = 1
193
+ foo.inspect.should == '{:a=>1}'
194
+ foo[:b].should == 2
195
+ end
196
+ it 'should correctly inspect array' do
197
+ foo = DArray(3, 2)
198
+ foo.inspect.should == '[2, 2, 2]'
199
+ end
200
+ end
201
+ end
@@ -4,14 +4,14 @@ describe Doodle, 'class attributes' do
4
4
  temporary_constants :Bar, :Foo do
5
5
  before(:each) do
6
6
  class Foo
7
- include Doodle::Helper
7
+ include Doodle::Core
8
8
  class << self
9
9
  has :metadata
10
10
  end
11
11
  end
12
12
  @foo = Foo.new
13
13
  class Bar < Foo
14
- include Doodle::Helper
14
+ include Doodle::Core
15
15
  class << self
16
16
  has :doc
17
17
  end
@@ -76,8 +76,11 @@ describe Doodle, 'class attributes' do
76
76
  Bar.singleton_class.attributes(false).keys.should == [:doc]
77
77
  end
78
78
 
79
- it "should list all class's own attributes" do
80
- Bar.singleton_class.attributes.keys.should == [:metadata, :doc]
79
+ it "should list all class's singleton attributes" do
80
+ Bar.singleton_class.attributes.keys.should == [:doc]
81
+ end
82
+ it "should list all class's class_attributes" do
83
+ Bar.class_attributes.keys.should == [:metadata, :doc]
81
84
  end
82
85
  end
83
86
  end
@@ -0,0 +1,46 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Doodle, 'class validations' do
4
+ temporary_constants :Foo, :Bar do
5
+ before :each do
6
+ class Foo < Doodle
7
+ class << self
8
+ has :meta, { :default => "data", :kind => String } do
9
+ must "be >= 3 chars long" do |s|
10
+ s.size >= 3
11
+ end
12
+ end
13
+ end
14
+ end
15
+ class Bar < Foo
16
+ end
17
+ end
18
+
19
+ it 'should validate singleton class attributes' do
20
+ proc { Foo.meta = 1 }.should raise_error(Doodle::ValidationError)
21
+ end
22
+
23
+ it 'should reject invalid singleton class attributes specified with must clause' do
24
+ proc { Foo.meta = "a" }.should raise_error(Doodle::ValidationError)
25
+ end
26
+
27
+ it 'should accept valid singleton class attributes specified with must clause' do
28
+ proc { Foo.meta = "abc" }.should_not raise_error
29
+ end
30
+
31
+ it 'should validate inherited singleton class attributes' do
32
+ proc { Bar.meta = 1 }.should raise_error(Doodle::ValidationError)
33
+ end
34
+
35
+ it 'should reject invalid inherited singleton class attributes specified with must clause' do
36
+ proc { Bar.meta = "a" }.should raise_error(Doodle::ValidationError)
37
+ end
38
+
39
+ it 'should accept valid inherited singleton class attributes specified with must clause' do
40
+ proc { Bar.meta = "abc" }.should_not raise_error
41
+ end
42
+
43
+ end
44
+ end
45
+
46
+
@@ -0,0 +1,76 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Doodle, 'class attributes:' do
4
+ temporary_constant :Foo, :Bar do
5
+ before :each do
6
+ class Foo < Doodle
7
+ has :ivar
8
+ class << self
9
+ has :cvar, :kind => Integer, :init => 1
10
+ end
11
+ end
12
+ class Bar < Doodle
13
+ end
14
+ end
15
+
16
+ it 'should be possible to set a class var without setting an instance var' do
17
+ proc { Foo.cvar = 42 }.should_not raise_error
18
+ Foo.cvar.should == 42
19
+ end
20
+
21
+ it 'should be possible to set an instance variable without setting a class var' do
22
+ proc { Foo.new :ivar => 42 }.should_not raise_error
23
+ end
24
+
25
+ it 'should be possible to set a class variable without setting an newly added instance var' do
26
+ proc {
27
+ foo = Bar.new
28
+ class << Bar
29
+ has :cvar, :init => 43
30
+ end
31
+ class Bar < Doodle
32
+ has :ivar
33
+ end
34
+ Bar.cvar = 44
35
+ }.should_not raise_error
36
+ end
37
+
38
+ it 'should be possible to set a singleton variable without setting an instance var' do
39
+ proc {
40
+ class Bar < Doodle
41
+ has :ivar
42
+ end
43
+ foo = Bar.new :ivar => 42
44
+ class << foo
45
+ has :svar, :init => 43
46
+ end
47
+ foo.svar = 44
48
+ }.should_not raise_error
49
+ end
50
+
51
+ it 'should be possible to set a singleton variable without setting a newly added instance var' do
52
+ pending 'figuring out if this is a pathological case and if so how to handle it' do
53
+ proc {
54
+ foo = Bar.new
55
+ class << foo
56
+ has :svar, :init => 43
57
+ end
58
+ class Bar < Doodle
59
+ has :ivar
60
+ end
61
+ foo.svar = 44
62
+ }.should_not raise_error
63
+ end
64
+ end
65
+
66
+ it 'should validate class var' do
67
+ proc { Foo.cvar = "Hello" }.should raise_error(Doodle::ValidationError)
68
+ end
69
+
70
+ it 'should be possible to read initialized class var' do
71
+ #pending 'getting this working' do
72
+ proc { Foo.cvar == 1 }.should_not raise_error
73
+ #end
74
+ end
75
+ end
76
+ end