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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed2ffb4ec0dbbbcb9215c77af53ea65ff29697f4
4
- data.tar.gz: 123f3cf6588274e6605708bc2fc27c71004702c4
3
+ metadata.gz: 63c012a4a880107aa2abc578cd5d6e31586685f4
4
+ data.tar.gz: 9f48ce28d5770a44db409a24e851ec417dea2566
5
5
  SHA512:
6
- metadata.gz: e13f8fb585f8339390a6f82d339ce0daf8b3057467aa67ead071905af9bc125802746b8a984b10198b918cecc57b90e45f07f11099606e2dfd175289a87c0246
7
- data.tar.gz: acc087d16fbf6ceb3380e80b6f118d24270c31beb2a0d1a7f757f087e32e07e4c637d3c4da562926d57944fc8daa9f7ec65b7ee3e998503a248a8352e93e96bd
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
- require_relative 'sdl/base'
4
- require_relative 'sdl/receivers'
5
- require_relative 'sdl/types'
6
- require_relative 'sdl/exporters'
7
- require_relative 'sdl/util'
8
- require_relative 'sdl/ng/version'
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
- module SDL
2
- module Base
3
- ##
4
- # A fact, which is known about a service.
5
- #
6
- # Facts are defined by using a ServiceCompendium.
7
- class Fact < Type
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
@@ -1,34 +1,30 @@
1
- module SDL
2
- module Base
3
- ##
4
- # A property of a Fact or Type. It has a #name and an associated Type.
5
- class Property
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
- # The Property Type
10
- attr :type
7
+ # The Property Type
8
+ attr :type
11
9
 
12
- # Is this Property multi-valued
13
- attr :multi
10
+ # Is this Property multi-valued
11
+ attr :multi
14
12
 
15
- # The parent type, where this property belongs to
16
- attr :parent
13
+ # The parent type, where this property belongs to
14
+ attr :parent
17
15
 
18
- # Is this Property single-valued
19
- def single?
20
- !@multi
21
- end
16
+ # Is this Property single-valued
17
+ def single?
18
+ !@multi
19
+ end
22
20
 
23
- # Is this Property multi-valued
24
- def multi?
25
- @multi
26
- end
21
+ # Is this Property multi-valued
22
+ def multi?
23
+ @multi
24
+ end
27
25
 
28
- # Define a property by its name and type
29
- def initialize(name, type, parent, multi = false)
30
- @name, @type, @parent, @multi = name.to_s, type, parent, multi
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
@@ -1,17 +1,13 @@
1
- module SDL
2
- module Base
3
- class Service
4
- attr_accessor :facts, :symbolic_name
1
+ class SDL::Base::Service
2
+ attr_accessor :facts, :symbolic_name
5
3
 
6
- def initialize(symbolic_name)
7
- @symbolic_name = symbolic_name
4
+ def initialize(symbolic_name)
5
+ @symbolic_name = symbolic_name
8
6
 
9
- @facts, @facades = [], []
10
- end
7
+ @facts, @facades = [], []
8
+ end
11
9
 
12
- def fact_class_facts_map
13
- facts.group_by &:class
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
- require 'active_support/inflector'
2
-
3
- module SDL
4
- module Base
5
- ##
6
- # A service compendium allows the definition of service facts, types and services.
7
- class ServiceCompendium
8
- class << self
9
- def default_sdltypes
10
- @default_sdltypes ||= []
11
- end
12
- end
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
- attr :fact_classes
15
- attr :types
16
- attr :sdltype_codes
17
- attr :type_instances
18
- attr :services
17
+ def facts_definition(&facts_definitions)
18
+ self.instance_eval &facts_definitions
19
+ end
19
20
 
20
- def initialize
21
- @fact_classes, @types, @services = [], [], {}
22
- @type_instances, @sdltype_codes = {}, {}
21
+ def type_instances_definition(&type_instances_definition)
22
+ self.instance_eval &type_instances_definition
23
+ end
23
24
 
24
- register_default_types
25
- end
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
- def facts_definition(&facts_definitions)
28
- self.instance_eval &facts_definitions
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
- def type_instances_definition(&type_instances_definition)
32
- self.instance_eval &type_instances_definition
33
- end
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
- # Defines a new class of service facts
36
- def fact(sym, &fact_definition)
37
- receiver = SDL::Receivers::FactReceiver.new(sym, self)
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
- # Defines a new type and returns it
62
- def type(sym, &type_definition)
63
- receiver = SDL::Receivers::TypeReceiver.new(sym, self)
64
- receiver.instance_eval &type_definition if block_given?
65
- register_sdltype_codes(receiver.klass)
66
- register_sdltype(receiver.klass)
67
- @types << receiver.klass
68
- @type_instances[receiver.klass] = {}
69
- receiver.klass
70
- end
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
- # Defines a new service, adds all service methods, and returns it
73
- def service(sym, &service_definition)
74
- receiver = SDL::Receivers::ServiceReceiver.new(sym, self)
75
- receiver.instance_eval &service_definition if block_given?
76
- @services[sym] = receiver.service
77
- receiver.service.symbolic_name = sym.to_s
78
- receiver.service.extend ServiceMethods
79
- receiver.service
80
- end
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
- # Registers the type under its codes
84
- def register_sdltype_codes(type)
85
- type.instance_variable_get(:@codes).each do |code|
86
- @sdltype_codes[code] = type
87
- end
88
- end
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
- # Allows this compendium to be used for adding new type instances
92
- def register_sdltype(type)
93
- # Define a method, which adds the type instance defined in the block to this compendium and adds it as a
94
- # constant the the type class
95
- self.class.send(:define_method, type.local_name.underscore) do |identifier, &block|
96
- receiver = SDL::Receivers::TypeInstanceReceiver.new(type.new, self)
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
- receiver.instance_eval &block if block != nil
88
+ receiver.instance_eval &block if block != nil
99
89
 
100
- receiver.instance.identifier = identifier
101
- @type_instances[type][identifier] = receiver.instance
102
- end
103
- end
90
+ receiver.instance.identifier = identifier
91
+ @type_instances[type][identifier] = receiver.instance
92
+ end
93
+ end
104
94
 
105
- ##
106
- # Registers all classes by their #local_name to be used in all scopes
107
- def register_classes_globally
108
- (@fact_classes + @types).each do |defined_class|
109
- Object.send(:remove_const, defined_class.local_name) if Object.const_defined? defined_class.local_name.to_sym
110
- Object.const_set defined_class.local_name, defined_class
111
- end
112
- end
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
- # This module is included in every service defined by this compendium and contains methods to easily retreive
115
- # certain fact instances by their name.
116
- module ServiceMethods
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
- end
108
+ end
119
109
 
120
- private
121
- ##
122
- # Registers all default types
123
- def register_default_types
124
- self.class.default_sdltypes.each do |type|
125
- register_sdltype_codes type
126
- end
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
- require 'i18n'
2
-
3
- module SDL
4
- module Base
5
- class Type
6
- class << self
7
- ## The namespace URL of this Fact class
8
- attr_accessor :namespace
9
-
10
- ##
11
- # The local name of the type, e.g. "Name" or "ServiceInterface". Defaults to the name of the class.
12
- #
13
- # The ServiceCompendium#register_classes_globally method makes this class accessible by a constant of this name
14
- @local_name
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
- def to_s
25
- @local_name || name
26
- end
16
+ def local_name=(name)
17
+ @local_name = name
18
+ end
27
19
 
28
- def properties(including_super = false)
29
- if including_super && is_sub?
30
- self.properties + superclass.properties(true)
31
- else
32
- @properties ||= []
33
- end
34
- end
20
+ def to_s
21
+ @local_name || name
22
+ end
35
23
 
36
- def propertyless?(including_super = false)
37
- properties(including_super).count == 0
38
- end
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
- def single_property?(including_super = false)
41
- properties(including_super).count == 1
42
- end
32
+ def propertyless?(including_super = false)
33
+ properties(including_super).count == 0
34
+ end
43
35
 
44
- def multi_property?(including_super = true)
45
- properties(including_super).count > 1
46
- end
36
+ def single_property?(including_super = false)
37
+ properties(including_super).count == 1
38
+ end
47
39
 
48
- def is_sub?
49
- not [SDL::Base::Type, SDL::Base::Fact].include? superclass
50
- end
51
- end
40
+ def multi_property?(including_super = true)
41
+ properties(including_super).count > 1
42
+ end
52
43
 
53
- ##
54
- # Gets the values of all properties
55
- def property_values
56
- Hash[self.class.properties(true).map{|p| [p, send(p.name)]}]
57
- end
44
+ def is_sub?
45
+ not [SDL::Base::Type, SDL::Base::Fact].include? superclass
46
+ end
47
+ end
58
48
 
59
- def to_s
60
- # If there is a property with the same name, than the type, return its to_s, return the name of the class
61
- naming_property = self.class.properties(true).find {|p| p.name.eql?(self.class.to_s.underscore) }
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
- if(naming_property)
64
- instance_variable_get("@#{naming_property.name.to_sym}").to_s
65
- else
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
- def annotated?
71
- ! @annotations.blank?
72
- end
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
- def annotations
75
- @annotations ||= []
76
- end
66
+ def annotated?
67
+ ! @annotations.blank?
68
+ end
77
69
 
78
- # An identifier for type instances
79
- attr_accessor :identifier
80
- end
70
+ def annotations
71
+ @annotations ||= []
81
72
  end
73
+
74
+ # An identifier for type instances
75
+ attr_accessor :identifier
82
76
  end