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.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rspec +2 -0
  4. data/.yard_redcarpet_ext +1 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +13 -0
  7. data/README.md +454 -0
  8. data/Rakefile +16 -0
  9. data/bin/process_service_descriptions +102 -0
  10. data/examples/services/google_drive_for_business.service.rb +50 -0
  11. data/examples/services/salesforce_sales_cloud.service.rb +51 -0
  12. data/examples/translations/en.yml +184 -0
  13. data/examples/vocabulary/base/base.sdl.rb +8 -0
  14. data/examples/vocabulary/base/location.sdl.rb +5 -0
  15. data/examples/vocabulary/crf/characteristics.sdl.rb +25 -0
  16. data/examples/vocabulary/crf/charging.sdl.rb +8 -0
  17. data/examples/vocabulary/crf/compliance.sdl.rb +35 -0
  18. data/examples/vocabulary/crf/delivery.sdl.rb +22 -0
  19. data/examples/vocabulary/crf/dynamics.sdl.rb +6 -0
  20. data/examples/vocabulary/crf/interop.sdl.rb +54 -0
  21. data/examples/vocabulary/crf/optimizing.sdl.rb +15 -0
  22. data/examples/vocabulary/crf/portability.sdl.rb +25 -0
  23. data/examples/vocabulary/crf/protection.sdl.rb +8 -0
  24. data/examples/vocabulary/crf/reliability.sdl.rb +1 -0
  25. data/examples/vocabulary/crf/reputation.sdl.rb +3 -0
  26. data/lib/sdl.rb +17 -0
  27. data/lib/sdl/base.rb +20 -0
  28. data/lib/sdl/base/fact.rb +11 -0
  29. data/lib/sdl/base/property.rb +34 -0
  30. data/lib/sdl/base/service.rb +13 -0
  31. data/lib/sdl/base/service_compendium.rb +130 -0
  32. data/lib/sdl/base/type.rb +66 -0
  33. data/lib/sdl/exporters.rb +9 -0
  34. data/lib/sdl/exporters/exporter.rb +19 -0
  35. data/lib/sdl/exporters/markdown_service_exporter.rb +5 -0
  36. data/lib/sdl/exporters/rdf_exporter.rb +34 -0
  37. data/lib/sdl/exporters/rdf_mapping.rb +48 -0
  38. data/lib/sdl/exporters/schema_exporter.rb +9 -0
  39. data/lib/sdl/exporters/service_exporter.rb +9 -0
  40. data/lib/sdl/exporters/xml_mapping.rb +51 -0
  41. data/lib/sdl/exporters/xml_service_exporter.rb +37 -0
  42. data/lib/sdl/exporters/xsd_schema_exporter.rb +94 -0
  43. data/lib/sdl/receivers.rb +22 -0
  44. data/lib/sdl/receivers/fact_receiver.rb +15 -0
  45. data/lib/sdl/receivers/service_receiver.rb +63 -0
  46. data/lib/sdl/receivers/type_instance_receiver.rb +86 -0
  47. data/lib/sdl/receivers/type_receiver.rb +87 -0
  48. data/lib/sdl/translations/en.yml +9 -0
  49. data/lib/sdl/types.rb +19 -0
  50. data/lib/sdl/types/sdl_datetime.rb +10 -0
  51. data/lib/sdl/types/sdl_default_type.rb +13 -0
  52. data/lib/sdl/types/sdl_description.rb +10 -0
  53. data/lib/sdl/types/sdl_duration.rb +12 -0
  54. data/lib/sdl/types/sdl_number.rb +10 -0
  55. data/lib/sdl/types/sdl_string.rb +10 -0
  56. data/lib/sdl/types/sdl_type.rb +31 -0
  57. data/lib/sdl/types/sdl_url.rb +12 -0
  58. data/lib/sdl/util.rb +4 -0
  59. data/lib/sdl/util/documentation.rb +80 -0
  60. data/lib/sdl/util/nokogiri.rb +28 -0
  61. data/lib/sdl/util/verbs.rb +3 -0
  62. data/lib/sdl/version.rb +3 -0
  63. data/sdl-ng.gemspec +34 -0
  64. data/spec/documentation_spec.rb +64 -0
  65. data/spec/fact_type_instance_definition_spec.rb +188 -0
  66. data/spec/property_definitions_spec.rb +44 -0
  67. data/spec/service_compendium_spec.rb +90 -0
  68. data/spec/service_definition_spec.rb +81 -0
  69. data/spec/shared_test_compendium.rb +65 -0
  70. data/spec/spec_helper.rb +10 -0
  71. metadata +291 -0
@@ -0,0 +1,188 @@
1
+ require_relative '../lib/sdl'
2
+ require_relative 'spec_helper'
3
+ require_relative 'shared_test_compendium'
4
+
5
+ require 'rspec'
6
+
7
+ shared_examples_for 'it can use identifiers for predefined types' do
8
+ it 'can set facts' do
9
+ eval "compendium.service :red_service do
10
+ has_color #{red_identifier}, 'Ruby Red'
11
+ end"
12
+
13
+ expect(compendium.services[:red_service].facts[0].color).to eq(compendium.type_instances[Color][:red])
14
+ expect(compendium.services[:red_service].facts[0].name).to eq("Ruby Red")
15
+ end
16
+
17
+ it 'lets service definitions use symbolic names also in lists' do
18
+ eval "compendium.service :multicolored_service do
19
+ has_multicolor do
20
+ color #{red_identifier}
21
+ color #{green_identifier}
22
+ end
23
+ end"
24
+
25
+ expect(compendium.services[:multicolored_service].facts[0].colors[0]).to eq(compendium.type_instances[Color][:red])
26
+ expect(compendium.services[:multicolored_service].facts[0].colors[1]).to eq(compendium.type_instances[Color][:green])
27
+ end
28
+ end
29
+
30
+ describe 'Doing type instance definition' do
31
+ include_context 'the default compendium'
32
+
33
+ # Registers the classes of the default compendium
34
+ before(:each) do
35
+ compendium.register_classes_globally
36
+ end
37
+
38
+ context 'With identifiers as symbolic names' do
39
+ it_should_behave_like 'it can use identifiers for predefined types' do
40
+ let :red_identifier do
41
+ ':red'
42
+ end
43
+
44
+ let :green_identifier do
45
+ ':green'
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'With identifiers as regular names (i.e. method calls)' do
51
+ it_should_behave_like 'it can use identifiers for predefined types' do
52
+ let :red_identifier do
53
+ 'red'
54
+ end
55
+
56
+ let :green_identifier do
57
+ 'green'
58
+ end
59
+ end
60
+ end
61
+
62
+ it 'raises errors if it detects non existing names or symbols' do
63
+ expect {compendium.service :invalid_service do
64
+ has_multicolor do
65
+ color :the_colour_of_magic
66
+ end
67
+ end}.to raise_exception
68
+
69
+ expect do
70
+ compendium.service :second_invalid_service do
71
+ has_color :the_colour_of_magic
72
+ end
73
+ end.to raise_exception
74
+
75
+ expect {compendium.service :invalid_service do
76
+ has_multicolor do
77
+ color the_colour_of_magic
78
+ end
79
+ end}.to raise_exception
80
+
81
+ expect do
82
+ compendium.service :second_invalid_service do
83
+ has_color the_colour_of_magic
84
+ end
85
+ end.to raise_exception
86
+ end
87
+
88
+ it 'raises an error, if multiple predefined type instances with the same name are found by #method_missing' do
89
+ expect do
90
+ compendium.service :service_with_ambiguous_reference do
91
+ color text
92
+ end
93
+ end.to raise_exception
94
+ end
95
+
96
+ it 'can be done through multiple arguments and associative hashes' do
97
+ compendium.facts_definition do
98
+ type :multi do
99
+ string :a
100
+ string :b
101
+ string :c
102
+ string :d
103
+ string :e
104
+ end
105
+
106
+ fact :multi do
107
+ string :a
108
+ string :b
109
+ string :c
110
+ string :d
111
+ string :e
112
+ end
113
+
114
+ fact :multi_multi do
115
+ list_of_multis :multis
116
+ end
117
+ end
118
+
119
+ compendium.service :multi_service do
120
+ multi '1', '2', d: '3'
121
+
122
+ multi_multi do
123
+ multi '1', '2', d: '3'
124
+ multi '3', '4', e: '5'
125
+ end
126
+ end
127
+
128
+ expect(compendium.services[:multi_service].facts[0].a).to eql '1'
129
+ expect(compendium.services[:multi_service].facts[0].b).to eql '2'
130
+ expect(compendium.services[:multi_service].facts[0].c).to eq(nil)
131
+ expect(compendium.services[:multi_service].facts[0].d).to eql '3'
132
+ expect(compendium.services[:multi_service].facts[0].e).to eq(nil)
133
+
134
+ expect(compendium.services[:multi_service].facts[1].multis[0].b).to eql '2'
135
+ expect(compendium.services[:multi_service].facts[1].multis[1].e).to eql '5'
136
+ end
137
+
138
+ context 'the #to_s method of a service' do
139
+ it 'gives out the #to_s output of a same-named property than the class' do
140
+ compendium.service :named_color_service do
141
+ has_named_color 'My color name'
142
+ end
143
+
144
+ expect(compendium.services[:named_color_service].facts[0].to_s).to eq('My color name')
145
+ end
146
+
147
+ it 'gives out the Fact class local name when no same-named property than the class exists' do
148
+ compendium.service :blue_service do
149
+ has_color :blue
150
+ end
151
+
152
+ expect(compendium.services[:blue_service].facts[0].to_s).to eq('Color')
153
+ end
154
+ end
155
+
156
+ it 'lets facts be annotated by arbitrary values' do
157
+ compendium.service :yellow_service do
158
+ has_color :yellow, annotation: "Yuck!"
159
+ end
160
+
161
+ expect(compendium.services[:yellow_service].facts[0].annotations).to include("Yuck!")
162
+ end
163
+
164
+ it 'lets fact have list types' do
165
+ compendium.service :favourite_service do
166
+ favourite_colors do
167
+ favourite :red, 5
168
+ favourite :green, 10
169
+ end
170
+ end
171
+
172
+ expect(compendium.services[:favourite_service].facts[0].favourites[0].color).to eq(compendium.type_instances[Color][:red])
173
+ expect(compendium.services[:favourite_service].facts[0].favourites[1].color).to eq(compendium.type_instances[Color][:green])
174
+ expect(compendium.services[:favourite_service].facts[0].favourites[0].rating).to eq(5)
175
+ expect(compendium.services[:favourite_service].facts[0].favourites[1].rating).to eq(10)
176
+ end
177
+
178
+ it 'returns the values of all properties by calling #property_values on a type' do
179
+ compendium.service :imaginative_service do
180
+ has_color :yellow, 'Yellow'
181
+ end
182
+
183
+ property_values = compendium.services[:imaginative_service].facts[0].property_values
184
+
185
+ expect(property_values[property_values.keys[0]]).to eq(compendium.type_instances[Color][:yellow])
186
+ expect(property_values[property_values.keys[1]]).to eq('Yellow')
187
+ end
188
+ end
@@ -0,0 +1,44 @@
1
+ require_relative '../lib/sdl'
2
+ require_relative 'spec_helper'
3
+
4
+ require 'rspec'
5
+
6
+ describe 'The definition of properties' do
7
+ subject do
8
+ SDL::Receivers::TypeReceiver.new :my_example_type, SDL::Base::ServiceCompendium.new
9
+ end
10
+
11
+ it 'allows the definition of properties' do
12
+ subject.string :my_string_property
13
+
14
+ defined_property = subject.klass.properties.first
15
+
16
+ expect(defined_property.name).to eq "my_string_property"
17
+ expect(defined_property.type).to be SDL::Types::SDLString
18
+ expect(defined_property.multi).to be_false
19
+ end
20
+
21
+ it 'allows the definition of properties, omitting the name if it should be the same as the type' do
22
+ subject.url
23
+
24
+ defined_property = subject.klass.properties.first
25
+
26
+ expect(defined_property.name).to eq 'url'
27
+ expect(defined_property.type).to be SDL::Types::SDLUrl
28
+ expect(defined_property.multi).to be_false
29
+ end
30
+
31
+ it 'allows the definition of list properties' do
32
+ subject.list_of_integers :my_integer_list
33
+
34
+ defined_property = subject.klass.properties.first
35
+
36
+ expect(defined_property.name).to eq("my_integer_list")
37
+ expect(defined_property.type).to be SDL::Types::SDLNumber
38
+ expect(defined_property.multi?).to be_true
39
+ end
40
+
41
+ it 'does not handle unknown types' do
42
+ expect {subject.unknown_type}.to raise_exception
43
+ end
44
+ end
@@ -0,0 +1,90 @@
1
+ require_relative '../lib/sdl'
2
+ require_relative 'spec_helper'
3
+
4
+ require 'rspec'
5
+
6
+ describe 'The service compendium' do
7
+ subject do
8
+ SDL::Base::ServiceCompendium.new
9
+ end
10
+
11
+ it 'has empty arrays' do
12
+ %w[fact_classes types type_instances services].each do |list|
13
+ expect(subject.send(list)).to be_empty
14
+ end
15
+ end
16
+
17
+ it 'allows the definition of service fact classes' do
18
+ subject.fact :has_example_fact
19
+
20
+ expect(subject.fact_classes.first).to be < SDL::Base::Fact
21
+ end
22
+
23
+ it 'allows the definition of fact subclasses' do
24
+ subject.fact :example_fact do
25
+ subfact :example_subfact
26
+ end
27
+
28
+ expect(subject.fact_classes.last.superclass).to be subject.fact_classes.first
29
+ end
30
+
31
+ it 'allows the definition of service types' do
32
+ subject.type :example_type
33
+
34
+ expect(subject.types.first).to be < SDL::Base::Type
35
+ end
36
+
37
+ it 'allows the definition of services' do
38
+ subject.service :example_service
39
+
40
+ expect(subject.services[:example_service]).to be_a(SDL::Base::Service)
41
+ expect(subject.services[:example_service]).to eq(subject.services.first[1])
42
+ end
43
+
44
+ it 'can register defined classes globally' do
45
+ subject.fact :example_fact
46
+ subject.type :example_type
47
+
48
+ subject.register_classes_globally
49
+
50
+ expect(Kernel.const_get('ExampleFact')).to be < SDL::Base::Fact
51
+ expect(Kernel.const_get('ExampleType')).to be < SDL::Base::Type
52
+ end
53
+
54
+ it 'has a #facts_definition shortcut' do
55
+ subject.facts_definition do
56
+ CONTEXT_SELF = self
57
+ end
58
+
59
+ expect(subject).to be CONTEXT_SELF
60
+ end
61
+
62
+ context 'with defined example classes' do
63
+ subject do
64
+ compendium = SDL::Base::ServiceCompendium.new
65
+ compendium.fact :example_fact
66
+ compendium.register_classes_globally
67
+ compendium
68
+ end
69
+
70
+ it 'allows to use these facts in the definition of services' do
71
+ subject.service :example_service do
72
+ has_example_fact
73
+ end
74
+
75
+ expect(subject.services[:example_service].facts.first).to be_an(ExampleFact)
76
+ end
77
+ end
78
+
79
+ context 'with a new service type' do
80
+ subject do
81
+ compendium = SDL::Base::ServiceCompendium.new
82
+ compendium.type :example_type
83
+ compendium
84
+ end
85
+
86
+ it 'registers the code for the example type with its #sdltype_codes' do
87
+ expect(subject.sdltype_codes[:example_type]).to be subject.types.first
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,81 @@
1
+ require_relative '../lib/sdl'
2
+ require_relative 'spec_helper'
3
+
4
+ require 'rspec'
5
+
6
+ describe 'The definition of services' do
7
+ let! :example_compendium do
8
+ compendium = SDL::Base::ServiceCompendium.new
9
+
10
+ compendium.facts_definition do
11
+ fact :fact
12
+
13
+ fact :my_value do
14
+ string :my_value
15
+
16
+ subfact :my_inherited_value
17
+ end
18
+ end
19
+
20
+ compendium
21
+ end
22
+
23
+ context 'the addition of a Fact instance' do
24
+ after(:all) do
25
+ example_service = example_compendium.services[:example_service]
26
+ example_fact_instance = example_service.facts.first
27
+
28
+ expect(example_fact_instance).to be_a(example_compendium.fact_classes.first)
29
+ end
30
+
31
+ it 'allows the addition of a Fact instance using has_{Fact class name} syntax' do
32
+ example_compendium.service(:example_service) do
33
+ has_fact
34
+ end
35
+ end
36
+
37
+ it 'allows the addition of a Fact instance using {Fact class name} syntax' do
38
+ example_compendium.service(:example_service) do
39
+ fact
40
+ end
41
+ end
42
+
43
+ it 'allows the addition of a Fact instance using is_{Fact class name past participle} syntax' do
44
+ example_compendium.service(:example_service) do
45
+ is_facted
46
+ end
47
+ end
48
+ end
49
+
50
+ it 'allows to set a property value of a Fact instance, when both the property and the instance class have the same name' do
51
+ compendium = example_compendium
52
+
53
+ compendium.service(:example_service) do
54
+ my_value "ABC"
55
+ my_inherited_value "BCD"
56
+ end
57
+
58
+ example_service = compendium.services[:example_service]
59
+ my_inherited_value_fact = example_service.facts.last
60
+
61
+ expect(my_inherited_value_fact).to be_a(compendium.fact_classes.last)
62
+
63
+ expect(my_inherited_value_fact.my_value).to eq("BCD")
64
+ end
65
+
66
+ it 'raises an error, if a value is given for a non-existing property' do
67
+ expect do
68
+ example_compendium.service(:example_service) do
69
+ my_value "ABC", "DEF"
70
+ end
71
+ end.to raise_exception
72
+ end
73
+
74
+ it 'allows to access the first fact instance by its name' do
75
+ service = example_compendium.service(:my_service) do
76
+ my_value "ABC"
77
+ end
78
+
79
+ expect(service.my_value.my_value).to eq "ABC"
80
+ end
81
+ end
@@ -0,0 +1,65 @@
1
+ require 'rspec'
2
+
3
+ shared_context 'the default compendium' do
4
+ let :compendium do
5
+ compendium = SDL::Base::ServiceCompendium.new
6
+
7
+ compendium.facts_definition do
8
+ type :color do
9
+ string :hex_value
10
+ end
11
+
12
+ type :something_other do
13
+ string :some_text
14
+ end
15
+
16
+ fact :color do
17
+ color :color
18
+ string :name
19
+
20
+ subfact :supercolor do
21
+ string :superpower
22
+ end
23
+ end
24
+
25
+ fact :multicolor do
26
+ list_of_colors :colors
27
+ end
28
+
29
+ fact :favourite_colors do
30
+ list :favourites do
31
+ color :color
32
+ int :rating
33
+ end
34
+ end
35
+ end
36
+
37
+ compendium.type_instances_definition do
38
+ color :red do
39
+ hex_value '#F00'
40
+ end
41
+
42
+ color :green do
43
+ hex_value '#0F0'
44
+ end
45
+
46
+ color :blue do
47
+ hex_value '#00F'
48
+ end
49
+
50
+ color :yellow do
51
+ hex_value '#FF0'
52
+ end
53
+
54
+ color :text do
55
+ hex_value '#000'
56
+ end
57
+
58
+ something_other :text do
59
+ some_text 'This is some text'
60
+ end
61
+ end
62
+
63
+ compendium
64
+ end
65
+ end