doodle 0.0.3 → 0.0.4
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/examples/event-location.rb +26 -2
- data/lib/doodle.rb +10 -7
- metadata +2 -2
data/examples/event-location.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'date'
|
3
|
-
require 'pp'
|
4
3
|
require 'doodle'
|
4
|
+
require "yaml"
|
5
|
+
require "pp"
|
5
6
|
|
6
7
|
class Location < Doodle::Base
|
7
8
|
has :name, :kind => String
|
@@ -35,4 +36,27 @@ event = Event "Festival" do
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
|
-
|
39
|
+
str = event.to_yaml
|
40
|
+
puts str
|
41
|
+
loaded_event = YAML::load(str)
|
42
|
+
pp loaded_event
|
43
|
+
|
44
|
+
another_event = YAML::load(DATA.read)
|
45
|
+
another_event.validate!(true)
|
46
|
+
|
47
|
+
__END__
|
48
|
+
--- !ruby/object:Event
|
49
|
+
date: 2000-04-01
|
50
|
+
locations:
|
51
|
+
- !ruby/object:Location
|
52
|
+
events: []
|
53
|
+
|
54
|
+
name: The muddy field
|
55
|
+
- !ruby/object:Location
|
56
|
+
events:
|
57
|
+
- !ruby/object:Event
|
58
|
+
locations: []
|
59
|
+
|
60
|
+
name: Drinking
|
61
|
+
name: Beer tent
|
62
|
+
name: Festival
|
data/lib/doodle.rb
CHANGED
@@ -638,29 +638,32 @@ module Doodle
|
|
638
638
|
private :ivar_defined?
|
639
639
|
|
640
640
|
# validate this object by applying all validations in sequence
|
641
|
-
|
642
|
-
|
641
|
+
# - if all == true, validate all attributes, e.g. when loaded from YAML
|
642
|
+
def validate!(all = false)
|
643
|
+
#Doodle::Debug.d { [:validate!, self] }
|
644
|
+
#Doodle::Debug.d { [:validate!, self, __doodle__.validation_on] }
|
643
645
|
if __doodle__.validation_on
|
644
646
|
attributes.each do |name, att|
|
645
|
-
# d { [:validate!, self, self.class, att.name, att.default_defined? ] }
|
646
|
-
#p collect_inherited(:attributes)
|
647
647
|
# treat default as special case
|
648
648
|
if att.name == :default || att.default_defined?
|
649
|
+
# nop
|
649
650
|
elsif !ivar_defined?(att.name)
|
650
651
|
raise ArgumentError, "#{self} missing required attribute '#{name}'", [caller[-1]]
|
651
652
|
end
|
653
|
+
# if all == true, validate all attributes - e.g. when loaded from YAML
|
654
|
+
if all
|
655
|
+
att.validate(send(att.name))
|
656
|
+
end
|
652
657
|
end
|
653
658
|
|
654
659
|
validations.each do |v|
|
655
|
-
|
660
|
+
Doodle::Debug.d { [:validate!, self, v ] }
|
656
661
|
if !instance_eval(&v.block)
|
657
|
-
# if !instance_eval{ v.block.call(self) }
|
658
662
|
raise ValidationError, "#{ self.inspect } must #{ v.message }", [caller[-1]]
|
659
663
|
end
|
660
664
|
end
|
661
665
|
end
|
662
666
|
end
|
663
|
-
private :validate!
|
664
667
|
|
665
668
|
# turn off validation, execute block, then set validation to same
|
666
669
|
# state as it was before +defer_validation+ was called - can be nested
|
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.4
|
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-15 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|