sdl-ng 0.1.5 → 0.1.6
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/base/fact.rb +13 -0
- data/lib/sdl/base/property.rb +26 -0
- data/lib/sdl/base/service_compendium.rb +106 -22
- data/lib/sdl/base/service_compendium/load_transaction.rb +9 -0
- data/lib/sdl/base/service_compendium/service_load_transaction.rb +22 -19
- data/lib/sdl/base/service_compendium/vocabulary_load_transaction.rb +27 -25
- data/lib/sdl/base/type.rb +20 -1
- data/lib/sdl/ng/version.rb +1 -1
- data/lib/sdl/receivers/service_receiver.rb +6 -12
- data/lib/sdl/receivers/type_instance_receiver.rb +1 -1
- data/lib/sdl/receivers/type_receiver.rb +10 -2
- data/spec/examples_spec.rb +12 -12
- data/spec/service_compendium_spec.rb +7 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0087ac1bbc359ae8f572a80782a5b71ab6aa1599
|
4
|
+
data.tar.gz: 1541db73e7090f6c099508a02d197aebd0c8dd66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d56fdaf6e4b8442359afbc25cd0733ff106720754c89e9981b8b675b3e4a1989d948c21ebaa9afe3edcc0a8a91c566ee0a0fd6a30ef623d75a90ce36ab98fd0a
|
7
|
+
data.tar.gz: d796b0b1eb65a5149e79f78238ef8061a605df537a9298e302ca28ecb98d0a4b053a73066dd094c772e654a95147ef1762cd151ffaac25b4348d6216c30daef9
|
data/lib/sdl/base/fact.rb
CHANGED
@@ -5,6 +5,19 @@
|
|
5
5
|
class SDL::Base::Fact < SDL::Base::Type
|
6
6
|
attr_accessor :service
|
7
7
|
|
8
|
+
class << self
|
9
|
+
##
|
10
|
+
# Returns the possible keywords to instantiate this fact class
|
11
|
+
# @return [<String>]
|
12
|
+
def keywords
|
13
|
+
is_form = "is_#{local_name.underscore.verb.conjugate(:tense => :past, :person => :third, :plurality => :singular, :aspect => :perfective)}"
|
14
|
+
has_form = "has_#{local_name.underscore}"
|
15
|
+
simple_form = local_name.underscore
|
16
|
+
|
17
|
+
[has_form, simple_form, is_form]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
8
21
|
def parent
|
9
22
|
service
|
10
23
|
end
|
data/lib/sdl/base/property.rb
CHANGED
@@ -1,31 +1,57 @@
|
|
1
1
|
##
|
2
2
|
# A property of a Fact or Type. It has a #name and an associated Type.
|
3
3
|
class SDL::Base::Property
|
4
|
+
##
|
4
5
|
# The Property name
|
6
|
+
# @!attribute [r] name
|
7
|
+
# @return [String]
|
5
8
|
attr :name
|
6
9
|
|
10
|
+
##
|
7
11
|
# The Property Type
|
12
|
+
# @!attribute [r] type
|
13
|
+
# @return [Class]
|
8
14
|
attr :type
|
9
15
|
|
16
|
+
##
|
10
17
|
# Is this Property multi-valued
|
18
|
+
# @!attribute [r] multi
|
19
|
+
# @return [Boolean]
|
11
20
|
attr :multi
|
12
21
|
|
22
|
+
##
|
13
23
|
# The type, for which the property is defined
|
24
|
+
# @!attribute [r] parent
|
25
|
+
# @return [Class]
|
14
26
|
attr :parent
|
15
27
|
|
28
|
+
##
|
16
29
|
# The type, which currently holds this property
|
30
|
+
# @!attribute [r] holder
|
31
|
+
# @return [Class]
|
17
32
|
attr_accessor :holder
|
18
33
|
|
34
|
+
##
|
19
35
|
# Is this Property single-valued
|
36
|
+
# @return [Boolean]
|
20
37
|
def single?
|
21
38
|
!@multi
|
22
39
|
end
|
23
40
|
|
41
|
+
##
|
24
42
|
# Is this Property multi-valued
|
43
|
+
# @return [Boolean]
|
25
44
|
def multi?
|
26
45
|
@multi
|
27
46
|
end
|
28
47
|
|
48
|
+
##
|
49
|
+
# Was this property inherited from one of its parents?
|
50
|
+
# @return [Boolean]
|
51
|
+
def inherited?
|
52
|
+
! parent.eql? holder
|
53
|
+
end
|
54
|
+
|
29
55
|
# Define a property by its name and type
|
30
56
|
def initialize(name, type, parent, multi = false)
|
31
57
|
@name, @type, @parent, @multi = name.to_s, type, parent, multi
|
@@ -3,6 +3,7 @@
|
|
3
3
|
class SDL::Base::ServiceCompendium
|
4
4
|
extend ActiveSupport::Autoload
|
5
5
|
|
6
|
+
autoload :LoadTransaction
|
6
7
|
autoload :VocabularyLoadTransaction
|
7
8
|
autoload :ServiceLoadTransaction
|
8
9
|
|
@@ -12,21 +13,44 @@ class SDL::Base::ServiceCompendium
|
|
12
13
|
##
|
13
14
|
# A list of all +Fact+ classes registered in this compendium
|
14
15
|
# @!attribute [r] fact_classes
|
15
|
-
# @return Array<Class>
|
16
|
+
# @return [Array<Class>]
|
16
17
|
attr :fact_classes
|
17
18
|
|
18
19
|
##
|
19
20
|
# A list of all +Type+ classes registered in this compendium
|
20
21
|
# @!attribute [r] types
|
21
|
-
# @return Array<Class>
|
22
|
+
# @return [Array<Class>]
|
22
23
|
attr :types
|
23
24
|
|
24
25
|
##
|
25
|
-
# Registered codes for +SDLSimpleType+s
|
26
|
+
# Registered codes for +SDLSimpleType+s and +Type+s.
|
26
27
|
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
|
28
|
+
# These are used in the definition of the type of a property.
|
29
|
+
#
|
30
|
+
# @!attribute [r] all_codes
|
31
|
+
# @return [Hash{String => Class}]
|
32
|
+
attr :all_codes
|
33
|
+
|
34
|
+
##
|
35
|
+
# Registered codes for +SDLSimpleType+s.
|
36
|
+
#
|
37
|
+
# These are used in the definition of the type of a property.
|
38
|
+
#
|
39
|
+
# @!attribute [r] sdl_simple_type_codes
|
40
|
+
# @return [Hash{String => Class}]
|
41
|
+
attr :sdl_simple_type_codes
|
42
|
+
|
43
|
+
##
|
44
|
+
# Registered codes for +Type+s.
|
45
|
+
#
|
46
|
+
# These are used in the definition of the type of a property.
|
47
|
+
#
|
48
|
+
# @!attribute [r] type_codes
|
49
|
+
# @return [Hash{String => Class}]
|
50
|
+
attr :type_codes
|
51
|
+
|
52
|
+
##
|
53
|
+
# Registered codes for +SDL
|
30
54
|
|
31
55
|
##
|
32
56
|
# A map containing predefined type instances, mapped to their Type classes.
|
@@ -61,7 +85,9 @@ class SDL::Base::ServiceCompendium
|
|
61
85
|
# Initializes the compendium.
|
62
86
|
def initialize
|
63
87
|
@fact_classes, @types, @services = [], [], {}
|
64
|
-
@type_instances, @
|
88
|
+
@type_instances, @sdl_simple_type_codes, @type_codes, @all_codes = {}, {}, {}, {}
|
89
|
+
|
90
|
+
@type_instances.default = {}
|
65
91
|
|
66
92
|
@service_methods = Module.new() do |mod|
|
67
93
|
include ServiceMethods
|
@@ -70,6 +96,17 @@ class SDL::Base::ServiceCompendium
|
|
70
96
|
register_default_types
|
71
97
|
end
|
72
98
|
|
99
|
+
##
|
100
|
+
# A compendium is empty, if there are neither types, nor services loaded.
|
101
|
+
# @return [Boolean] If this compendium is empty.
|
102
|
+
def empty?
|
103
|
+
@fact_classes.empty? &&
|
104
|
+
@types.empty? &&
|
105
|
+
@services.empty? &&
|
106
|
+
@type_instances.empty? &&
|
107
|
+
@type_codes.empty?
|
108
|
+
end
|
109
|
+
|
73
110
|
def facts_definition(&facts_definitions)
|
74
111
|
self.instance_eval &facts_definitions
|
75
112
|
end
|
@@ -78,6 +115,11 @@ class SDL::Base::ServiceCompendium
|
|
78
115
|
self.instance_eval &type_instances_definition
|
79
116
|
end
|
80
117
|
|
118
|
+
##
|
119
|
+
# Runs the +&block+ with specified +current_uri+ and restores the old +current_uri+.
|
120
|
+
#
|
121
|
+
# @param [String] current_uri The URI, with which the block should be run.
|
122
|
+
# @param [Block] block The block, which will be called.
|
81
123
|
def with_uri(current_uri, &block)
|
82
124
|
old_uri = @current_uri
|
83
125
|
@current_uri = current_uri
|
@@ -101,6 +143,8 @@ class SDL::Base::ServiceCompendium
|
|
101
143
|
# Refer to the symbolic name of the current class, which can be a subclass of
|
102
144
|
sym = fact_class.local_name.underscore.to_sym
|
103
145
|
|
146
|
+
# Extend the @service_methods module with methods retrieving the first or all
|
147
|
+
# instances of this fact, e.g. "service.features" would find all Feature facts
|
104
148
|
@service_methods.class_eval do
|
105
149
|
unless SDL::Base::Service.instance_methods.include? sym
|
106
150
|
define_method sym do
|
@@ -122,10 +166,16 @@ class SDL::Base::ServiceCompendium
|
|
122
166
|
receiver = SDL::Receivers::TypeReceiver.new(sym, self)
|
123
167
|
receiver.klass.loaded_from = @current_uri
|
124
168
|
receiver.instance_eval &type_definition if block_given?
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
169
|
+
|
170
|
+
@types.concat receiver.subclasses
|
171
|
+
|
172
|
+
receiver.subclasses.each do |klass|
|
173
|
+
klass.loaded_from = @current_uri
|
174
|
+
register_codes klass
|
175
|
+
register_sdltype klass
|
176
|
+
@type_instances[klass] = {}
|
177
|
+
end
|
178
|
+
|
129
179
|
receiver.klass
|
130
180
|
end
|
131
181
|
|
@@ -142,10 +192,17 @@ class SDL::Base::ServiceCompendium
|
|
142
192
|
end
|
143
193
|
|
144
194
|
##
|
145
|
-
# Registers an SDLSimpleType under its code
|
146
|
-
|
195
|
+
# Registers an SDLSimpleType or SDLType under its code
|
196
|
+
# @param [Class] type The type to be registered.
|
197
|
+
def register_codes(type)
|
198
|
+
if type < SDL::Types::SDLSimpleType
|
199
|
+
type.codes.each do |c| @sdl_simple_type_codes[c] = type end
|
200
|
+
else
|
201
|
+
type.codes.each do |c| @type_codes[c] = type end
|
202
|
+
end
|
203
|
+
|
147
204
|
type.codes.each do |code|
|
148
|
-
@
|
205
|
+
@all_codes[code] = type
|
149
206
|
end
|
150
207
|
end
|
151
208
|
|
@@ -174,19 +231,46 @@ class SDL::Base::ServiceCompendium
|
|
174
231
|
end
|
175
232
|
end
|
176
233
|
|
234
|
+
##
|
235
|
+
# Returns an iterator for all items, which were loaded by this compendium
|
236
|
+
def loaded_items
|
237
|
+
@fact_classes.each do |fact_class|
|
238
|
+
yield fact_class
|
239
|
+
end
|
240
|
+
|
241
|
+
@types.each do |type_class|
|
242
|
+
yield type_class
|
243
|
+
end
|
244
|
+
|
245
|
+
@type_instances.each do |type_class, instance_hash|
|
246
|
+
instance_hash.each do |symbol, instance|
|
247
|
+
yield instance
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
@services.each do |symbol, service|
|
252
|
+
yield service
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
177
256
|
##
|
178
257
|
# Unloads all items with the specified uri from this service compendium
|
179
258
|
def unload(uri)
|
259
|
+
@services.delete_if do |symbolic_name, service| service.loaded_from.eql?(uri) end
|
260
|
+
|
180
261
|
@fact_classes.delete_if do |item| item.loaded_from.eql?(uri) end
|
181
|
-
@types.delete_if do |item| item.loaded_from.eql?(uri) end
|
182
|
-
@services.delete_if do |item| item.loaded_from.eql?(uri) end
|
183
262
|
|
184
|
-
@
|
185
|
-
|
186
|
-
|
187
|
-
end
|
263
|
+
@types.delete_if do |item|
|
264
|
+
if item.loaded_from.eql?(uri) then
|
265
|
+
@type_instances.delete(item)
|
188
266
|
|
189
|
-
|
267
|
+
@all_codes.delete_if do |code, type| type.eql? item end
|
268
|
+
@type_codes.delete_if do |code, type| type.eql? item end
|
269
|
+
|
270
|
+
true
|
271
|
+
else
|
272
|
+
false
|
273
|
+
end
|
190
274
|
end
|
191
275
|
end
|
192
276
|
|
@@ -212,7 +296,7 @@ class SDL::Base::ServiceCompendium
|
|
212
296
|
# Registers all default types
|
213
297
|
def register_default_types
|
214
298
|
SDL::Types::SDLSimpleType.descendants.each do |type|
|
215
|
-
|
299
|
+
register_codes type
|
216
300
|
end
|
217
301
|
end
|
218
302
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module SDL::Base::ServiceCompendium::LoadTransaction
|
2
|
+
def to_files_array(path_or_filename, suffix)
|
3
|
+
if File.file? path_or_filename
|
4
|
+
[path_or_filename]
|
5
|
+
elsif File.directory? path_or_filename
|
6
|
+
Dir.glob(File.join(path_or_filename, '**', "*#{suffix}"))
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -1,17 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# Service definition files are expected to end with +.service.rb+
|
7
|
-
# @param path_or_filename[String] Either a filename or a path
|
8
|
-
def load_service_from_path(path_or_filename)
|
9
|
-
path_or_filename = [path_or_filename] if File.file? path_or_filename
|
1
|
+
class SDL::Base::ServiceCompendium
|
2
|
+
# A transaction for loading vocabulary definition
|
3
|
+
module ServiceLoadTransaction
|
4
|
+
include LoadTransaction
|
10
5
|
|
11
|
-
|
12
|
-
|
6
|
+
##
|
7
|
+
# Loads a service, either from a file or from a path recursively.
|
8
|
+
#
|
9
|
+
# Service definition files are expected to end with +.service.rb+
|
10
|
+
# @param path_or_filename[String] Either a filename or a path
|
11
|
+
# @param ignore_errors[Boolean] Ignore errors when loading service
|
12
|
+
def load_service_from_path(path_or_filename, ignore_errors = false)
|
13
|
+
to_files_array(path_or_filename, '.service.rb').each do |filename|
|
14
|
+
service_name = filename.match(%r[.+/(.+).service.rb])[1]
|
13
15
|
|
14
|
-
|
16
|
+
begin
|
17
|
+
load_service_from_string File.read(filename), service_name, filename
|
18
|
+
rescue Exception => e
|
19
|
+
raise e unless ignore_errors
|
20
|
+
end
|
21
|
+
end
|
15
22
|
end
|
16
23
|
end
|
17
24
|
|
@@ -22,14 +29,10 @@ module SDL::Base::ServiceCompendium::ServiceLoadTransaction
|
|
22
29
|
# @param [String] uri The URI
|
23
30
|
# @raise [SyntaxError] If there is an error in service_definition
|
24
31
|
def load_service_from_string(service_definition, service_name, uri)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
eval service_definition, binding
|
29
|
-
end
|
32
|
+
with_uri uri do
|
33
|
+
service service_name do
|
34
|
+
eval service_definition, binding, uri
|
30
35
|
end
|
31
|
-
rescue Exception => e
|
32
|
-
raise SyntaxError.new("Error while loading '#{service_name}' from '#{uri}': #{e}")
|
33
36
|
end
|
34
37
|
end
|
35
38
|
end
|
@@ -1,33 +1,35 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# Vocabulary definition files are expected to end with +.sdl.rb+
|
7
|
-
# @param path_or_filename[String] Either a filename or a path
|
8
|
-
def load_vocabulary_from_path(path_or_filename)
|
9
|
-
path_or_filename = [path_or_filename] if File.file? path_or_filename
|
1
|
+
class SDL::Base::ServiceCompendium
|
2
|
+
# A transaction for loading vocabulary definition
|
3
|
+
module VocabularyLoadTransaction
|
4
|
+
include LoadTransaction
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
##
|
7
|
+
# Loads vocabulary, either from a file or from a path recursively.
|
8
|
+
#
|
9
|
+
# Vocabulary definition files are expected to end with +.sdl.rb+
|
10
|
+
# @param path_or_filename[String] Either a filename or a path
|
11
|
+
def load_vocabulary_from_path(path_or_filename)
|
12
|
+
to_files_array(path_or_filename, '.sdl.rb').each do |filename|
|
13
|
+
with_uri filename do
|
14
|
+
load_vocabulary_from_string File.read(filename), filename
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
##
|
20
|
+
# Loads a vocabulary from a string. The URI is used with ServiceCompendium#with_uri.
|
21
|
+
# @param [String] vocabulary_definition The vocabulary definition
|
22
|
+
# @param [String] uri The URI
|
23
|
+
def load_vocabulary_from_string(vocabulary_definition, uri)
|
24
|
+
begin
|
25
|
+
with_uri uri do
|
26
|
+
eval vocabulary_definition, binding
|
27
|
+
end
|
28
|
+
rescue Exception => e
|
29
|
+
unload uri
|
29
30
|
|
30
|
-
|
31
|
+
raise "Error while loading vocabulary from #{uri}: #{e}"
|
32
|
+
end
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
data/lib/sdl/base/type.rb
CHANGED
@@ -5,9 +5,11 @@ class SDL::Base::Type
|
|
5
5
|
include SDL::Base::URIMappedResource
|
6
6
|
|
7
7
|
# The namespace URL of this Type class
|
8
|
+
# !@attr [r] namespace
|
8
9
|
attr_accessor :namespace
|
9
10
|
|
10
11
|
# If the Type is a list item type
|
12
|
+
# !@attr [r] list_item
|
11
13
|
attr_accessor :list_item
|
12
14
|
|
13
15
|
##
|
@@ -16,14 +18,27 @@ class SDL::Base::Type
|
|
16
18
|
# The ServiceCompendium#register_classes_globally method makes this class accessible by a constant of this name
|
17
19
|
@local_name
|
18
20
|
|
21
|
+
alias :original_name :name
|
22
|
+
|
23
|
+
def name
|
24
|
+
original_name || local_name
|
25
|
+
end
|
26
|
+
|
19
27
|
def local_name
|
20
|
-
@local_name ||
|
28
|
+
@local_name || original_name.demodulize
|
21
29
|
end
|
22
30
|
|
23
31
|
def local_name=(name)
|
24
32
|
@local_name = name
|
25
33
|
end
|
26
34
|
|
35
|
+
# A list of all subtypes
|
36
|
+
# !@attr [r] subtypes
|
37
|
+
# @return [<Class>] The subtypes
|
38
|
+
def subtypes
|
39
|
+
@subtypes ||= []
|
40
|
+
end
|
41
|
+
|
27
42
|
def to_s
|
28
43
|
@local_name || name
|
29
44
|
end
|
@@ -63,6 +78,10 @@ class SDL::Base::Type
|
|
63
78
|
def is_sub?
|
64
79
|
not [SDL::Base::Type, SDL::Base::Fact].include? superclass
|
65
80
|
end
|
81
|
+
|
82
|
+
def sdl_ancestors
|
83
|
+
ancestors.drop(1).take_while {|ancestor| ! [SDL::Base::Type, SDL::Base::Fact, SDL::Types::SDLType].include? ancestor}
|
84
|
+
end
|
66
85
|
end
|
67
86
|
|
68
87
|
##
|
data/lib/sdl/ng/version.rb
CHANGED
@@ -11,16 +11,10 @@ class SDL::Receivers::ServiceReceiver < SDL::Receivers::Receiver
|
|
11
11
|
@service = SDL::Base::Service.new(sym.to_s)
|
12
12
|
|
13
13
|
compendium.fact_classes.each do |fact_class|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
define_singleton_method("has_#{fact_class.local_name.underscore}") do |*args, &block|
|
19
|
-
add_fact fact_class, *args, &block
|
20
|
-
end
|
21
|
-
|
22
|
-
define_singleton_method("#{fact_class.local_name.underscore}") do |*args, &block|
|
23
|
-
add_fact fact_class, *args, &block
|
14
|
+
fact_class.keywords.each do |keyword|
|
15
|
+
define_singleton_method keyword do |*args, &block|
|
16
|
+
add_fact fact_class, *args, &block
|
17
|
+
end
|
24
18
|
end
|
25
19
|
end
|
26
20
|
end
|
@@ -48,12 +42,12 @@ class SDL::Receivers::ServiceReceiver < SDL::Receivers::Receiver
|
|
48
42
|
|
49
43
|
unless possible_type_instances.nil? || possible_type_instances.empty?
|
50
44
|
if possible_type_instances.length > 1
|
51
|
-
raise Exception.new("Multiple possibilities for #{name}
|
45
|
+
raise Exception.new("Multiple possibilities for #{name}")
|
52
46
|
else
|
53
47
|
possible_type_instances[0]
|
54
48
|
end
|
55
49
|
else
|
56
|
-
raise Exception.new("I do not know what to do with '#{name}'
|
50
|
+
raise Exception.new("I do not know what to do with '#{name}'")
|
57
51
|
end
|
58
52
|
end
|
59
53
|
end
|
@@ -82,7 +82,7 @@ class SDL::Receivers::TypeInstanceReceiver < SDL::Receivers::Receiver
|
|
82
82
|
unless possible_type_instances.nil? || possible_type_instances.empty?
|
83
83
|
possible_type_instances[0]
|
84
84
|
else
|
85
|
-
raise Exception.new("I do not know what to do with '#{name}'
|
85
|
+
raise Exception.new("I do not know what to do with '#{name}'.")
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
@@ -1,7 +1,14 @@
|
|
1
1
|
class SDL::Receivers::TypeReceiver < SDL::Receivers::Receiver
|
2
2
|
include ActiveSupport::Inflector
|
3
3
|
|
4
|
+
# The class for which the type receiver was instantiated
|
5
|
+
# !@attr [r] klass
|
6
|
+
# @return [Class]
|
4
7
|
attr :klass
|
8
|
+
|
9
|
+
# The class and all subclasses
|
10
|
+
# !@attr [r] subclasses
|
11
|
+
# @return [Array<Class>]
|
5
12
|
attr :subclasses
|
6
13
|
|
7
14
|
def initialize(sym, compendium, superklass = nil)
|
@@ -31,6 +38,7 @@ class SDL::Receivers::TypeReceiver < SDL::Receivers::Receiver
|
|
31
38
|
def subtype(sym, &definition)
|
32
39
|
receiver = self.class.new(sym, @compendium, @klass)
|
33
40
|
receiver.instance_eval(&definition) if block_given?
|
41
|
+
klass.subtypes << receiver.klass
|
34
42
|
|
35
43
|
@subclasses.concat(receiver.subclasses)
|
36
44
|
end
|
@@ -51,10 +59,10 @@ class SDL::Receivers::TypeReceiver < SDL::Receivers::Receiver
|
|
51
59
|
|
52
60
|
if name =~ /list_of_/
|
53
61
|
multi = true
|
54
|
-
type = @compendium.
|
62
|
+
type = @compendium.all_codes[name.to_s.gsub('list_of_', '').singularize.to_sym]
|
55
63
|
else
|
56
64
|
multi = false
|
57
|
-
type = @compendium.
|
65
|
+
type = @compendium.all_codes[name.to_sym]
|
58
66
|
end
|
59
67
|
|
60
68
|
if type
|
data/spec/examples_spec.rb
CHANGED
@@ -3,26 +3,26 @@ require_relative 'spec_helper'
|
|
3
3
|
require 'rspec'
|
4
4
|
|
5
5
|
describe 'the bundled examples' do
|
6
|
-
|
7
|
-
SDL::Base::ServiceCompendium.new
|
8
|
-
end
|
6
|
+
it 'can be (un-)loaded and traces the load path of files' do
|
7
|
+
compendium = SDL::Base::ServiceCompendium.new
|
9
8
|
|
10
|
-
let :loaded_compendium do
|
11
9
|
expect {
|
12
10
|
compendium.load_vocabulary_from_path File.join(__dir__, '..', 'examples', 'vocabulary')
|
13
11
|
compendium.load_service_from_path File.join(__dir__, '..', 'examples', 'services')
|
14
12
|
}.not_to raise_exception
|
15
13
|
|
16
|
-
|
17
|
-
end
|
14
|
+
items_to_unload = []
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
compendium.loaded_items do |loaded_item|
|
17
|
+
expect(File.exists?(loaded_item.loaded_from))
|
18
|
+
|
19
|
+
items_to_unload << loaded_item
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
22
|
+
items_to_unload.each do |loaded_item|
|
23
|
+
expect{compendium.unload(loaded_item.loaded_from)}.not_to raise_exception
|
24
|
+
end
|
25
25
|
|
26
|
-
expect(
|
26
|
+
expect(compendium).to be_empty
|
27
27
|
end
|
28
28
|
end
|
@@ -34,6 +34,10 @@ describe 'The service compendium' do
|
|
34
34
|
expect(subject.types.first).to be < SDL::Base::Type
|
35
35
|
end
|
36
36
|
|
37
|
+
it 'allows the definition of service subtypes' do
|
38
|
+
pending 'Not yet implemented'
|
39
|
+
end
|
40
|
+
|
37
41
|
it 'allows the definition of services' do
|
38
42
|
subject.service :example_service
|
39
43
|
|
@@ -137,7 +141,7 @@ END
|
|
137
141
|
end
|
138
142
|
|
139
143
|
it 'does not let double definitions of types and facts happen' do
|
140
|
-
pending
|
144
|
+
pending
|
141
145
|
end
|
142
146
|
|
143
147
|
context 'with defined example classes' do
|
@@ -164,8 +168,8 @@ END
|
|
164
168
|
compendium
|
165
169
|
end
|
166
170
|
|
167
|
-
it 'registers the code for the example type with its #
|
168
|
-
expect(subject.
|
171
|
+
it 'registers the code for the example type with its #all_codes' do
|
172
|
+
expect(subject.all_codes[:example_type]).to be subject.types.first
|
169
173
|
end
|
170
174
|
end
|
171
175
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sdl-ng
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathias Slawik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -234,6 +234,7 @@ files:
|
|
234
234
|
- lib/sdl/base/property.rb
|
235
235
|
- lib/sdl/base/service.rb
|
236
236
|
- lib/sdl/base/service_compendium.rb
|
237
|
+
- lib/sdl/base/service_compendium/load_transaction.rb
|
237
238
|
- lib/sdl/base/service_compendium/service_load_transaction.rb
|
238
239
|
- lib/sdl/base/service_compendium/vocabulary_load_transaction.rb
|
239
240
|
- lib/sdl/base/type.rb
|