doodle 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +36 -7
- data/lib/doodle.rb +71 -42
- data/spec/arg_order_spec.rb +81 -98
- data/spec/attributes_spec.rb +70 -82
- data/spec/bugs_spec.rb +21 -0
- data/spec/class_spec.rb +63 -70
- data/spec/collector_spec.rb +97 -0
- data/spec/conversion_spec.rb +1 -3
- data/spec/defaults_spec.rb +104 -125
- data/spec/doodle_spec.rb +240 -227
- data/spec/flatten_first_level_spec.rb +4 -3
- data/spec/init_spec.rb +45 -49
- data/spec/required_spec.rb +9 -17
- data/spec/serialization_spec.rb +32 -0
- data/spec/superclass_spec.rb +17 -20
- data/spec/validation_spec.rb +79 -88
- metadata +5 -6
- data/examples/example-01.rdoc +0 -16
- data/examples/example-02.rdoc +0 -62
- data/examples/foo.rb +0 -10
- data/lib/spec_helper.rb +0 -19
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'lib/doodle'
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
4
2
|
|
5
3
|
describe 'flatten_first_level' do
|
6
4
|
|
@@ -26,6 +24,9 @@ describe 'flatten_first_level' do
|
|
26
24
|
[1, [2, 3]],
|
27
25
|
]
|
28
26
|
end
|
27
|
+
after :each do
|
28
|
+
remove_ivars :data, :results
|
29
|
+
end
|
29
30
|
|
30
31
|
it 'should flatten first level' do
|
31
32
|
@data.zip(@results).each do |input, result|
|
data/spec/init_spec.rb
CHANGED
@@ -1,57 +1,53 @@
|
|
1
|
-
|
2
|
-
require 'lib/spec_helper'
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
3
2
|
|
4
3
|
describe Doodle, 'init' do
|
4
|
+
temporary_constant :Foo do
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
before(:each) do
|
7
|
+
class Foo
|
8
|
+
include Doodle::Helper
|
9
|
+
has :name, :init => 'D1'
|
10
|
+
class << self
|
11
|
+
has :metadata, :init => 'D2'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
@foo = Foo.new
|
15
|
+
class << @foo
|
16
|
+
has :special, :init => 'D3'
|
13
17
|
end
|
14
18
|
end
|
15
|
-
@foo = Foo.new
|
16
|
-
class << @foo
|
17
|
-
has :special, :init => 'D3'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
after :each do
|
21
|
-
undefine_const :Foo
|
22
|
-
end
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
20
|
+
it 'should have instance attribute init via class' do
|
21
|
+
Foo.attributes[:name].init.should == 'D1'
|
22
|
+
end
|
23
|
+
it 'should have instance attribute init via instance' do
|
24
|
+
@foo.attributes[:name].init.should == 'D1'
|
25
|
+
end
|
26
|
+
it 'should have class attribute init via class.singleton_class' do
|
27
|
+
Foo.singleton_class.attributes(false)[:metadata].init.should == 'D2'
|
28
|
+
end
|
29
|
+
it 'should have class attribute init via class.singleton_class' do
|
30
|
+
Foo.singleton_class.attributes[:metadata].init.should == 'D2'
|
31
|
+
end
|
32
|
+
it 'should have singleton attribute init via instance.singleton_class' do
|
33
|
+
@foo.singleton_class.attributes(false)[:special].init.should == 'D3'
|
34
|
+
end
|
35
|
+
it 'should have singleton attribute init via instance.singleton_class' do
|
36
|
+
@foo.singleton_class.attributes[:special].init.should == 'D3'
|
37
|
+
end
|
38
|
+
it 'should have an attribute :name from init' do
|
39
|
+
@foo.name.should == 'D1'
|
40
|
+
end
|
41
|
+
it 'should have an instance_variable for attribute :name' do
|
42
|
+
@foo.instance_variables.include?('@name').should == true
|
43
|
+
end
|
44
|
+
it 'should have an initialized class attribute :metadata' do
|
45
|
+
pending 'deciding how this should work'
|
46
|
+
#Foo.metadata.should == 'D2'
|
47
|
+
end
|
48
|
+
it 'should have an initialized singleton attribute :special' do
|
49
|
+
pending 'deciding how this should work'
|
50
|
+
#@foo.special.should == 'D3'
|
51
|
+
end
|
55
52
|
end
|
56
53
|
end
|
57
|
-
raise_if_defined :Foo
|
data/spec/required_spec.rb
CHANGED
@@ -1,25 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'lib/spec_helper'
|
4
|
-
require 'date'
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
5
2
|
|
6
3
|
describe Doodle, 'defaults which have not been set' do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
class Foo < Doodle::Base
|
14
|
-
has :baz
|
15
|
-
has :start do
|
16
|
-
default { Date.today }
|
4
|
+
temporary_constant :Foo do
|
5
|
+
before :each do
|
6
|
+
class Foo < Doodle::Base
|
7
|
+
has :baz
|
8
|
+
has :start, :default => 1
|
17
9
|
end
|
18
10
|
end
|
19
|
-
end
|
20
11
|
|
21
|
-
|
22
|
-
|
12
|
+
it 'should have raise error if required value not set' do
|
13
|
+
proc { Foo.new }.should raise_error(ArgumentError)
|
14
|
+
end
|
23
15
|
end
|
24
16
|
end
|
25
17
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
describe Doodle, "Serialization" do
|
5
|
+
temporary_constant :Foo do
|
6
|
+
before :each do
|
7
|
+
class Foo < Doodle::Base
|
8
|
+
has :var, :kind => Integer
|
9
|
+
end
|
10
|
+
@foo = Foo 42
|
11
|
+
end
|
12
|
+
after :each do
|
13
|
+
remove_ivars :foo
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be serializable to yaml" do
|
17
|
+
@foo.to_yaml.should == "--- !ruby/object:Foo \nvar: 42\n"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be loadable from yaml" do
|
21
|
+
src = @foo.to_yaml
|
22
|
+
new_foo = YAML::load(src)
|
23
|
+
new_foo.var.should == 42
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should make it possible to validate already set instance variables" do
|
27
|
+
new_foo = YAML::load("--- !ruby/object:Foo \nvar: Hello World!\n")
|
28
|
+
proc { new_foo.validate!(true) }.should raise_error(Doodle::ValidationError)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/spec/superclass_spec.rb
CHANGED
@@ -1,27 +1,24 @@
|
|
1
|
-
require '
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
|
-
describe 'Doodle', '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
describe 'Doodle', 'parents' do
|
4
|
+
temporary_constant :Foo do
|
5
|
+
before :each do
|
6
|
+
class Foo < Doodle::Base
|
7
|
+
end
|
8
|
+
@foo = Foo.new
|
9
|
+
@sc = class << @foo; self; end
|
10
|
+
@scc = class << @sc; self; end
|
11
|
+
@sclass_doodle_root = class << Doodle::Base; self; end
|
12
|
+
@sclass_foo = class << @foo; class << self; self; end; end
|
11
13
|
end
|
12
|
-
@foo = Foo.new
|
13
|
-
@sc = class << @foo; self; end
|
14
|
-
@scc = class << @sc; self; end
|
15
|
-
@sclass_doodle_root = class << Doodle::Base; self; end
|
16
|
-
@sclass_foo = class << @foo; class << self; self; end; end
|
17
|
-
end
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
it 'should have singleton class parents == class, doodle root' do
|
16
|
+
@sc.parents.should == [@sclass_foo, @sclass_doodle_root]
|
17
|
+
end
|
22
18
|
|
23
|
-
|
24
|
-
|
19
|
+
it "should have singleton class's singleton class parents == []" do
|
20
|
+
@scc.parents.should == []
|
21
|
+
end
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
data/spec/validation_spec.rb
CHANGED
@@ -1,108 +1,99 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'lib/spec_helper'
|
4
|
-
require 'date'
|
5
|
-
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
6
2
|
|
7
3
|
describe :DateRange, 'validation & conversions' do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
from Integer do |jd|
|
37
|
-
Doodle::Debug.d { [:converting_from, Integer, jd] }
|
38
|
-
Date.new(*Date.jd_to_civil(jd))
|
4
|
+
temporary_constants :Base, :DateRange, :ClassMethods do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
module ClassMethods
|
8
|
+
def date(*a, &b)
|
9
|
+
# if a.size > 0
|
10
|
+
name = a.shift
|
11
|
+
# else
|
12
|
+
# name = :date
|
13
|
+
# end
|
14
|
+
td = has(name, :kind => Date, *a) do
|
15
|
+
# it is a bit clumsy to define these conversions &
|
16
|
+
# conditions for every attribute/typedef - could define a
|
17
|
+
# subclass of Typedef which does this by default (so we
|
18
|
+
# instances can override or defer to class level conversions
|
19
|
+
# and conditions)
|
20
|
+
from String do |s|
|
21
|
+
Date.parse(s)
|
22
|
+
end
|
23
|
+
from Array do |y,m,d|
|
24
|
+
#p [:from, Array, y, m, d]
|
25
|
+
Date.new(y, m, d)
|
26
|
+
end
|
27
|
+
from Integer do |jd|
|
28
|
+
Doodle::Debug.d { [:converting_from, Integer, jd] }
|
29
|
+
Date.new(*Date.jd_to_civil(jd))
|
30
|
+
end
|
39
31
|
end
|
32
|
+
Doodle::Debug.d { [:date, td] }
|
33
|
+
td.instance_eval(&b) if block_given? # user's block should override default
|
40
34
|
end
|
41
|
-
Doodle::Debug.d { [:date, td] }
|
42
|
-
td.instance_eval(&b) if block_given? # user's block should override default
|
43
35
|
end
|
44
|
-
end
|
45
36
|
|
46
|
-
|
47
|
-
|
48
|
-
|
37
|
+
class Base < Doodle::Base
|
38
|
+
extend ClassMethods
|
39
|
+
end
|
49
40
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
41
|
+
class DateRange < Base
|
42
|
+
date :start_date do
|
43
|
+
Doodle::Debug.d { [:start_date, self, self.class] }
|
44
|
+
default { Date.today }
|
45
|
+
must "be >= 2007-01-01" do |d|
|
46
|
+
d >= Date.new(2007, 01, 01)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
date :end_date do
|
50
|
+
default { start_date }
|
51
|
+
end
|
52
|
+
must "have end_date >= start_date" do
|
53
|
+
end_date >= start_date
|
56
54
|
end
|
57
|
-
end
|
58
|
-
date :end_date do
|
59
|
-
default { start_date }
|
60
|
-
end
|
61
|
-
must "have end_date >= start_date" do
|
62
|
-
end_date >= start_date
|
63
55
|
end
|
64
56
|
end
|
65
|
-
end
|
66
57
|
|
67
|
-
|
68
|
-
|
69
|
-
|
58
|
+
it 'should not raise an exception if end_date >= start_date' do
|
59
|
+
proc { DateRange.new('2007-01-01', '2007-01-02') }.should_not raise_error
|
60
|
+
end
|
70
61
|
|
71
|
-
|
72
|
-
|
73
|
-
|
62
|
+
it 'should raise an exception if end_date < start_date' do
|
63
|
+
proc { DateRange.new('2007-01-02', '2007-01-01') }.should raise_error
|
64
|
+
end
|
74
65
|
|
75
|
-
|
76
|
-
|
77
|
-
|
66
|
+
it 'should raise an exception if end_date < start_date' do
|
67
|
+
proc { DateRange.new('2007-01-01', '2007-01-01') }.should_not raise_error
|
68
|
+
end
|
78
69
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
70
|
+
it 'should have start_date kind == Date' do
|
71
|
+
d = DateRange.new
|
72
|
+
d.attributes[:start_date].kind == Date
|
73
|
+
end
|
83
74
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
75
|
+
it 'should have two validations' do
|
76
|
+
d = DateRange.new
|
77
|
+
d.attributes[:start_date].validations.size.should == 2
|
78
|
+
d.attributes[:start_date].validations(false).size.should == 2
|
79
|
+
end
|
89
80
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
81
|
+
it 'should have two conversions' do
|
82
|
+
d = DateRange.new
|
83
|
+
d.attributes[:start_date].conversions.size.should == 3
|
84
|
+
d.attributes[:start_date].conversions(false).size.should == 3
|
85
|
+
end
|
95
86
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
87
|
+
it 'should convert from Array' do
|
88
|
+
d = DateRange.new [2007,01,01], [2007,01,02]
|
89
|
+
d.start_date.should == Date.new(2007,01,01)
|
90
|
+
d.end_date.should == Date.new(2007,01,02)
|
91
|
+
end
|
101
92
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
93
|
+
it 'should convert Integer representing Julian date to Date' do
|
94
|
+
d = DateRange.new 2454428, 2454429
|
95
|
+
d.start_date.should == Date.new(2007,11,23)
|
96
|
+
d.end_date.should == Date.new(2007,11,24)
|
97
|
+
end
|
106
98
|
end
|
107
|
-
|
108
99
|
end
|
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.0.
|
4
|
+
version: 0.0.5
|
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: 2008-03-
|
12
|
+
date: 2008-03-16 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -26,16 +26,12 @@ extra_rdoc_files:
|
|
26
26
|
files:
|
27
27
|
- lib/doodle.rb
|
28
28
|
- lib/molic_orderedhash.rb
|
29
|
-
- lib/spec_helper.rb
|
30
29
|
- examples/event-location.rb
|
31
30
|
- examples/event.rb
|
32
31
|
- examples/event1.rb
|
33
32
|
- examples/event2.rb
|
34
33
|
- examples/example-01.rb
|
35
|
-
- examples/example-01.rdoc
|
36
34
|
- examples/example-02.rb
|
37
|
-
- examples/example-02.rdoc
|
38
|
-
- examples/foo.rb
|
39
35
|
- README
|
40
36
|
- COPYING
|
41
37
|
- ChangeLog
|
@@ -68,12 +64,15 @@ summary: Declarative attribute definitions, validations and conversions
|
|
68
64
|
test_files:
|
69
65
|
- spec/arg_order_spec.rb
|
70
66
|
- spec/attributes_spec.rb
|
67
|
+
- spec/bugs_spec.rb
|
71
68
|
- spec/class_spec.rb
|
69
|
+
- spec/collector_spec.rb
|
72
70
|
- spec/conversion_spec.rb
|
73
71
|
- spec/defaults_spec.rb
|
74
72
|
- spec/doodle_spec.rb
|
75
73
|
- spec/flatten_first_level_spec.rb
|
76
74
|
- spec/init_spec.rb
|
77
75
|
- spec/required_spec.rb
|
76
|
+
- spec/serialization_spec.rb
|
78
77
|
- spec/superclass_spec.rb
|
79
78
|
- spec/validation_spec.rb
|