dslize 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,6 +9,11 @@ module DSLize
9
9
  self.objects = DSLize.objects
10
10
  self.superclasses = DSLize.superclasses
11
11
  end
12
+
13
+ protected
14
+ def get_subclasses(type)
15
+ superclasses.select { |k,v| v.to_s == type.to_s }.keys
16
+ end
12
17
  end
13
18
 
14
19
  end
@@ -21,7 +21,20 @@ module DSLize
21
21
  { :has_one => nil, :has_many => "unbounded"}.each do |relation, max_occurs|
22
22
  (options[relation] or []).each do |k, v|
23
23
  named_object_if_needed(xsd, k, v) do
24
- xsd.element(nil, { :ref => (v[:type] or k), :maxOccurs => max_occurs }.select { |k,v| !v.nil? })
24
+ clazz = v[:type] or k
25
+ subclasses = get_subclasses(clazz)
26
+ if subclasses.empty?
27
+ xsd.element(nil, { :ref => clazz, :maxOccurs => max_occurs }.select { |k,v| !v.nil? })
28
+ else
29
+ xsd.choice({ :maxOccurs => max_occurs }.select { |k,v| !v.nil? }) do
30
+ subclasses.each do |sub_type|
31
+ xsd.element(nil, :ref => sub_type)
32
+ end
33
+ if !objects[clazz][:abstract]
34
+ xsd.element(nil, :ref => clazz)
35
+ end
36
+ end
37
+ end
25
38
  end
26
39
  end
27
40
  end
@@ -1,3 +1,3 @@
1
1
  module DSLize
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/sample.rb CHANGED
@@ -56,6 +56,10 @@ module DSLize::Definition
56
56
  class WaterPlanet < Planet
57
57
  end
58
58
 
59
+ class Universe
60
+ has_many Planet
61
+ end
62
+
59
63
  end
60
64
 
61
65
  DSLize::Formatter::XSD.new.generate!(ARGV[0])
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - redox
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-07-11 00:00:00 +02:00
17
+ date: 2012-07-12 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20