sdl-ng 0.0.1
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 +7 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.yard_redcarpet_ext +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +454 -0
- data/Rakefile +16 -0
- data/bin/process_service_descriptions +102 -0
- data/examples/services/google_drive_for_business.service.rb +50 -0
- data/examples/services/salesforce_sales_cloud.service.rb +51 -0
- data/examples/translations/en.yml +184 -0
- data/examples/vocabulary/base/base.sdl.rb +8 -0
- data/examples/vocabulary/base/location.sdl.rb +5 -0
- data/examples/vocabulary/crf/characteristics.sdl.rb +25 -0
- data/examples/vocabulary/crf/charging.sdl.rb +8 -0
- data/examples/vocabulary/crf/compliance.sdl.rb +35 -0
- data/examples/vocabulary/crf/delivery.sdl.rb +22 -0
- data/examples/vocabulary/crf/dynamics.sdl.rb +6 -0
- data/examples/vocabulary/crf/interop.sdl.rb +54 -0
- data/examples/vocabulary/crf/optimizing.sdl.rb +15 -0
- data/examples/vocabulary/crf/portability.sdl.rb +25 -0
- data/examples/vocabulary/crf/protection.sdl.rb +8 -0
- data/examples/vocabulary/crf/reliability.sdl.rb +1 -0
- data/examples/vocabulary/crf/reputation.sdl.rb +3 -0
- data/lib/sdl.rb +17 -0
- data/lib/sdl/base.rb +20 -0
- data/lib/sdl/base/fact.rb +11 -0
- data/lib/sdl/base/property.rb +34 -0
- data/lib/sdl/base/service.rb +13 -0
- data/lib/sdl/base/service_compendium.rb +130 -0
- data/lib/sdl/base/type.rb +66 -0
- data/lib/sdl/exporters.rb +9 -0
- data/lib/sdl/exporters/exporter.rb +19 -0
- data/lib/sdl/exporters/markdown_service_exporter.rb +5 -0
- data/lib/sdl/exporters/rdf_exporter.rb +34 -0
- data/lib/sdl/exporters/rdf_mapping.rb +48 -0
- data/lib/sdl/exporters/schema_exporter.rb +9 -0
- data/lib/sdl/exporters/service_exporter.rb +9 -0
- data/lib/sdl/exporters/xml_mapping.rb +51 -0
- data/lib/sdl/exporters/xml_service_exporter.rb +37 -0
- data/lib/sdl/exporters/xsd_schema_exporter.rb +94 -0
- data/lib/sdl/receivers.rb +22 -0
- data/lib/sdl/receivers/fact_receiver.rb +15 -0
- data/lib/sdl/receivers/service_receiver.rb +63 -0
- data/lib/sdl/receivers/type_instance_receiver.rb +86 -0
- data/lib/sdl/receivers/type_receiver.rb +87 -0
- data/lib/sdl/translations/en.yml +9 -0
- data/lib/sdl/types.rb +19 -0
- data/lib/sdl/types/sdl_datetime.rb +10 -0
- data/lib/sdl/types/sdl_default_type.rb +13 -0
- data/lib/sdl/types/sdl_description.rb +10 -0
- data/lib/sdl/types/sdl_duration.rb +12 -0
- data/lib/sdl/types/sdl_number.rb +10 -0
- data/lib/sdl/types/sdl_string.rb +10 -0
- data/lib/sdl/types/sdl_type.rb +31 -0
- data/lib/sdl/types/sdl_url.rb +12 -0
- data/lib/sdl/util.rb +4 -0
- data/lib/sdl/util/documentation.rb +80 -0
- data/lib/sdl/util/nokogiri.rb +28 -0
- data/lib/sdl/util/verbs.rb +3 -0
- data/lib/sdl/version.rb +3 -0
- data/sdl-ng.gemspec +34 -0
- data/spec/documentation_spec.rb +64 -0
- data/spec/fact_type_instance_definition_spec.rb +188 -0
- data/spec/property_definitions_spec.rb +44 -0
- data/spec/service_compendium_spec.rb +90 -0
- data/spec/service_definition_spec.rb +81 -0
- data/spec/shared_test_compendium.rb +65 -0
- data/spec/spec_helper.rb +10 -0
- metadata +291 -0
@@ -0,0 +1,87 @@
|
|
1
|
+
module SDL
|
2
|
+
module Receivers
|
3
|
+
class TypeReceiver
|
4
|
+
include ActiveSupport::Inflector
|
5
|
+
|
6
|
+
attr :klass
|
7
|
+
attr :subclasses
|
8
|
+
attr :compendium
|
9
|
+
|
10
|
+
def initialize(sym, compendium, superklass = nil)
|
11
|
+
@compendium = compendium
|
12
|
+
@klass = Class.new(superklass || base_class)
|
13
|
+
@klass.local_name = sym.to_s.camelize
|
14
|
+
|
15
|
+
@subclasses = [@klass]
|
16
|
+
|
17
|
+
register_sdltype(@klass)
|
18
|
+
end
|
19
|
+
|
20
|
+
def base_class
|
21
|
+
SDL::Base::Type
|
22
|
+
end
|
23
|
+
|
24
|
+
def register_sdltype(klass)
|
25
|
+
klass.class_eval do
|
26
|
+
include SDL::Types::SDLType
|
27
|
+
|
28
|
+
wraps self
|
29
|
+
codes local_name.underscore.to_sym
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def subtype(sym, &definition)
|
34
|
+
receiver = self.class.new(sym, @compendium, @klass)
|
35
|
+
receiver.instance_eval(&definition) if block_given?
|
36
|
+
|
37
|
+
@subclasses.concat(receiver.subclasses)
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Define a list of a type, which is defined in the block.
|
42
|
+
def list(name, &block)
|
43
|
+
list_type = @compendium.type name.to_s.singularize.to_sym, &block
|
44
|
+
|
45
|
+
add_property name.to_sym, list_type, true
|
46
|
+
end
|
47
|
+
|
48
|
+
def method_missing(name, *args, &block)
|
49
|
+
sym = args[0] || name.to_sym
|
50
|
+
|
51
|
+
if name =~ /list_of_/
|
52
|
+
multi = true
|
53
|
+
type = @compendium.sdltype_codes[name.to_s.gsub('list_of_', '').singularize.to_sym]
|
54
|
+
else
|
55
|
+
multi = false
|
56
|
+
type = @compendium.sdltype_codes[name.to_sym]
|
57
|
+
end
|
58
|
+
|
59
|
+
if type
|
60
|
+
add_property sym, type, multi
|
61
|
+
else
|
62
|
+
super(name, *args, &block)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
##
|
68
|
+
# Adds accessors to set the property to the target class.
|
69
|
+
def add_property(sym, type, multi)
|
70
|
+
unless multi
|
71
|
+
@klass.class_eval do
|
72
|
+
attr_accessor sym
|
73
|
+
end
|
74
|
+
else
|
75
|
+
# Define accessor method for lists
|
76
|
+
@klass.class_eval do
|
77
|
+
define_method sym do
|
78
|
+
eval "@#{sym} ||= []"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
@klass.properties << SDL::Base::Property.new(sym, type, @klass, multi)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
---
|
2
|
+
en:
|
3
|
+
sdl:
|
4
|
+
xml:
|
5
|
+
annotation: An arbitrary annotation to be displayed for the description consumer.
|
6
|
+
documentation: The documentation of this type or fact instance.
|
7
|
+
identifier: An identifier for a type instance. Two instances are the same, if they share the same identifier.
|
8
|
+
service_root: The root element of the service. Contains an arbitrary number of facts.
|
9
|
+
typebase: The base type of all SDL types and facts. Contains annotations and documentation.
|
data/lib/sdl/types.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'types/sdl_type'
|
2
|
+
require_relative 'types/sdl_default_type'
|
3
|
+
require_relative 'types/sdl_string'
|
4
|
+
require_relative 'types/sdl_description'
|
5
|
+
require_relative 'types/sdl_number'
|
6
|
+
require_relative 'types/sdl_duration'
|
7
|
+
require_relative 'types/sdl_url'
|
8
|
+
require_relative 'types/sdl_datetime'
|
9
|
+
|
10
|
+
module SDL
|
11
|
+
##
|
12
|
+
# This module contains the SDL type system.
|
13
|
+
#
|
14
|
+
# An SDL type is a wrapper around a Ruby type and is used in two contexts:
|
15
|
+
# * When setting a property, its new value is checked for type compatibility to the wrapped Ruby class
|
16
|
+
# * When exporting a service description, the wrapper is used to determine the serialization format
|
17
|
+
module Types
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SDL
|
2
|
+
module Types
|
3
|
+
class SDLDefaultType
|
4
|
+
include SDLType
|
5
|
+
|
6
|
+
##
|
7
|
+
# Designates this SDLType to be a default type, i.e., to be loaded by all ServiceCompendiums automatically
|
8
|
+
def self.inherited(subclass)
|
9
|
+
SDL::Base::ServiceCompendium.default_sdltypes << subclass
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module SDL
|
2
|
+
module Types
|
3
|
+
##
|
4
|
+
# An SDLType is a wrapper around a basic Ruby type
|
5
|
+
module SDLType
|
6
|
+
def self.included(base)
|
7
|
+
base.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
## The Ruby type, which is to be wrapped
|
12
|
+
attr :wrapped_type
|
13
|
+
|
14
|
+
## The codes, which are to be used to refer to this type
|
15
|
+
attr :codes
|
16
|
+
|
17
|
+
##
|
18
|
+
# Sets the wrapped Ruby type
|
19
|
+
def wraps(type)
|
20
|
+
@wrapped_type = type
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Registers the codes +symbols+ to be used to refer to this type
|
25
|
+
def codes(*symbols)
|
26
|
+
@codes = symbols
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/sdl/util.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
3
|
+
module I18n
|
4
|
+
class MissingTranslation
|
5
|
+
module Base
|
6
|
+
alias :old_message :message
|
7
|
+
|
8
|
+
def message
|
9
|
+
puts old_message
|
10
|
+
|
11
|
+
puts @key
|
12
|
+
|
13
|
+
I18n.backend.store_translations I18n.locale, to_deep_hash({@key => 'Translate'})
|
14
|
+
|
15
|
+
old_message
|
16
|
+
end
|
17
|
+
|
18
|
+
# Taken from: http://www.ruby-doc.org/gems/docs/t/translate-rails3-0.2.2/Translate/Keys.html
|
19
|
+
def to_deep_hash(hash)
|
20
|
+
hash.inject({}) do |deep_hash, (key, value)|
|
21
|
+
keys = key.to_s.split('.').reverse
|
22
|
+
leaf_key = keys.shift
|
23
|
+
key_hash = keys.inject({leaf_key.to_sym => value}) { |hash, key| {key.to_sym => hash} }
|
24
|
+
deep_hash.deep_merge!(key_hash)
|
25
|
+
deep_hash
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module SDL
|
33
|
+
module Util
|
34
|
+
module Documentation
|
35
|
+
def self.included(base)
|
36
|
+
base.extend(self)
|
37
|
+
end
|
38
|
+
|
39
|
+
def documentation
|
40
|
+
if self.respond_to?(:documentation_key)
|
41
|
+
I18n.t(documentation_key)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.walk_the_class_name(klass)
|
46
|
+
klass_key = klass.local_name.underscore.downcase
|
47
|
+
|
48
|
+
if klass.superclass.eql?(SDL::Base::Fact) || klass.superclass.eql?(SDL::Base::Type)
|
49
|
+
klass_key = "#{klass.superclass.local_name.underscore.downcase}.#{klass_key}"
|
50
|
+
else
|
51
|
+
klass_key = "#{walk_the_class_name(klass.superclass)}_#{klass_key}"
|
52
|
+
end
|
53
|
+
|
54
|
+
klass_key
|
55
|
+
end
|
56
|
+
|
57
|
+
[SDL::Base::Type, SDL::Base::Fact, SDL::Base::Property].each do |m| m.class_eval do include SDL::Util::Documentation end end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
module SDL
|
63
|
+
module Base
|
64
|
+
class Type
|
65
|
+
def self.documentation_key
|
66
|
+
"sdl.#{SDL::Util::Documentation.walk_the_class_name(self)}"
|
67
|
+
end
|
68
|
+
|
69
|
+
def documentation_key
|
70
|
+
"sdl.instance.#{SDL::Util::Documentation.walk_the_class_name(self.class)}.#{@identifier}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class Property
|
75
|
+
def documentation_key
|
76
|
+
"sdl.property.#{SDL::Util::Documentation.walk_the_class_name(@parent)}.#{@name}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module SDL
|
5
|
+
module Util
|
6
|
+
module NokogiriUtils
|
7
|
+
def fetch_from_url(url, *search)
|
8
|
+
begin
|
9
|
+
doc = Nokogiri::HTML(open(url))
|
10
|
+
|
11
|
+
doc.search(*search)
|
12
|
+
rescue SocketError => e
|
13
|
+
[]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module SDL
|
21
|
+
module Receivers
|
22
|
+
[FactReceiver, ServiceReceiver, TypeInstanceReceiver, TypeReceiver].each do |r|
|
23
|
+
r.class_eval do
|
24
|
+
include(SDL::Util::NokogiriUtils)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/sdl/version.rb
ADDED
data/sdl-ng.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
|
+
$:.unshift(lib) unless $:.include?(lib)
|
4
|
+
require 'sdl/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sdl-ng"
|
8
|
+
spec.version = SDL::VERSION
|
9
|
+
spec.authors = ["Mathias Slawik"]
|
10
|
+
spec.email = ["mathias.slawik@tu-berlin.de"]
|
11
|
+
spec.description = %q{Next Generation Service Description Language}
|
12
|
+
spec.summary = %q{Framework for building descriptions of business services.}
|
13
|
+
spec.homepage = 'https://github.com/TU-Berlin-SNET/sdl-ng'
|
14
|
+
spec.license = 'Apache-2.0'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'activesupport', '>=4.0.0'
|
22
|
+
spec.add_runtime_dependency 'nokogiri', '1.6.0'
|
23
|
+
spec.add_runtime_dependency 'verbs', '~> 2.1.3'
|
24
|
+
spec.add_runtime_dependency 'linkeddata', '1.0.9'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'yard'
|
27
|
+
spec.add_development_dependency 'yard-redcarpet-ext'
|
28
|
+
spec.add_development_dependency 'redcarpet'
|
29
|
+
spec.add_development_dependency 'rspec', '2.14.1'
|
30
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
31
|
+
spec.add_development_dependency 'rake'
|
32
|
+
spec.add_development_dependency 'fuubar'
|
33
|
+
spec.add_development_dependency 'simplecov', '~> 0.8.0.pre'
|
34
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require_relative '../lib/sdl'
|
2
|
+
require_relative 'spec_helper'
|
3
|
+
require_relative 'shared_test_compendium'
|
4
|
+
|
5
|
+
require 'rspec'
|
6
|
+
|
7
|
+
describe 'Documentation of SDL objects' do
|
8
|
+
include_context 'the default compendium'
|
9
|
+
|
10
|
+
I18n.backend.store_translations('en', :sdl => {
|
11
|
+
:type => {
|
12
|
+
:color => 'A color'
|
13
|
+
},
|
14
|
+
:fact => {
|
15
|
+
:multicolor => 'The service is multi-colored.',
|
16
|
+
:color_supercolor => 'The service has a supercolor.'
|
17
|
+
},
|
18
|
+
:property => {
|
19
|
+
:fact => {
|
20
|
+
:favourite_colors => {
|
21
|
+
:favourites => 'The favourite colors'
|
22
|
+
}
|
23
|
+
}
|
24
|
+
},
|
25
|
+
:instance => {
|
26
|
+
:type => {
|
27
|
+
:color => {
|
28
|
+
:red => 'The color "red"'
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
})
|
33
|
+
|
34
|
+
# Registers the classes of the default compendium
|
35
|
+
before(:each) do
|
36
|
+
compendium.register_classes_globally
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'can document types' do
|
40
|
+
expect(Color.documentation).to eq('A color')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'can document facts' do
|
44
|
+
expect(Multicolor.documentation).to eq('The service is multi-colored.')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'can document subfacts' do
|
48
|
+
expect(Supercolor.documentation).to eq('The service has a supercolor.')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'can document properties' do
|
52
|
+
expect(FavouriteColors.properties.first.documentation).to eq('The favourite colors')
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'can document instances' do
|
56
|
+
expect(compendium.type_instances[Color][:red].documentation).to eq('The color "red"')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'adds missing translations to the I18n backend as "translate" string after trying to translate a missing key' do
|
60
|
+
expect(compendium.type_instances[Color][:green].documentation).to eq('translation missing: en.sdl.instance.type.color.green')
|
61
|
+
|
62
|
+
expect(I18n.backend.instance_variable_get(:@translations)[:en][:sdl][:instance][:type][:color][:green]).to eq('Translate')
|
63
|
+
end
|
64
|
+
end
|