schematic 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/schematic/generator/names.rb +1 -1
- data/lib/schematic/generator/xsd.rb +22 -11
- data/lib/schematic/version.rb +1 -1
- data/spec/schematic_serializers_xsd_spec.rb +39 -0
- metadata +18 -18
@@ -11,8 +11,8 @@ module Schematic
|
|
11
11
|
|
12
12
|
def options=(hash = {})
|
13
13
|
@options = hash
|
14
|
-
@options[:
|
15
|
-
@options[:
|
14
|
+
@options[:generated_singular_types] ||= []
|
15
|
+
@options[:generated_plural_types] ||= []
|
16
16
|
@options
|
17
17
|
end
|
18
18
|
|
@@ -35,22 +35,33 @@ module Schematic
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def generate(builder, klass, include_collection=true, exclude_from_parent = [])
|
38
|
+
@iteration ||= 0
|
38
39
|
@exclude = exclude_from_parent
|
39
|
-
|
40
40
|
nested_attributes.each do |nested_attribute|
|
41
41
|
next if nested_attribute.klass == klass
|
42
42
|
next if nested_attribute.klass == klass.superclass
|
43
43
|
@options ||= {}
|
44
|
-
@options[:
|
44
|
+
@options[:generated_singular_types] ||= []
|
45
|
+
@options[:generated_plural_types] ||= []
|
45
46
|
exclude = klass.schematic_sandbox.ignored_elements[nested_attribute.name].dup
|
46
|
-
next if @options[:generated_types].include?(nested_attribute.klass)
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
if nested_attribute.macro == :has_many && !@options[:generated_plural_types].include?(nested_attribute.klass)
|
49
|
+
nested_attribute.klass.schematic_sandbox.generate_xsd(builder, klass, true, @options, exclude)
|
50
|
+
@options[:generated_plural_types] << nested_attribute.klass
|
51
|
+
elsif !@options[:generated_singular_types].include?(nested_attribute.klass)
|
52
|
+
nested_attribute.klass.schematic_sandbox.generate_xsd(builder, klass, false, @options, exclude)
|
53
|
+
@options[:generated_singular_types] << nested_attribute.klass
|
54
|
+
end
|
50
55
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
56
|
+
if include_collection && !@options[:generated_plural_types].include?(@names.collection_type)
|
57
|
+
generate_complex_type_for_collection(builder)
|
58
|
+
@options[:generated_plural_types] << @names.collection_type
|
59
|
+
end
|
60
|
+
unless @options[:generated_singular_types].include?(@names.type)
|
61
|
+
generate_complex_type_for_model(builder)
|
62
|
+
@options[:generated_singular_types] << @names.type
|
63
|
+
end
|
64
|
+
builder
|
54
65
|
end
|
55
66
|
|
56
67
|
def generate_complex_type_for_collection(builder)
|
@@ -120,7 +131,7 @@ module Schematic
|
|
120
131
|
def generate_uniqueness_constraints(builder)
|
121
132
|
return unless @klass.respond_to?(:columns)
|
122
133
|
@klass.columns.each do |column|
|
123
|
-
|
134
|
+
Uniqueness.new(@klass, column).generate(builder)
|
124
135
|
end
|
125
136
|
end
|
126
137
|
|
data/lib/schematic/version.rb
CHANGED
@@ -739,4 +739,43 @@ describe Schematic::Serializers::Xsd do
|
|
739
739
|
xsd.nested_attribute_name(:very_special_children).should == "very-special-children-attributes"
|
740
740
|
end
|
741
741
|
end
|
742
|
+
context "when the model has a nested attribute with a different class name and foreign key than the has_many association" do
|
743
|
+
with_model :foo do
|
744
|
+
model do
|
745
|
+
has_one :bar, :class_name => "Quz", :foreign_key => "bar_id"
|
746
|
+
has_many :children, :class_name => "Quz", :foreign_key => "children_id"
|
747
|
+
accepts_nested_attributes_for :children
|
748
|
+
accepts_nested_attributes_for :bar
|
749
|
+
end
|
750
|
+
end
|
751
|
+
with_model :quz do
|
752
|
+
table do |t|
|
753
|
+
t.integer :bar_id
|
754
|
+
t.integer :children_id
|
755
|
+
t.string :name
|
756
|
+
end
|
757
|
+
end
|
758
|
+
subject { Foo.to_xsd }
|
759
|
+
|
760
|
+
it "should generate a valid XSD" do
|
761
|
+
test_xml = <<-END
|
762
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
763
|
+
<foos>
|
764
|
+
<foo>
|
765
|
+
<children-attributes>
|
766
|
+
<quz>
|
767
|
+
<name>Joe</name>
|
768
|
+
</quz>
|
769
|
+
</children-attributes>
|
770
|
+
</foo>
|
771
|
+
</foos>
|
772
|
+
END
|
773
|
+
|
774
|
+
subject.should include "Quz"
|
775
|
+
subject.should include "Quzs"
|
776
|
+
validate_xml_against_xsd(test_xml, subject)
|
777
|
+
end
|
778
|
+
end
|
742
779
|
end
|
780
|
+
|
781
|
+
|
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.1
|
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-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &70212766160660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70212766160660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: builder
|
27
|
-
requirement: &
|
27
|
+
requirement: &70212766160240 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70212766160240
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec-rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &70212766159700 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - =
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '2.7'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70212766159700
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: with_model
|
49
|
-
requirement: &
|
49
|
+
requirement: &70212766159200 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.2.4
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70212766159200
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: nokogiri
|
60
|
-
requirement: &
|
60
|
+
requirement: &70212766158820 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70212766158820
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sqlite3
|
71
|
-
requirement: &
|
71
|
+
requirement: &70212766158360 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70212766158360
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: autotest
|
82
|
-
requirement: &
|
82
|
+
requirement: &70212766157940 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70212766157940
|
91
91
|
description: Automatic XSD generation from ActiveRecord models
|
92
92
|
email:
|
93
93
|
- casecommons-dev@googlegroups.com
|
@@ -153,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
153
|
version: '0'
|
154
154
|
segments:
|
155
155
|
- 0
|
156
|
-
hash: -
|
156
|
+
hash: -3449394722461241422
|
157
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
158
|
none: false
|
159
159
|
requirements:
|
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
162
|
version: '0'
|
163
163
|
segments:
|
164
164
|
- 0
|
165
|
-
hash: -
|
165
|
+
hash: -3449394722461241422
|
166
166
|
requirements: []
|
167
167
|
rubyforge_project: schematic
|
168
168
|
rubygems_version: 1.8.10
|