occi-core 5.0.0.beta.16 → 5.0.0.beta.17

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: 4a0ab29b73d64e17d3196b39205eb9fc2e2c1810
4
- data.tar.gz: 46f3633cb5dfb7ece6df2a96c33e6f045f76c170
3
+ metadata.gz: 12e316bc3ef9174ebf47ea762c64444bf481b3b9
4
+ data.tar.gz: a372534fbfbea3aa689e76483725fed437476714
5
5
  SHA512:
6
- metadata.gz: fe713635ebab1f64c3b3d953e0bc98b87b4e7d2120483c1307251802951ebaa3e608c06b3ee83c2cce9cac85be1353f0ad565e94246d46748b74a1b3d5acb68b
7
- data.tar.gz: b3f9e167697889b2238a3514d6e847a4def422d7454e05001cfd0bb310777767166647f7af6fcc0b2319081171d9b440a98728c181be0b4923133fd279eaee92
6
+ metadata.gz: 90ccde6b8820e0be6cc5d3cf595ce75456c2990604aecfbeddec367c56af0811b5877c9a1de23483765df4c4abeb57684e8f82b957841144f1726d1033b4d559
7
+ data.tar.gz: d42a2e5157c338648adc4c1d16ce8a86724f4d00e155221baedbdf39bfb326f9b3bdaba7d9646210cf29f45e33a3040ff6b74336bdd3a04fd43323c43eec925f
@@ -295,7 +295,7 @@ module Occi
295
295
  #
296
296
  # @return [NilClass] when entity instance is valid
297
297
  def valid!
298
- %i[kind id location title attributes mixins actions].each do |attr|
298
+ %i[kind location attributes mixins actions].each do |attr|
299
299
  unless send(attr)
300
300
  raise Occi::Core::Errors::InstanceValidationError,
301
301
  "Missing valid #{attr}"
@@ -34,6 +34,24 @@ module Occi
34
34
  select_mixin(filter) \
35
35
  || raise(Occi::Core::Errors::InstanceLookupError, "Mixin dependent on #{filter} not found")
36
36
  end
37
+
38
+ # Returns a list of term of mixins dependent on the given mixin.
39
+ #
40
+ # @param mixin [Occi::Core::Mixin] parent mixin
41
+ # @return [Array] terms of mixins
42
+ def dependent_terms(mixin)
43
+ select_mixins(mixin).map(&:term)
44
+ end
45
+
46
+ # @see `dependent_terms`
47
+ def dependent_term(mixin)
48
+ [select_mixin(mixin)].compact.map(&:term).first
49
+ end
50
+
51
+ # @see `dependent_term`
52
+ def dependent_term!(mixin)
53
+ select_mixin!(mixin).term
54
+ end
37
55
  end
38
56
  end
39
57
  end
@@ -10,6 +10,9 @@ module Occi
10
10
  #
11
11
  # @author Boris Parak <parak@cesnet.cz>
12
12
  class Link < Entity
13
+ # Separator in URI PATHs
14
+ URI_PATH_SEPARATOR = '/'.freeze
15
+
13
16
  attr_accessor :target_kind, :source_kind
14
17
 
15
18
  # @return [URI] link source
@@ -38,12 +41,22 @@ module Occi
38
41
 
39
42
  # See `#valid!` on `Occi::Core::Entity`.
40
43
  def valid!
44
+ super
45
+
41
46
  %i[source target].each do |attr|
42
- next if send(attr)
43
- raise Occi::Core::Errors::InstanceValidationError, "Missing valid #{attr}"
47
+ next if valid_uri? send(attr)
48
+ raise Occi::Core::Errors::InstanceValidationError, "Malformed or incomplete occi.core.#{attr}"
44
49
  end
50
+ end
45
51
 
46
- super
52
+ # :nodoc:
53
+ def target_id
54
+ last_uri_segment target
55
+ end
56
+
57
+ # :nodoc:
58
+ def source_id
59
+ last_uri_segment source
47
60
  end
48
61
 
49
62
  protected
@@ -65,6 +78,21 @@ module Occi
65
78
  self.target = args.fetch(:target)
66
79
  @target_kind = args.fetch(:target_kind)
67
80
  end
81
+
82
+ # :nodoc:
83
+ def valid_uri?(uri)
84
+ uri_path_segments(uri).count > 2
85
+ end
86
+
87
+ # :nodoc:
88
+ def last_uri_segment(uri)
89
+ uri_path_segments(uri).last
90
+ end
91
+
92
+ # :nodoc:
93
+ def uri_path_segments(uri)
94
+ uri.path.split(URI_PATH_SEPARATOR)
95
+ end
68
96
  end
69
97
  end
70
98
  end
@@ -21,14 +21,12 @@ module Occi
21
21
  end
22
22
 
23
23
  # @param links [Set] set of links
24
- def links=(links)
25
- unless links
26
- raise Occi::Core::Errors::InstanceValidationError,
27
- 'Missing valid links'
28
- end
24
+ def links=(new_links)
25
+ raise Occi::Core::Errors::InstanceValidationError, 'Missing valid links' unless new_links
26
+
29
27
  @links ||= Set.new
30
28
  @links.each { |l| remove_link(l) }
31
- links.each { |l| add_link(l) }
29
+ new_links.each { |l| add_link(l) }
32
30
 
33
31
  @links
34
32
  end
@@ -59,10 +57,8 @@ module Occi
59
57
  #
60
58
  # @param link [Occi::Core::Link] link to be added
61
59
  def add_link(link)
62
- unless link
63
- raise Occi::Core::Errors::MandatoryArgumentError,
64
- 'Cannot add a non-existent link'
65
- end
60
+ raise Occi::Core::Errors::MandatoryArgumentError, 'Cannot add a non-existent link' unless link
61
+
66
62
  link.source = location
67
63
  link.source_kind = kind
68
64
  links << link
@@ -72,10 +68,8 @@ module Occi
72
68
  #
73
69
  # @param link [Occi::Core::Link] link to be removed
74
70
  def remove_link(link)
75
- unless link
76
- raise Occi::Core::Errors::MandatoryArgumentError,
77
- 'Cannot remove a non-existent link'
78
- end
71
+ raise Occi::Core::Errors::MandatoryArgumentError, 'Cannot remove a non-existent link' unless link
72
+
79
73
  link.source = nil
80
74
  link.source_kind = nil
81
75
  links.delete link
@@ -83,12 +77,25 @@ module Occi
83
77
 
84
78
  # See `#valid!` on `Occi::Core::Entity`.
85
79
  def valid!
86
- unless links
87
- raise Occi::Core::Errors::InstanceValidationError,
88
- 'Missing valid links'
89
- end
90
- links.each(&:valid!)
91
80
  super
81
+
82
+ raise Occi::Core::Errors::InstanceValidationError, 'Missing valid links' unless links
83
+ links.each(&:valid!)
84
+ end
85
+
86
+ # :nodoc:
87
+ def links_by_klass(klass)
88
+ links.select { |l| l.is_a?(klass) }
89
+ end
90
+
91
+ # :nodoc:
92
+ def links_by_kind(kind)
93
+ links.select { |l| l.kind == kind }
94
+ end
95
+
96
+ # :nodoc:
97
+ def links_by_kind_identifier(kind_identifier)
98
+ links.select { |l| l.kind_identifier == kind_identifier }
92
99
  end
93
100
 
94
101
  protected
@@ -103,8 +110,7 @@ module Occi
103
110
  super
104
111
 
105
112
  return unless args[:links].nil?
106
- raise Occi::Core::Errors::MandatoryArgumentError,
107
- "Links is a mandatory argument for #{self.class}"
113
+ raise Occi::Core::Errors::MandatoryArgumentError, "Links is a mandatory argument for #{self.class}"
108
114
  end
109
115
 
110
116
  # :nodoc:
@@ -3,7 +3,7 @@ module Occi
3
3
  MAJOR_VERSION = 5 # Major update constant
4
4
  MINOR_VERSION = 0 # Minor update constant
5
5
  PATCH_VERSION = 0 # Patch/Fix version constant
6
- STAGE_VERSION = 'beta.16'.freeze # use `nil` for production releases
6
+ STAGE_VERSION = 'beta.17'.freeze # use `nil` for production releases
7
7
 
8
8
  unless defined?(::Occi::Core::VERSION)
9
9
  VERSION = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: occi-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.beta.16
4
+ version: 5.0.0.beta.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Parak
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-08-05 00:00:00.000000000 Z
13
+ date: 2017-08-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json