sdl-ng 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/lib/sdl.rb +18 -7
- data/lib/sdl/base.rb +7 -6
- data/lib/sdl/base/fact.rb +7 -11
- data/lib/sdl/base/property.rb +22 -26
- data/lib/sdl/base/service.rb +8 -12
- data/lib/sdl/base/service_compendium.rb +97 -109
- data/lib/sdl/base/type.rb +62 -68
- data/lib/sdl/exporters.rb +13 -9
- data/lib/sdl/exporters/exporter.rb +10 -14
- data/lib/sdl/exporters/markdown_service_exporter.rb +0 -2
- data/lib/sdl/exporters/rdf_exporter.rb +17 -21
- data/lib/sdl/exporters/rdf_mapping.rb +0 -1
- data/lib/sdl/exporters/schema_exporter.rb +3 -7
- data/lib/sdl/exporters/service_exporter.rb +4 -8
- data/lib/sdl/exporters/xml_service_exporter.rb +22 -26
- data/lib/sdl/exporters/xsd_schema_exporter.rb +65 -70
- data/lib/sdl/ng/version.rb +1 -1
- data/lib/sdl/receivers.rb +7 -6
- data/lib/sdl/receivers/fact_receiver.rb +8 -12
- data/lib/sdl/receivers/service_receiver.rb +41 -47
- data/lib/sdl/receivers/type_instance_receiver.rb +67 -73
- data/lib/sdl/receivers/type_receiver.rb +72 -76
- data/lib/sdl/types.rb +15 -9
- data/lib/sdl/types/sdl_datetime.rb +4 -8
- data/lib/sdl/types/sdl_description.rb +6 -10
- data/lib/sdl/types/sdl_duration.rb +4 -8
- data/lib/sdl/types/sdl_number.rb +4 -8
- data/lib/sdl/types/sdl_simple_type.rb +13 -6
- data/lib/sdl/types/sdl_string.rb +4 -8
- data/lib/sdl/types/sdl_type.rb +20 -24
- data/lib/sdl/types/sdl_url.rb +9 -13
- data/lib/sdl/util.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63c012a4a880107aa2abc578cd5d6e31586685f4
|
4
|
+
data.tar.gz: 9f48ce28d5770a44db409a24e851ec417dea2566
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff01a182a62dd8a80e8f4c417382fe1b376e4938c8fd8ba7864fed886d549d1afb04099ac58d74794ac2ee03160e4171d5c024b63e6a7df881795101a8c14027
|
7
|
+
data.tar.gz: 18875548fa81bf0b0e4b48a5c0313eb031aebc8e93194583624f92cb42848c7aac79cbf087796766596adb7f1f329fc6f11b965755d1d36d38c1f8ee9b838ee8
|
data/lib/sdl.rb
CHANGED
@@ -1,17 +1,28 @@
|
|
1
1
|
#:include: ../README.md
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/dependencies'
|
5
|
+
require 'active_support/inflector'
|
6
|
+
|
7
|
+
require 'i18n'
|
8
|
+
|
9
|
+
ActiveSupport::Dependencies.autoload_paths += ['sdl']
|
9
10
|
|
10
11
|
##
|
11
12
|
#
|
12
|
-
#
|
13
13
|
# Author:: Mathias Slawik (mailto:mathias.slawik@tu-berlin.de)
|
14
14
|
# License:: Apache License 2.0
|
15
15
|
module SDL
|
16
|
+
extend ActiveSupport::Autoload
|
17
|
+
|
18
|
+
autoload :Base
|
19
|
+
autoload :Exporters
|
20
|
+
autoload :Receivers
|
21
|
+
|
22
|
+
eager_autoload do
|
23
|
+
autoload :Types
|
24
|
+
end
|
16
25
|
|
26
|
+
require_relative 'sdl/util'
|
27
|
+
require_relative 'sdl/ng/version'
|
17
28
|
end
|
data/lib/sdl/base.rb
CHANGED
@@ -1,9 +1,3 @@
|
|
1
|
-
require_relative 'base/type'
|
2
|
-
require_relative 'base/fact'
|
3
|
-
require_relative 'base/property'
|
4
|
-
require_relative 'base/service'
|
5
|
-
require_relative 'base/service_compendium'
|
6
|
-
|
7
1
|
module SDL
|
8
2
|
##
|
9
3
|
# This module contains the base classes of the \SDL Framework.
|
@@ -16,5 +10,12 @@ module SDL
|
|
16
10
|
#
|
17
11
|
# The ServiceCompendium is used for easy definition of new facts, services, types and properties.
|
18
12
|
module Base
|
13
|
+
extend ActiveSupport::Autoload
|
14
|
+
|
15
|
+
autoload :Fact
|
16
|
+
autoload :Property
|
17
|
+
autoload :Service
|
18
|
+
autoload :ServiceCompendium
|
19
|
+
autoload :Type
|
19
20
|
end
|
20
21
|
end
|
data/lib/sdl/base/fact.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
attr_accessor :service
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
##
|
2
|
+
# A fact, which is known about a service.
|
3
|
+
#
|
4
|
+
# Facts are defined by using a ServiceCompendium.
|
5
|
+
class SDL::Base::Fact < SDL::Base::Type
|
6
|
+
attr_accessor :service
|
7
|
+
end
|
data/lib/sdl/base/property.rb
CHANGED
@@ -1,34 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# The Property name
|
7
|
-
attr :name
|
1
|
+
##
|
2
|
+
# A property of a Fact or Type. It has a #name and an associated Type.
|
3
|
+
class SDL::Base::Property
|
4
|
+
# The Property name
|
5
|
+
attr :name
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
# The Property Type
|
8
|
+
attr :type
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
# Is this Property multi-valued
|
11
|
+
attr :multi
|
14
12
|
|
15
|
-
|
16
|
-
|
13
|
+
# The parent type, where this property belongs to
|
14
|
+
attr :parent
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
# Is this Property single-valued
|
17
|
+
def single?
|
18
|
+
!@multi
|
19
|
+
end
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
# Is this Property multi-valued
|
22
|
+
def multi?
|
23
|
+
@multi
|
24
|
+
end
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
26
|
+
# Define a property by its name and type
|
27
|
+
def initialize(name, type, parent, multi = false)
|
28
|
+
@name, @type, @parent, @multi = name.to_s, type, parent, multi
|
33
29
|
end
|
34
30
|
end
|
data/lib/sdl/base/service.rb
CHANGED
@@ -1,17 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Service
|
4
|
-
attr_accessor :facts, :symbolic_name
|
1
|
+
class SDL::Base::Service
|
2
|
+
attr_accessor :facts, :symbolic_name
|
5
3
|
|
6
|
-
|
7
|
-
|
4
|
+
def initialize(symbolic_name)
|
5
|
+
@symbolic_name = symbolic_name
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
@facts, @facades = [], []
|
8
|
+
end
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
10
|
+
def fact_class_facts_map
|
11
|
+
facts.group_by &:class
|
16
12
|
end
|
17
13
|
end
|
@@ -1,130 +1,118 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
##
|
2
|
+
# A service compendium allows the definition of service facts, types and services.
|
3
|
+
class SDL::Base::ServiceCompendium
|
4
|
+
attr :fact_classes
|
5
|
+
attr :types
|
6
|
+
attr :sdltype_codes
|
7
|
+
attr :type_instances
|
8
|
+
attr :services
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@fact_classes, @types, @services = [], [], {}
|
12
|
+
@type_instances, @sdltype_codes = {}, {}
|
13
|
+
|
14
|
+
register_default_types
|
15
|
+
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
attr :type_instances
|
18
|
-
attr :services
|
17
|
+
def facts_definition(&facts_definitions)
|
18
|
+
self.instance_eval &facts_definitions
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def type_instances_definition(&type_instances_definition)
|
22
|
+
self.instance_eval &type_instances_definition
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
# Defines a new class of service facts
|
26
|
+
def fact(sym, &fact_definition)
|
27
|
+
receiver = SDL::Receivers::FactReceiver.new(sym, self)
|
28
|
+
receiver.instance_eval &fact_definition if block_given?
|
29
|
+
receiver.subclasses.each do |fact_class|
|
30
|
+
@fact_classes << fact_class
|
26
31
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
32
|
+
# Refer to the symbolic name of the current class, which can be a subclass of
|
33
|
+
sym = fact_class.local_name.underscore.to_sym
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
ServiceMethods.class_eval do
|
36
|
+
unless SDL::Base::Service.instance_methods.include? sym
|
37
|
+
define_method sym do
|
38
|
+
@facts.find {|fact| fact.is_a? fact_class}
|
39
|
+
end
|
40
|
+
end
|
34
41
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
receiver.instance_eval &fact_definition if block_given?
|
39
|
-
receiver.subclasses.each do |fact_class|
|
40
|
-
@fact_classes << fact_class
|
41
|
-
|
42
|
-
# Refer to the symbolic name of the current class, which can be a subclass of
|
43
|
-
sym = fact_class.local_name.underscore.to_sym
|
44
|
-
|
45
|
-
ServiceMethods.class_eval do
|
46
|
-
unless Service.instance_methods.include? sym
|
47
|
-
define_method sym do
|
48
|
-
@facts.find {|fact| fact.is_a? fact_class}
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
unless Service.instance_methods.include? sym.to_s.pluralize.to_sym
|
53
|
-
define_method sym.to_s.pluralize do
|
54
|
-
@facts.find_all {|fact| fact.is_a? fact_class}
|
55
|
-
end
|
56
|
-
end
|
42
|
+
unless SDL::Base::Service.instance_methods.include? sym.to_s.pluralize.to_sym
|
43
|
+
define_method sym.to_s.pluralize do
|
44
|
+
@facts.find_all {|fact| fact.is_a? fact_class}
|
57
45
|
end
|
58
46
|
end
|
59
47
|
end
|
48
|
+
end
|
49
|
+
end
|
60
50
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
51
|
+
# Defines a new type and returns it
|
52
|
+
def type(sym, &type_definition)
|
53
|
+
receiver = SDL::Receivers::TypeReceiver.new(sym, self)
|
54
|
+
receiver.instance_eval &type_definition if block_given?
|
55
|
+
register_sdltype_codes(receiver.klass)
|
56
|
+
register_sdltype(receiver.klass)
|
57
|
+
@types << receiver.klass
|
58
|
+
@type_instances[receiver.klass] = {}
|
59
|
+
receiver.klass
|
60
|
+
end
|
71
61
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
62
|
+
# Defines a new service, adds all service methods, and returns it
|
63
|
+
def service(sym, &service_definition)
|
64
|
+
receiver = SDL::Receivers::ServiceReceiver.new(sym, self)
|
65
|
+
receiver.instance_eval &service_definition if block_given?
|
66
|
+
@services[sym] = receiver.service
|
67
|
+
receiver.service.symbolic_name = sym.to_s
|
68
|
+
receiver.service.extend ServiceMethods
|
69
|
+
receiver.service
|
70
|
+
end
|
81
71
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
72
|
+
##
|
73
|
+
# Registers the type under its codes
|
74
|
+
def register_sdltype_codes(type)
|
75
|
+
type.instance_variable_get(:@codes).each do |code|
|
76
|
+
@sdltype_codes[code] = type
|
77
|
+
end
|
78
|
+
end
|
89
79
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
80
|
+
##
|
81
|
+
# Allows this compendium to be used for adding new type instances
|
82
|
+
def register_sdltype(type)
|
83
|
+
# Define a method, which adds the type instance defined in the block to this compendium and adds it as a
|
84
|
+
# constant the the type class
|
85
|
+
self.class.send(:define_method, type.local_name.underscore) do |identifier, &block|
|
86
|
+
receiver = SDL::Receivers::TypeInstanceReceiver.new(type.new, self)
|
97
87
|
|
98
|
-
|
88
|
+
receiver.instance_eval &block if block != nil
|
99
89
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
90
|
+
receiver.instance.identifier = identifier
|
91
|
+
@type_instances[type][identifier] = receiver.instance
|
92
|
+
end
|
93
|
+
end
|
104
94
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
95
|
+
##
|
96
|
+
# Registers all classes by their #local_name to be used in all scopes
|
97
|
+
def register_classes_globally
|
98
|
+
(@fact_classes + @types).each do |defined_class|
|
99
|
+
Object.send(:remove_const, defined_class.local_name) if Object.const_defined? defined_class.local_name.to_sym
|
100
|
+
Object.const_set defined_class.local_name, defined_class
|
101
|
+
end
|
102
|
+
end
|
113
103
|
|
114
|
-
|
115
|
-
|
116
|
-
|
104
|
+
# This module is included in every service defined by this compendium and contains methods to easily retreive
|
105
|
+
# certain fact instances by their name.
|
106
|
+
module ServiceMethods
|
117
107
|
|
118
|
-
|
108
|
+
end
|
119
109
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
end
|
110
|
+
private
|
111
|
+
##
|
112
|
+
# Registers all default types
|
113
|
+
def register_default_types
|
114
|
+
SDL::Types::SDLSimpleType.sdl_types.each do |type|
|
115
|
+
register_sdltype_codes type
|
116
|
+
end
|
128
117
|
end
|
129
|
-
end
|
130
118
|
end
|
data/lib/sdl/base/type.rb
CHANGED
@@ -1,82 +1,76 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def local_name
|
17
|
-
@local_name || name.demodulize
|
18
|
-
end
|
19
|
-
|
20
|
-
def local_name=(name)
|
21
|
-
@local_name = name
|
22
|
-
end
|
1
|
+
class SDL::Base::Type
|
2
|
+
class << self
|
3
|
+
## The namespace URL of this Fact class
|
4
|
+
attr_accessor :namespace
|
5
|
+
|
6
|
+
##
|
7
|
+
# The local name of the type, e.g. "Name" or "ServiceInterface". Defaults to the name of the class.
|
8
|
+
#
|
9
|
+
# The ServiceCompendium#register_classes_globally method makes this class accessible by a constant of this name
|
10
|
+
@local_name
|
11
|
+
|
12
|
+
def local_name
|
13
|
+
@local_name || name.demodulize
|
14
|
+
end
|
23
15
|
|
24
|
-
|
25
|
-
|
26
|
-
|
16
|
+
def local_name=(name)
|
17
|
+
@local_name = name
|
18
|
+
end
|
27
19
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
else
|
32
|
-
@properties ||= []
|
33
|
-
end
|
34
|
-
end
|
20
|
+
def to_s
|
21
|
+
@local_name || name
|
22
|
+
end
|
35
23
|
|
36
|
-
|
37
|
-
|
38
|
-
|
24
|
+
def properties(including_super = false)
|
25
|
+
if including_super && is_sub?
|
26
|
+
self.properties + superclass.properties(true)
|
27
|
+
else
|
28
|
+
@properties ||= []
|
29
|
+
end
|
30
|
+
end
|
39
31
|
|
40
|
-
|
41
|
-
|
42
|
-
|
32
|
+
def propertyless?(including_super = false)
|
33
|
+
properties(including_super).count == 0
|
34
|
+
end
|
43
35
|
|
44
|
-
|
45
|
-
|
46
|
-
|
36
|
+
def single_property?(including_super = false)
|
37
|
+
properties(including_super).count == 1
|
38
|
+
end
|
47
39
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
40
|
+
def multi_property?(including_super = true)
|
41
|
+
properties(including_super).count > 1
|
42
|
+
end
|
52
43
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
44
|
+
def is_sub?
|
45
|
+
not [SDL::Base::Type, SDL::Base::Fact].include? superclass
|
46
|
+
end
|
47
|
+
end
|
58
48
|
|
59
|
-
|
60
|
-
|
61
|
-
|
49
|
+
##
|
50
|
+
# Gets the values of all properties
|
51
|
+
def property_values
|
52
|
+
Hash[self.class.properties(true).map{|p| [p, send(p.name)]}]
|
53
|
+
end
|
62
54
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
self.class.to_s
|
67
|
-
end
|
68
|
-
end
|
55
|
+
def to_s
|
56
|
+
# If there is a property with the same name, than the type, return its to_s, return the name of the class
|
57
|
+
naming_property = self.class.properties(true).find {|p| p.name.eql?(self.class.to_s.underscore) }
|
69
58
|
|
70
|
-
|
71
|
-
|
72
|
-
|
59
|
+
if(naming_property)
|
60
|
+
instance_variable_get("@#{naming_property.name.to_sym}").to_s
|
61
|
+
else
|
62
|
+
self.class.to_s
|
63
|
+
end
|
64
|
+
end
|
73
65
|
|
74
|
-
|
75
|
-
|
76
|
-
|
66
|
+
def annotated?
|
67
|
+
! @annotations.blank?
|
68
|
+
end
|
77
69
|
|
78
|
-
|
79
|
-
|
80
|
-
end
|
70
|
+
def annotations
|
71
|
+
@annotations ||= []
|
81
72
|
end
|
73
|
+
|
74
|
+
# An identifier for type instances
|
75
|
+
attr_accessor :identifier
|
82
76
|
end
|