doodle 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +0,0 @@
1
- require 'date'
2
- require 'doodle'
3
-
4
- class DateRange < Doodle::Base
5
- has :start_date do
6
- default { Date.today }
7
- end
8
- has :end_date do
9
- default { start_date }
10
- end
11
- end
12
-
13
- dr = DateRange.new
14
- dr.start_date # => #<Date: 4909053/2,0,2299161>
15
- dr.end_date # => #<Date: 4909053/2,0,2299161>
16
-
@@ -1,62 +0,0 @@
1
- require 'date'
2
- require 'doodle'
3
-
4
- class DateRange < Doodle::Base
5
- has :start_date, :kind => Date do
6
- default { Date.today }
7
- from String do |s|
8
- Date.parse(s)
9
- end
10
- must "be >= 2000-01-01" do |d|
11
- d >= Date.parse('2000-01-01')
12
- end
13
- end
14
- has :end_date do
15
- default { start_date }
16
- from String do |s|
17
- Date.parse(s)
18
- end
19
- end
20
- must 'have end_date >= start_date' do
21
- end_date >= start_date
22
- end
23
- from String do |s|
24
- m = /(\d{4}-\d{2}-\d{2})\s*(?:to|-|\s)\s*(\d{4}-\d{2}-\d{2})/.match(s)
25
- if m
26
- self.new(*m.captures)
27
- end
28
- end
29
- end
30
-
31
- dr = DateRange.new '2007-12-31', '2008-01-01'
32
- dr.start_date # => #<Date: 4908931/2,0,2299161>
33
- dr.end_date # => #<Date: 4908933/2,0,2299161>
34
-
35
- dr = DateRange '2007-12-31', '2008-01-01'
36
- dr.start_date # => #<Date: 4908931/2,0,2299161>
37
- dr.end_date # => #<Date: 4908933/2,0,2299161>
38
-
39
- dr = DateRange :start_date => '2007-12-31', :end_date => '2008-01-01'
40
- dr.start_date # => #<Date: 4908931/2,0,2299161>
41
- dr.end_date # => #<Date: 4908933/2,0,2299161>
42
-
43
- dr = DateRange do
44
- start_date '2007-12-31'
45
- end_date '2008-01-01'
46
- end
47
- dr.start_date # => #<Date: 4908931/2,0,2299161>
48
- dr.end_date # => #<Date: 4908933/2,0,2299161>
49
-
50
-
51
- dr = DateRange.from '2007-01-01 to 2008-12-31'
52
- dr.start_date # => #<Date: 4908203/2,0,2299161>
53
- dr.end_date # => #<Date: 4909663/2,0,2299161>
54
-
55
- dr = DateRange.from '2007-01-01 2007-12-31'
56
- dr.start_date # => #<Date: 4908203/2,0,2299161>
57
- dr.end_date # => #<Date: 4908931/2,0,2299161>
58
-
59
- dr = DateRange '2008-01-01', '2007-12-31'
60
- dr.start_date # =>
61
- dr.end_date # =>
62
- # ~> -:59: #<DateRange:0x747fc @start_date=#<Date: 4908933/2,0,2299161>, @end_date=#<Date: 4908931/2,0,2299161>> must have end_date >= start_date (Doodle::ValidationError)
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'doodle'
3
-
4
- class Foo < Doodle::Base
5
- has :name, :kind => String
6
- end
7
-
8
- foo = Foo "Bar"
9
- foo # =>
10
- baz = Foo 1
@@ -1,19 +0,0 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), '../lib'))
2
- require 'molic_orderedhash'
3
- require 'doodle'
4
- require 'date'
5
-
6
- def undefine_const(*consts)
7
- consts.each do |const|
8
- if Object.const_defined?(const)
9
- Object.send(:remove_const, const)
10
- end
11
- end
12
- end
13
-
14
- def raise_if_defined(*args)
15
- defined, undefined = args.partition{ |x| Object.const_defined?(x)}
16
- raise "Namespace pollution: #{defined.join(', ')}" if defined.size > 0
17
- end
18
-
19
-