schematic 0.5.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,10 +19,14 @@ module Schematic
19
19
  def generate(builder)
20
20
  return if skip_generation?
21
21
 
22
- builder.xs :element,
22
+ options = {
23
23
  "name" => @column.name.dasherize,
24
- "minOccurs" => minimum_occurrences_for_column,
25
- "maxOccurs" => "1" do |field|
24
+ "minOccurs" => minimum_occurrences_for_column.to_s,
25
+ "maxOccurs" => "1"
26
+ }
27
+ options.merge!({"nillable" => "false"}) if minimum_occurrences_for_column > 0
28
+
29
+ builder.xs :element, options do |field|
26
30
  field.xs :complexType do |complex_type|
27
31
  complex_type.xs :simpleContent do |simple_content|
28
32
  simple_content.xs :restriction, "base" => map_type(@column) do |restriction|
@@ -36,18 +40,18 @@ module Schematic
36
40
  end
37
41
 
38
42
  def minimum_occurrences_for_column
39
- return "1" if @required_methods.include?(@column.name.to_sym)
40
- return "0" unless @klass.respond_to?(:_validators)
43
+ return 1 if @required_methods.include?(@column.name.to_sym)
44
+ return 0 unless @klass.respond_to?(:_validators)
41
45
  @klass._validators[@column.name.to_sym].each do |column_validation|
42
46
  next unless column_validation.is_a? ActiveModel::Validations::PresenceValidator
43
47
  if column_validation.options[:allow_blank] != true &&
44
48
  column_validation.options[:if].nil? &&
45
49
  column_validation.options[:unless].nil?
46
50
 
47
- return "1"
51
+ return 1
48
52
  end
49
53
  end
50
- "0"
54
+ 0
51
55
  end
52
56
 
53
57
  def map_type(column)
@@ -1,3 +1,3 @@
1
1
  module Schematic
2
- VERSION = "0.5.9"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_dependency('activerecord', '>= 3.0.0')
18
18
  s.add_dependency('builder')
19
- s.add_development_dependency('rspec-rails', '>= 2.1')
19
+ s.add_development_dependency('rspec-rails', '= 2.7')
20
20
  s.add_development_dependency('with_model', '>= 0.2.4')
21
21
  s.add_development_dependency('nokogiri')
22
22
  s.add_development_dependency('sqlite3')
@@ -47,7 +47,7 @@ describe Schematic::Serializers::Xsd do
47
47
  it "should mark that the field minimum occurrences is 1" do
48
48
  xsd = generate_xsd_for_model(SomeModel) do
49
49
  <<-XML
50
- <xs:element name="title" minOccurs="1" maxOccurs="1">
50
+ <xs:element name="title" minOccurs="1" maxOccurs="1" nillable="false">
51
51
  <xs:complexType>
52
52
  <xs:simpleContent>
53
53
  <xs:restriction base="String">
@@ -120,7 +120,7 @@ describe Schematic::Serializers::Xsd do
120
120
  it "should mark that the field minimum occurrences is 1" do
121
121
  xsd = generate_xsd_for_model(SomeModel) do
122
122
  <<-XML
123
- <xs:element name="current" minOccurs="1" maxOccurs="1">
123
+ <xs:element name="current" minOccurs="1" maxOccurs="1" nillable="false">
124
124
  <xs:complexType>
125
125
  <xs:simpleContent>
126
126
  <xs:restriction base="Boolean">
@@ -13,7 +13,7 @@ describe Schematic::Serializers::Xsd do
13
13
  end
14
14
  end
15
15
 
16
- it { should == "0" }
16
+ it { should == 0 }
17
17
  end
18
18
 
19
19
  context "given a column with presence of but allow blank" do
@@ -26,7 +26,7 @@ describe Schematic::Serializers::Xsd do
26
26
  end
27
27
  end
28
28
 
29
- it { should == "0" }
29
+ it { should == 0 }
30
30
  end
31
31
 
32
32
  context "given a column with presence of and no allow blank" do
@@ -39,7 +39,7 @@ describe Schematic::Serializers::Xsd do
39
39
  end
40
40
  end
41
41
 
42
- it { should == "1" }
42
+ it { should == 1 }
43
43
  end
44
44
  end
45
45
 
@@ -19,6 +19,7 @@ describe Schematic::Serializers::Xsd do
19
19
  before do
20
20
  class SomeClass
21
21
  include ActiveModel::Serializers::Xml
22
+ attr_accessor :foo, :bar
22
23
  def attributes=(hash)
23
24
  @hash = hash
24
25
  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.5.9
4
+ version: 0.6.0
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: 2011-12-27 00:00:00.000000000Z
12
+ date: 2012-02-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &2152959400 !ruby/object:Gem::Requirement
16
+ requirement: &70329222280980 !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: *2152959400
24
+ version_requirements: *70329222280980
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: builder
27
- requirement: &2152958280 !ruby/object:Gem::Requirement
27
+ requirement: &70329222247240 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,21 +32,21 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152958280
35
+ version_requirements: *70329222247240
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec-rails
38
- requirement: &2152957200 !ruby/object:Gem::Requirement
38
+ requirement: &70329222245680 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ! '>='
41
+ - - =
42
42
  - !ruby/object:Gem::Version
43
- version: '2.1'
43
+ version: '2.7'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2152957200
46
+ version_requirements: *70329222245680
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: with_model
49
- requirement: &2152955660 !ruby/object:Gem::Requirement
49
+ requirement: &70329222244100 !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: *2152955660
57
+ version_requirements: *70329222244100
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: nokogiri
60
- requirement: &2152954800 !ruby/object:Gem::Requirement
60
+ requirement: &70329222243200 !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: *2152954800
68
+ version_requirements: *70329222243200
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
- requirement: &2152953920 !ruby/object:Gem::Requirement
71
+ requirement: &70329222242300 !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: *2152953920
79
+ version_requirements: *70329222242300
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: autotest
82
- requirement: &2152952540 !ruby/object:Gem::Requirement
82
+ requirement: &70329222240840 !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: *2152952540
90
+ version_requirements: *70329222240840
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: -3956753853577588500
156
+ hash: -3320943580698096283
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: -3956753853577588500
165
+ hash: -3320943580698096283
166
166
  requirements: []
167
167
  rubyforge_project: schematic
168
168
  rubygems_version: 1.8.10