schematic 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/schematic/generator/column.rb +3 -1
- data/lib/schematic/generator/sandbox.rb +6 -1
- data/lib/schematic/generator/xsd.rb +4 -3
- data/lib/schematic/version.rb +1 -1
- data/spec/schematic/generator/sandbox_spec.rb +17 -0
- data/spec/schematic/serializers/xsd_validation_presence_spec.rb +35 -0
- metadata +55 -20
@@ -8,12 +8,13 @@ module Schematic
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def initialize(klass, column, additional_methods = {}, ignored_methods = {}, required_methods = [])
|
11
|
+
def initialize(klass, column, additional_methods = {}, ignored_methods = {}, required_methods = [], non_required_methods = [])
|
12
12
|
@klass = klass
|
13
13
|
@column = column
|
14
14
|
@additional_methods = additional_methods
|
15
15
|
@ignored_methods = ignored_methods
|
16
16
|
@required_methods = required_methods
|
17
|
+
@non_required_methods = non_required_methods
|
17
18
|
end
|
18
19
|
|
19
20
|
def generate(builder)
|
@@ -40,6 +41,7 @@ module Schematic
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def minimum_occurrences_for_column
|
44
|
+
return 0 if @non_required_methods.include?(@column.name.to_sym)
|
43
45
|
return 1 if @required_methods.include?(@column.name.to_sym)
|
44
46
|
return 0 unless @klass.respond_to?(:_validators)
|
45
47
|
@klass._validators[@column.name.to_sym].each do |column_validation|
|
@@ -1,13 +1,14 @@
|
|
1
1
|
module Schematic
|
2
2
|
module Generator
|
3
3
|
class Sandbox
|
4
|
-
attr_accessor :ignored_elements, :added_elements, :required_elements
|
4
|
+
attr_accessor :ignored_elements, :added_elements, :required_elements, :non_required_elements
|
5
5
|
|
6
6
|
def initialize(klass)
|
7
7
|
@klass = klass
|
8
8
|
@ignored_elements ||= Hash.new([])
|
9
9
|
@added_elements ||= {}
|
10
10
|
@required_elements ||= []
|
11
|
+
@non_required_elements ||= []
|
11
12
|
end
|
12
13
|
|
13
14
|
def run(&block)
|
@@ -55,6 +56,10 @@ module Schematic
|
|
55
56
|
fields.each { |field| required_elements << field }
|
56
57
|
end
|
57
58
|
|
59
|
+
def not_required(*fields)
|
60
|
+
fields.each { |field| non_required_elements << field }
|
61
|
+
end
|
62
|
+
|
58
63
|
def root(name)
|
59
64
|
xsd_generator.names.root = name
|
60
65
|
end
|
@@ -89,9 +89,10 @@ module Schematic
|
|
89
89
|
end
|
90
90
|
|
91
91
|
required_methods = @klass.schematic_sandbox.required_elements
|
92
|
+
non_required_methods = @klass.schematic_sandbox.non_required_elements
|
92
93
|
|
93
94
|
complex_type.xs :all do |all|
|
94
|
-
generate_column_elements(all, additional_methods, ignored_methods, required_methods)
|
95
|
+
generate_column_elements(all, additional_methods, ignored_methods, required_methods, non_required_methods)
|
95
96
|
|
96
97
|
nested_attributes.each do |nested_attribute|
|
97
98
|
case nested_attribute.macro
|
@@ -121,10 +122,10 @@ module Schematic
|
|
121
122
|
end
|
122
123
|
end
|
123
124
|
|
124
|
-
def generate_column_elements(builder, additional_methods, ignored_methods, required_methods)
|
125
|
+
def generate_column_elements(builder, additional_methods, ignored_methods, required_methods, non_required_methods)
|
125
126
|
return unless @klass.respond_to?(:columns)
|
126
127
|
@klass.columns.each do |column|
|
127
|
-
Column.new(@klass, column, additional_methods, ignored_methods, required_methods).generate(builder)
|
128
|
+
Column.new(@klass, column, additional_methods, ignored_methods, required_methods, non_required_methods).generate(builder)
|
128
129
|
end
|
129
130
|
end
|
130
131
|
|
data/lib/schematic/version.rb
CHANGED
@@ -78,6 +78,23 @@ describe Schematic::Generator::Sandbox do
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
+
describe "not requiring elements" do
|
82
|
+
it "should add the method to the non-required list" do
|
83
|
+
subject.run do
|
84
|
+
not_required :foo
|
85
|
+
end
|
86
|
+
subject.non_required_elements.should include(:foo)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "accepts multiple fields" do
|
90
|
+
subject.run do
|
91
|
+
not_required :foo, :bar
|
92
|
+
end
|
93
|
+
subject.non_required_elements.should include(:foo)
|
94
|
+
subject.non_required_elements.should include(:bar)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
81
98
|
describe "setting the root" do
|
82
99
|
it "should change the root element name" do
|
83
100
|
subject.run do
|
@@ -135,5 +135,40 @@ describe Schematic::Serializers::Xsd do
|
|
135
135
|
end
|
136
136
|
end
|
137
137
|
end
|
138
|
+
|
139
|
+
context "with a model with field explicitly not required" do
|
140
|
+
subject { sanitize_xml(ModelWithNotRequiredField.to_xsd) }
|
141
|
+
|
142
|
+
with_model :model_with_not_required_field do
|
143
|
+
table :id => false do |t|
|
144
|
+
t.string :some_field
|
145
|
+
end
|
146
|
+
|
147
|
+
model do
|
148
|
+
validates_presence_of :some_field
|
149
|
+
|
150
|
+
schematic do
|
151
|
+
not_required :some_field
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should mark that the field minimum occurrences is 1" do
|
157
|
+
xsd = generate_xsd_for_model(ModelWithNotRequiredField) do
|
158
|
+
<<-XML
|
159
|
+
<xs:element name="some-field" minOccurs="0" maxOccurs="1">
|
160
|
+
<xs:complexType>
|
161
|
+
<xs:simpleContent>
|
162
|
+
<xs:restriction base="String">
|
163
|
+
</xs:restriction>
|
164
|
+
</xs:simpleContent>
|
165
|
+
</xs:complexType>
|
166
|
+
</xs:element>
|
167
|
+
XML
|
168
|
+
end
|
169
|
+
|
170
|
+
subject.should == xsd
|
171
|
+
end
|
172
|
+
end
|
138
173
|
end
|
139
174
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schematic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-04-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: builder
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,21 +37,31 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rspec-rails
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
|
-
- - =
|
51
|
+
- - '='
|
42
52
|
- !ruby/object:Gem::Version
|
43
53
|
version: '2.7'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.7'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: with_model
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: 0.2.4
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.2.4
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: nokogiri
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: '0'
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: sqlite3
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
@@ -76,10 +101,15 @@ dependencies:
|
|
76
101
|
version: '0'
|
77
102
|
type: :development
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
80
110
|
- !ruby/object:Gem::Dependency
|
81
111
|
name: autotest
|
82
|
-
requirement:
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
83
113
|
none: false
|
84
114
|
requirements:
|
85
115
|
- - ! '>='
|
@@ -87,7 +117,12 @@ dependencies:
|
|
87
117
|
version: '0'
|
88
118
|
type: :development
|
89
119
|
prerelease: false
|
90
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
91
126
|
description: Automatic XSD generation from ActiveRecord models
|
92
127
|
email:
|
93
128
|
- casecommons-dev@googlegroups.com
|
@@ -153,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
188
|
version: '0'
|
154
189
|
segments:
|
155
190
|
- 0
|
156
|
-
hash: -
|
191
|
+
hash: -4530207830951825601
|
157
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
193
|
none: false
|
159
194
|
requirements:
|
@@ -162,10 +197,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
197
|
version: '0'
|
163
198
|
segments:
|
164
199
|
- 0
|
165
|
-
hash: -
|
200
|
+
hash: -4530207830951825601
|
166
201
|
requirements: []
|
167
202
|
rubyforge_project: schematic
|
168
|
-
rubygems_version: 1.8.
|
203
|
+
rubygems_version: 1.8.21
|
169
204
|
signing_key:
|
170
205
|
specification_version: 3
|
171
206
|
summary: Automatic XSD generation from ActiveRecord models
|