schematic 0.3.6 → 0.3.7
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/README.rdoc
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
== DESCRIPTION
|
6
6
|
|
7
|
-
Automatic XSD generation for your ActiveRecord models
|
7
|
+
Automatic XSD generation for your ActiveRecord models
|
8
8
|
|
9
9
|
== INSTALL
|
10
10
|
|
@@ -39,6 +39,42 @@ You can exclude elements by defining a ".xsd_ignore_methods" on your class:
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
+
You can define your own custom restrictions by inheriting from the Restrictions Base class:
|
43
|
+
|
44
|
+
class MyCustomRestriction < Schematic::Generator::Restrictions::Base
|
45
|
+
def generate(builder)
|
46
|
+
for_validator ActiveModel::BlockValidator do |validator|
|
47
|
+
builder.xs(:enumeration, "value" => "foo")
|
48
|
+
builder.xs(:enumeration, "value" => "bar")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
You can have a custom pattern restriction from a custom validater:
|
54
|
+
|
55
|
+
class MyValidator < ActiveModel::EachValidator
|
56
|
+
def validate_each(record, attribute, value)
|
57
|
+
...
|
58
|
+
end
|
59
|
+
|
60
|
+
def xsd_pattern_restrictions
|
61
|
+
[/foo/, /bar/]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
You can have a custom enumeration restriction from a custom validater:
|
66
|
+
|
67
|
+
class MyValidator < ActiveModel::EachValidator
|
68
|
+
def validate_each(record, attribute, value)
|
69
|
+
...
|
70
|
+
end
|
71
|
+
|
72
|
+
def xsd_field_enumeration_restrictions
|
73
|
+
["foo", "bar"]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
42
78
|
== REQUIREMENTS
|
43
79
|
|
44
80
|
* ActiveRecord 3.x
|
@@ -11,7 +11,9 @@ module Schematic
|
|
11
11
|
def for_validator(validator_klass)
|
12
12
|
validators_for_column.each do |column_validation|
|
13
13
|
next unless column_validation.is_a? validator_klass
|
14
|
-
|
14
|
+
has_conditional_proc = !column_validation.options[:if].nil? || !column_validation.options[:unless].nil?
|
15
|
+
force_inclusion = column_validation.options[:xsd] && column_validation.options[:xsd][:include]
|
16
|
+
next if has_conditional_proc && !force_inclusion
|
15
17
|
yield(column_validation)
|
16
18
|
return
|
17
19
|
end
|
data/lib/schematic/version.rb
CHANGED
@@ -8,14 +8,20 @@ describe Schematic::Generator::Restrictions::Enumeration do
|
|
8
8
|
with_model :enumeration_model do
|
9
9
|
table :id => false do |t|
|
10
10
|
t.string "title"
|
11
|
+
t.string "should_be_skipped"
|
12
|
+
t.string "should_also_be_skipped"
|
11
13
|
t.boolean "active"
|
12
14
|
t.string "options"
|
15
|
+
t.integer "force_enumeration"
|
13
16
|
end
|
14
17
|
|
15
18
|
model do
|
16
19
|
validates :title, :inclusion => { :in => ["a", "b", "c"] }
|
20
|
+
validates :should_be_skipped, :inclusion => ["a", "b", "c"], :if => lambda { false }
|
21
|
+
validates :should_also_be_skipped, :inclusion => ["a", "b", "c"], :unless => lambda { false }
|
17
22
|
validates :active, :inclusion => { :in => [true, false] }
|
18
23
|
validates :options, :inclusion => { :in => lambda { |f| ["some valid attribute"] } }
|
24
|
+
validates :force_enumeration, :inclusion => { :in => [1, 2], :xsd => { :include => true} }, :if => lambda { false }
|
19
25
|
end
|
20
26
|
end
|
21
27
|
|
@@ -25,7 +31,7 @@ describe Schematic::Generator::Restrictions::Enumeration do
|
|
25
31
|
lambda {
|
26
32
|
validate_xml_against_xsd(xml, subject)
|
27
33
|
}.should raise_error
|
28
|
-
valid_instance = EnumerationModel.new(:title => "a", :active => true, :options => "some valid attribute")
|
34
|
+
valid_instance = EnumerationModel.new(:title => "a", :should_be_skipped => "a", :should_also_be_skipped => "a", :active => true, :options => "some valid attribute", :force_enumeration => 2)
|
29
35
|
xml = [valid_instance].to_xml
|
30
36
|
lambda {
|
31
37
|
validate_xml_against_xsd(xml, subject)
|
@@ -46,6 +52,22 @@ describe Schematic::Generator::Restrictions::Enumeration do
|
|
46
52
|
</xs:simpleContent>
|
47
53
|
</xs:complexType>
|
48
54
|
</xs:element>
|
55
|
+
<xs:element name="should-be-skipped" minOccurs="0" maxOccurs="1">
|
56
|
+
<xs:complexType>
|
57
|
+
<xs:simpleContent>
|
58
|
+
<xs:restriction base="String">
|
59
|
+
</xs:restriction>
|
60
|
+
</xs:simpleContent>
|
61
|
+
</xs:complexType>
|
62
|
+
</xs:element>
|
63
|
+
<xs:element name="should-also-be-skipped" minOccurs="0" maxOccurs="1">
|
64
|
+
<xs:complexType>
|
65
|
+
<xs:simpleContent>
|
66
|
+
<xs:restriction base="String">
|
67
|
+
</xs:restriction>
|
68
|
+
</xs:simpleContent>
|
69
|
+
</xs:complexType>
|
70
|
+
</xs:element>
|
49
71
|
<xs:element name="active" minOccurs="0" maxOccurs="1">
|
50
72
|
<xs:complexType>
|
51
73
|
<xs:simpleContent>
|
@@ -62,6 +84,16 @@ describe Schematic::Generator::Restrictions::Enumeration do
|
|
62
84
|
</xs:simpleContent>
|
63
85
|
</xs:complexType>
|
64
86
|
</xs:element>
|
87
|
+
<xs:element name="force-enumeration" minOccurs="0" maxOccurs="1">
|
88
|
+
<xs:complexType>
|
89
|
+
<xs:simpleContent>
|
90
|
+
<xs:restriction base="Integer">
|
91
|
+
<xs:enumeration value="1"/>
|
92
|
+
<xs:enumeration value="2"/>
|
93
|
+
</xs:restriction>
|
94
|
+
</xs:simpleContent>
|
95
|
+
</xs:complexType>
|
96
|
+
</xs:element>
|
65
97
|
XML
|
66
98
|
end
|
67
99
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: schematic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Case Commons, LLC
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
14
|
-
default_executable:
|
13
|
+
date: 2011-08-01 00:00:00 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: activerecord
|
@@ -142,7 +141,6 @@ files:
|
|
142
141
|
- spec/support/extensions/active_model/validations/inclusion.rb
|
143
142
|
- spec/xsd/XMLSchema.xsd
|
144
143
|
- spec/xsd/xml.xsd
|
145
|
-
has_rdoc: true
|
146
144
|
homepage: https://github.com/Casecommons/schematic
|
147
145
|
licenses: []
|
148
146
|
|
@@ -156,7 +154,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
154
|
requirements:
|
157
155
|
- - ">="
|
158
156
|
- !ruby/object:Gem::Version
|
159
|
-
hash: -
|
157
|
+
hash: -1535622649516995802
|
160
158
|
segments:
|
161
159
|
- 0
|
162
160
|
version: "0"
|
@@ -165,14 +163,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
163
|
requirements:
|
166
164
|
- - ">="
|
167
165
|
- !ruby/object:Gem::Version
|
168
|
-
hash: -
|
166
|
+
hash: -1535622649516995802
|
169
167
|
segments:
|
170
168
|
- 0
|
171
169
|
version: "0"
|
172
170
|
requirements: []
|
173
171
|
|
174
172
|
rubyforge_project: schematic
|
175
|
-
rubygems_version: 1.
|
173
|
+
rubygems_version: 1.8.5
|
176
174
|
signing_key:
|
177
175
|
specification_version: 3
|
178
176
|
summary: Automatic XSD generation from ActiveRecord models
|