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
data/examples/example-01.rdoc
DELETED
@@ -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
|
-
|
data/examples/example-02.rdoc
DELETED
@@ -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)
|
data/examples/foo.rb
DELETED
data/lib/spec_helper.rb
DELETED
@@ -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
|
-
|