doodle 0.0.1
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 +18 -0
- data/README +57 -0
- data/examples/event.rb +30 -0
- data/examples/event1.rb +33 -0
- data/examples/event2.rb +21 -0
- data/examples/example-01.rb +16 -0
- data/examples/example-01.rdoc +16 -0
- data/examples/example-02.rb +61 -0
- data/examples/example-02.rdoc +62 -0
- data/lib/doodle.rb +800 -0
- data/lib/molic_orderedhash.rb +243 -0
- data/lib/spec_helper.rb +19 -0
- data/spec/arg_order_spec.rb +125 -0
- data/spec/attributes_spec.rb +106 -0
- data/spec/class_spec.rb +90 -0
- data/spec/conversion_spec.rb +59 -0
- data/spec/defaults_spec.rb +158 -0
- data/spec/doodle_spec.rb +297 -0
- data/spec/flatten_first_level_spec.rb +36 -0
- data/spec/required_spec.rb +25 -0
- data/spec/superclass_spec.rb +27 -0
- data/spec/validation_spec.rb +108 -0
- metadata +74 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), '../.'))
|
2
|
+
|
3
|
+
require 'lib/doodle'
|
4
|
+
|
5
|
+
describe 'flatten_first_level' do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@data = [
|
9
|
+
[1, 2, 3],
|
10
|
+
[1, [2], 3],
|
11
|
+
[[1, 2, 3]],
|
12
|
+
[1, [2, 3]],
|
13
|
+
[[1, 2], 3],
|
14
|
+
[[1, [2], 3]],
|
15
|
+
[1, [[2], 3]],
|
16
|
+
[1, [[2, 3]]],
|
17
|
+
]
|
18
|
+
@results = [
|
19
|
+
[1, 2, 3],
|
20
|
+
[1, 2, 3],
|
21
|
+
[1, 2, 3],
|
22
|
+
[1, 2, 3],
|
23
|
+
[1, 2, 3],
|
24
|
+
[1, [2], 3],
|
25
|
+
[1, [2], 3],
|
26
|
+
[1, [2, 3]],
|
27
|
+
]
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should flatten first level' do
|
31
|
+
@data.zip(@results).each do |input, result|
|
32
|
+
Doodle::Utils.flatten_first_level(input).should == result
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), '../.'))
|
2
|
+
|
3
|
+
require 'lib/spec_helper'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
describe Doodle, 'defaults which have not been set' do
|
7
|
+
after :each do
|
8
|
+
undefine_const(:Foo)
|
9
|
+
end
|
10
|
+
before :each do
|
11
|
+
raise_if_defined :Foo
|
12
|
+
|
13
|
+
class Foo < Doodle::Base
|
14
|
+
has :baz
|
15
|
+
has :start do
|
16
|
+
default { Date.today }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should have raise error if required value not set' do
|
22
|
+
proc { Foo.new }.should raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
|
3
|
+
describe 'Doodle', 'singleton superclass == self' do
|
4
|
+
after :each do
|
5
|
+
undefine_const(:Foo)
|
6
|
+
end
|
7
|
+
before :each do
|
8
|
+
raise_if_defined :Foo
|
9
|
+
|
10
|
+
class Foo < Doodle::Base
|
11
|
+
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
|
+
|
19
|
+
it 'should have singleton class superclass == self' do
|
20
|
+
@sc.parents.should == [@sclass_foo, @sclass_doodle_root]
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should have singleton class superclass == self' do
|
24
|
+
@scc.parents.should == []
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,108 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), '../.'))
|
2
|
+
|
3
|
+
require 'lib/spec_helper'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
|
7
|
+
describe :DateRange, 'validation & conversions' do
|
8
|
+
after :each do
|
9
|
+
undefine_const :DateRange
|
10
|
+
undefine_const :Base
|
11
|
+
undefine_const :ClassMethods
|
12
|
+
end
|
13
|
+
before :each do
|
14
|
+
raise_if_defined :Base, :ClassMethods, :DateRange
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def date(*a, &b)
|
18
|
+
# if a.size > 0
|
19
|
+
name = a.shift
|
20
|
+
# else
|
21
|
+
# name = :date
|
22
|
+
# end
|
23
|
+
td = has(name, :kind => Date, *a) do
|
24
|
+
# it is a bit clumsy to define these conversions &
|
25
|
+
# conditions for every attribute/typedef - could define a
|
26
|
+
# subclass of Typedef which does this by default (so we
|
27
|
+
# instances can override or defer to class level conversions
|
28
|
+
# and conditions)
|
29
|
+
from String do |s|
|
30
|
+
Date.parse(s)
|
31
|
+
end
|
32
|
+
from Array do |y,m,d|
|
33
|
+
#p [:from, Array, y, m, d]
|
34
|
+
Date.new(y, m, d)
|
35
|
+
end
|
36
|
+
from Integer do |jd|
|
37
|
+
Doodle::Debug.d { [:converting_from, Integer, jd] }
|
38
|
+
Date.new(*Date.jd_to_civil(jd))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
Doodle::Debug.d { [:date, td] }
|
42
|
+
td.instance_eval(&b) if block_given? # user's block should override default
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Base < Doodle::Base
|
47
|
+
extend ClassMethods
|
48
|
+
end
|
49
|
+
|
50
|
+
class DateRange < Base
|
51
|
+
date :start_date do
|
52
|
+
Doodle::Debug.d { [:start_date, self, self.class] }
|
53
|
+
default { Date.today }
|
54
|
+
must "be >= 2007-01-01" do |d|
|
55
|
+
d >= Date.new(2007, 01, 01)
|
56
|
+
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
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should not raise an exception if end_date >= start_date' do
|
68
|
+
proc { DateRange.new('2007-01-01', '2007-01-02') }.should_not raise_error
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should raise an exception if end_date < start_date' do
|
72
|
+
proc { DateRange.new('2007-01-02', '2007-01-01') }.should raise_error
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should raise an exception if end_date < start_date' do
|
76
|
+
proc { DateRange.new('2007-01-01', '2007-01-01') }.should_not raise_error
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should have start_date kind == Date' do
|
80
|
+
d = DateRange.new
|
81
|
+
d.attributes[:start_date].kind == Date
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should have two validations' do
|
85
|
+
d = DateRange.new
|
86
|
+
d.attributes[:start_date].validations.size.should == 2
|
87
|
+
d.attributes[:start_date].validations(false).size.should == 2
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should have two conversions' do
|
91
|
+
d = DateRange.new
|
92
|
+
d.attributes[:start_date].conversions.size.should == 3
|
93
|
+
d.attributes[:start_date].conversions(false).size.should == 3
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should convert from Array' do
|
97
|
+
d = DateRange.new [2007,01,01], [2007,01,02]
|
98
|
+
d.start_date.should == Date.new(2007,01,01)
|
99
|
+
d.end_date.should == Date.new(2007,01,02)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should convert Integer representing Julian date to Date' do
|
103
|
+
d = DateRange.new 2454428, 2454429
|
104
|
+
d.start_date.should == Date.new(2007,11,23)
|
105
|
+
d.end_date.should == Date.new(2007,11,24)
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: doodle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean O'Halpin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-03-08 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: sean.ohalpin@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
- COPYING
|
25
|
+
files:
|
26
|
+
- lib/doodle.rb
|
27
|
+
- lib/molic_orderedhash.rb
|
28
|
+
- lib/spec_helper.rb
|
29
|
+
- examples/event.rb
|
30
|
+
- examples/event1.rb
|
31
|
+
- examples/event2.rb
|
32
|
+
- examples/example-01.rb
|
33
|
+
- examples/example-01.rdoc
|
34
|
+
- examples/example-02.rb
|
35
|
+
- examples/example-02.rdoc
|
36
|
+
- README
|
37
|
+
- COPYING
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://doodle.rubyforge.org/
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project: doodle
|
60
|
+
rubygems_version: 1.0.1
|
61
|
+
signing_key:
|
62
|
+
specification_version: 2
|
63
|
+
summary: Declarative attribute definitions and validations
|
64
|
+
test_files:
|
65
|
+
- spec/arg_order_spec.rb
|
66
|
+
- spec/attributes_spec.rb
|
67
|
+
- spec/class_spec.rb
|
68
|
+
- spec/conversion_spec.rb
|
69
|
+
- spec/defaults_spec.rb
|
70
|
+
- spec/doodle_spec.rb
|
71
|
+
- spec/flatten_first_level_spec.rb
|
72
|
+
- spec/required_spec.rb
|
73
|
+
- spec/superclass_spec.rb
|
74
|
+
- spec/validation_spec.rb
|