sdl-ng 0.0.3 → 0.0.4

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: c497f1c651686544ac76c0bef8a35a7985d06890
4
- data.tar.gz: afed6c73a2b9b35c1a99dbdf1a6dc72c1e49a87b
3
+ metadata.gz: ed2ffb4ec0dbbbcb9215c77af53ea65ff29697f4
4
+ data.tar.gz: 123f3cf6588274e6605708bc2fc27c71004702c4
5
5
  SHA512:
6
- metadata.gz: e4e00d32bc7abf06443de8d8963388ad508972ed3fa3154ce74c5a183e1bd0b47d8fb9e484219d1b53d3522d88602a7127c0ec9f6a7aa4ff6804a87cf792d8b7
7
- data.tar.gz: 29fe5546a275bc0be41b44094004cccfe95006907d6de86e0a07378089a5af7e0f0d618e335163780e6a189f5a37e0fd51153be3224c6feb58085e964280eb40
6
+ metadata.gz: e13f8fb585f8339390a6f82d339ce0daf8b3057467aa67ead071905af9bc125802746b8a984b10198b918cecc57b90e45f07f11099606e2dfd175289a87c0246
7
+ data.tar.gz: acc087d16fbf6ceb3380e80b6f118d24270c31beb2a0d1a7f757f087e32e07e4c637d3c4da562926d57944fc8daa9f7ec65b7ee3e998503a248a8352e93e96bd
@@ -2,11 +2,11 @@
2
2
  en:
3
3
  sdl:
4
4
  fact:
5
- add_on_repository: The service has an add-on repository.
6
- audit_option: The service has an audit option
7
- bill: The service billing terms.
8
- charge_unit: The unit of service charging, e.g. "per user".
9
- cloud_service_model: The cloud service model
5
+ add_on_repository: Service add-on repo
6
+ audit_option: Audit option
7
+ bill: Billing terms
8
+ charge_unit: Charge unit
9
+ cloud_service_model: Cloud service model
10
10
  communication_protection: The communication with the service is protected
11
11
  continuous_service_improvement: The service has continuous service improvement
12
12
  means
@@ -101,54 +101,54 @@ en:
101
101
  property:
102
102
  fact:
103
103
  add_on_repository:
104
- number_of_add_ons: The number of available add-ons
105
- url: The URL of the add-on repository
104
+ number_of_add_ons: Number of add-ons
105
+ url: Repository URL
106
106
  audit_option:
107
- audit_option: The audit option
107
+ audit_option: Audit option
108
108
  bill:
109
- billing_term: The billing terms
110
- payment_term: The payment terms
109
+ billing_term: Billing terms
110
+ payment_term: Payment terms
111
111
  charge_unit:
112
- charge_unit: The unit of charge
112
+ charge_unit: Charge unit
113
113
  cloud_service_model:
114
- cloud_service_model: The cloud service model
114
+ cloud_service_model: Cloud service model
115
115
  communication_protection:
116
- communication_protection: The protection means
116
+ communication_protection: Protection means
117
117
  continuous_service_improvement:
118
- url: A link to the continuous service improvement
118
+ url: Link
119
119
  data_capability:
120
- format: The data format
121
- operation: The operation, which can be carried out on the data format
120
+ format: Format
121
+ operation: Operation
122
122
  data_encryption:
123
- key_control: Who excercises control over the encryption keys
123
+ key_control: Controlling party
124
124
  data_location:
125
- location: The location of data
125
+ location: Data location
126
126
  documentation:
127
- url: The documentation URL
127
+ url: Documentation URL
128
128
  duration:
129
- duration: The duration
129
+ duration: Duration
130
130
  establishing_year:
131
- year: The year, the service was established
131
+ year: Established in
132
132
  feature:
133
- description: The feature description
134
- feature: The feature name
133
+ description: Description
134
+ feature: Name
135
135
  interface_browser_interface:
136
- compatible_browsers: The compatible browsers
137
- required_plugins: The required browser plugins
136
+ compatible_browsers: Compatible to
137
+ required_plugins: Required plugins
138
138
  maintenance_maintenance_window:
139
- timespan: The timespan of the maintenance window
139
+ timespan: Maintenance Window
140
140
  name:
141
- name: The service name
141
+ name: Service name
142
142
  payment_option:
143
- payment_option: The payment option
143
+ payment_option: Payment option
144
144
  service_category:
145
- service_category: The category of the service
145
+ service_category: Service category
146
146
  service_level_agreement_public_service_level_agreement:
147
- url: The URL of the service level agreement
147
+ url: SLA URL
148
148
  service_tag:
149
- service_tag: The service tag
149
+ service_tag: Tag
150
150
  status_page:
151
- url: The URL of the service status page
151
+ url: Service status URL
152
152
  type:
153
153
  browser:
154
154
  browser_name: The name of the browser
@@ -8,6 +8,10 @@ module SDL
8
8
 
9
9
  @facts, @facades = [], []
10
10
  end
11
+
12
+ def fact_class_facts_map
13
+ facts.group_by &:class
14
+ end
11
15
  end
12
16
  end
13
17
  end
data/lib/sdl/base/type.rb CHANGED
@@ -8,7 +8,7 @@ module SDL
8
8
  attr_accessor :namespace
9
9
 
10
10
  ##
11
- # The local name of the fact, e.g. "Name" or "ServiceInterface". Defaults to the name of the class.
11
+ # The local name of the type, e.g. "Name" or "ServiceInterface". Defaults to the name of the class.
12
12
  #
13
13
  # The ServiceCompendium#register_classes_globally method makes this class accessible by a constant of this name
14
14
  @local_name
@@ -33,6 +33,18 @@ module SDL
33
33
  end
34
34
  end
35
35
 
36
+ def propertyless?(including_super = false)
37
+ properties(including_super).count == 0
38
+ end
39
+
40
+ def single_property?(including_super = false)
41
+ properties(including_super).count == 1
42
+ end
43
+
44
+ def multi_property?(including_super = true)
45
+ properties(including_super).count > 1
46
+ end
47
+
36
48
  def is_sub?
37
49
  not [SDL::Base::Type, SDL::Base::Fact].include? superclass
38
50
  end
@@ -49,7 +61,7 @@ module SDL
49
61
  naming_property = self.class.properties(true).find {|p| p.name.eql?(self.class.to_s.underscore) }
50
62
 
51
63
  if(naming_property)
52
- instance_variable_get "@#{naming_property.name.to_sym}"
64
+ instance_variable_get("@#{naming_property.name.to_sym}").to_s
53
65
  else
54
66
  self.class.to_s
55
67
  end
@@ -1,5 +1,5 @@
1
1
  module SDL
2
2
  module NG
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -24,7 +24,11 @@ module SDL
24
24
  value = compendium.type_instances[property.type][value] || raise("Could not find instance :#{value.to_s} in predefined #{property.type.name} types")
25
25
  end
26
26
 
27
- instance.send "#{property.name}=", value
27
+ begin
28
+ instance.send "#{property.name}=", value
29
+ rescue RuntimeError => e
30
+ raise RuntimeError, "Cannot set property '#{property.name}' of Type #{@instance.class.name}: #{e}", e.backtrace
31
+ end
28
32
  end
29
33
  else
30
34
  # Multi-valued properties are added to by their singular name
@@ -69,7 +69,16 @@ module SDL
69
69
  def add_property(sym, type, multi)
70
70
  unless multi
71
71
  @klass.class_eval do
72
- attr_accessor sym
72
+ attr_reader sym
73
+
74
+ # Setter
75
+ define_method "#{sym}=" do |value|
76
+ if type < SDL::Types::SDLSimpleType
77
+ instance_variable_set "@#{sym}".to_s, type.new(value)
78
+ else
79
+ instance_variable_set "@#{sym}".to_s, value
80
+ end
81
+ end
73
82
  end
74
83
  else
75
84
  # Define accessor method for lists
data/lib/sdl/types.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require_relative 'types/sdl_type'
2
- require_relative 'types/sdl_default_type'
2
+ require_relative 'types/sdl_simple_type'
3
3
  require_relative 'types/sdl_string'
4
4
  require_relative 'types/sdl_description'
5
5
  require_relative 'types/sdl_number'
@@ -1,6 +1,6 @@
1
1
  module SDL
2
2
  module Types
3
- class SDLDatetime < SDLDefaultType
3
+ class SDLDatetime < SDLSimpleType
4
4
  include SDLType
5
5
 
6
6
  wraps Time
@@ -1,10 +1,14 @@
1
1
  module SDL
2
2
  module Types
3
- class SDLDescription < SDLDefaultType
3
+ class SDLDescription < SDLSimpleType
4
4
  include SDLType
5
5
 
6
6
  wraps String
7
7
  codes :description
8
+
9
+ def from_nilclass(nilvalue)
10
+ @value = ""
11
+ end
8
12
  end
9
13
  end
10
14
  end
@@ -2,7 +2,7 @@ require 'active_support/duration'
2
2
 
3
3
  module SDL
4
4
  module Types
5
- class SDLDuration < SDLDefaultType
5
+ class SDLDuration < SDLSimpleType
6
6
  include SDLType
7
7
 
8
8
  wraps ActiveSupport::Duration
@@ -1,9 +1,9 @@
1
1
  module SDL
2
2
  module Types
3
- class SDLNumber < SDLDefaultType
3
+ class SDLNumber < SDLSimpleType
4
4
  include SDLType
5
5
 
6
- wraps Integer
6
+ wraps Numeric
7
7
  codes :number, :int, :integer
8
8
  end
9
9
  end
@@ -0,0 +1,57 @@
1
+ ##
2
+ # Base SDL type.
3
+ #
4
+ # All types share a common constructor, which delegates part of its functionality.
5
+ class SDL::Types::SDLSimpleType
6
+ include SDL::Types::SDLType
7
+
8
+ # The SDL value type value, possibly converted to the wrapped ruby type, e.g., an URI object created from an
9
+ # "http://" String
10
+ attr_reader :value
11
+
12
+ # The raw value, with which this type was instatiated
13
+ attr_reader :raw_value
14
+
15
+ ##
16
+ # Creates a new instance of an SDL type.
17
+ #
18
+ # Invokes +from_+ methods of subtypes, if +value+ is not subtype of the wrapped Ruby type.
19
+ #
20
+ # @param[Object] value
21
+ # The instance value. Unless the value class is a subclass of the wrapped Ruby class,
22
+ # perform conversion by invoking +from_#{classname}+, e.g. +from_string+ or +from_integer+.
23
+ #
24
+ # Subclasses are expected to implement this conversion function.
25
+ def initialize(value)
26
+ @raw_value = value
27
+
28
+ if value.class <= self.class.wrapped_type
29
+ @value = value
30
+ else
31
+ begin
32
+ send(conversion_method_name(value), value)
33
+ rescue NoMethodError
34
+ raise "Cannot create instance of #{self.class.name} with a #{value.class.name} value. Please implement #{self.class.name}##{conversion_method_name(value)}"
35
+ end
36
+ end
37
+ end
38
+
39
+ def ==(value)
40
+ @value == value
41
+ end
42
+
43
+ def to_s
44
+ @value.to_s
45
+ end
46
+
47
+ ##
48
+ # Designates this SDLType to be a default type, i.e., to be loaded by all ServiceCompendiums automatically
49
+ def self.inherited(subclass)
50
+ SDL::Base::ServiceCompendium.default_sdltypes << subclass
51
+ end
52
+
53
+ private
54
+ def conversion_method_name(value)
55
+ value.class.name.demodulize.camelize.downcase
56
+ end
57
+ end
@@ -1,6 +1,6 @@
1
1
  module SDL
2
2
  module Types
3
- class SDLString < SDLDefaultType
3
+ class SDLString < SDLSimpleType
4
4
  include SDLType
5
5
 
6
6
  wraps String
@@ -2,11 +2,19 @@ require 'uri'
2
2
 
3
3
  module SDL
4
4
  module Types
5
- class SDLUrl < SDLDefaultType
5
+ class SDLUrl < SDLSimpleType
6
6
  include SDLType
7
7
 
8
8
  wraps URI
9
9
  codes :uri, :url
10
+
11
+ def from_string(string_value)
12
+ begin
13
+ URI.parse string_value
14
+ rescue URI::InvalidURIError
15
+ throw "Invalid URI: #{string_value}"
16
+ end
17
+ end
10
18
  end
11
19
  end
12
20
  end
@@ -125,23 +125,23 @@ describe 'Doing type instance definition' do
125
125
  end
126
126
  end
127
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'
128
+ expect(compendium.services[:multi_service].facts[0].a).to eq '1'
129
+ expect(compendium.services[:multi_service].facts[0].b).to eq '2'
130
+ expect(compendium.services[:multi_service].facts[0].c).to eq nil
131
+ expect(compendium.services[:multi_service].facts[0].d).to eq '3'
132
132
  expect(compendium.services[:multi_service].facts[0].e).to eq(nil)
133
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'
134
+ expect(compendium.services[:multi_service].facts[1].multis[0].b).to eq '2'
135
+ expect(compendium.services[:multi_service].facts[1].multis[1].e).to eq '5'
136
136
  end
137
137
 
138
- context 'the #to_s method of a service' do
138
+ context 'the #to_s method of a fact' do
139
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'
140
+ compendium.service :named_service do
141
+ has_name 'My name'
142
142
  end
143
143
 
144
- expect(compendium.services[:named_color_service].facts[0].to_s).to eq('My color name')
144
+ expect(compendium.services[:named_service].facts[0].to_s).to eq 'My name'
145
145
  end
146
146
 
147
147
  it 'gives out the Fact class local name when no same-named property than the class exists' do
@@ -149,7 +149,7 @@ describe 'Doing type instance definition' do
149
149
  has_color :blue
150
150
  end
151
151
 
152
- expect(compendium.services[:blue_service].facts[0].to_s).to eq('Color')
152
+ expect(compendium.services[:blue_service].facts[0].to_s).to eq 'Color'
153
153
  end
154
154
  end
155
155
 
@@ -171,8 +171,8 @@ describe 'Doing type instance definition' do
171
171
 
172
172
  expect(compendium.services[:favourite_service].facts[0].favourites[0].color).to eq(compendium.type_instances[Color][:red])
173
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)
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
176
  end
177
177
 
178
178
  it 'returns the values of all properties by calling #property_values on a type' do
@@ -183,6 +183,6 @@ describe 'Doing type instance definition' do
183
183
  property_values = compendium.services[:imaginative_service].facts[0].property_values
184
184
 
185
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')
186
+ expect(property_values[property_values.keys[1]]).to eq 'Yellow'
187
187
  end
188
188
  end
@@ -22,6 +22,10 @@ shared_context 'the default compendium' do
22
22
  end
23
23
  end
24
24
 
25
+ fact :name do
26
+ string :name
27
+ end
28
+
25
29
  fact :multicolor do
26
30
  list_of_colors :colors
27
31
  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.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Slawik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-17 00:00:00.000000000 Z
11
+ date: 2014-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -237,10 +237,10 @@ files:
237
237
  - lib/sdl/translations/en.yml
238
238
  - lib/sdl/types.rb
239
239
  - lib/sdl/types/sdl_datetime.rb
240
- - lib/sdl/types/sdl_default_type.rb
241
240
  - lib/sdl/types/sdl_description.rb
242
241
  - lib/sdl/types/sdl_duration.rb
243
242
  - lib/sdl/types/sdl_number.rb
243
+ - lib/sdl/types/sdl_simple_type.rb
244
244
  - lib/sdl/types/sdl_string.rb
245
245
  - lib/sdl/types/sdl_type.rb
246
246
  - lib/sdl/types/sdl_url.rb
@@ -1,13 +0,0 @@
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