occi-core 4.2.10 → 4.2.11

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,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 24ac48413195e65ec6847bb7d4c3ebad5a13e910
4
- data.tar.gz: 039a79688fea638a32f959e5faa7dbba6e71938a
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWU2NmRkOTcxMWYxMjZmNTExZTZmY2MyZTk5NTA0OTZkYTZjYzNhNw==
5
+ data.tar.gz: !binary |-
6
+ MWExYTgyNzM0ZjU4NzA4MjhjNjRkNzZiZDBhZjI4N2IwNmY5ZTdkMw==
5
7
  SHA512:
6
- metadata.gz: aa4eeb03ceadf69c476ace568a61d1517b166043a3e0104a0451b569a91f16882a258144ae48254a2ca2d9e7c4c0ec62be9a1c5b9cc9cf62b6fcebd92ecc92f8
7
- data.tar.gz: f601b3b6bde0c77b61da0c2d7c817761060d2556ff4b716d6f787ae9c5f80e25a2b31e3ca4039ac2c698efb10333f37f2aece544b4c5c04878d9d5d7af5ba29c
8
+ metadata.gz: !binary |-
9
+ MzE2MDM1N2NmYmNmMTZhMWY0NDg3YmM3M2NhYTM0NzU3MTJhZGYyNTQxOTk1
10
+ YmVjNGEyMzkxZjM4OTI4MGFmZDg5ZjA5NTFkNGM1ODFiMjg3MmY4N2FhNTVk
11
+ ZDZlNWY0NDg2YzZhMDdiNjZkNTIyN2NkODA4MjBkNTYyNGMyZTM=
12
+ data.tar.gz: !binary |-
13
+ ZDhmN2JjNzFmZTFjYTg2NTRiNjU1MjkwZjkyMDFkNGU5YWY5ZjkzYzQxZWEw
14
+ OWZlNjAzZDRhZGYyMDk3Njk1MzcwYTgzZmQ1OTEzYmNmODJjODM0ODBjZTc0
15
+ ZmEzOTUyMmJiNTk5ZTliMjQ1ZmI5YzMyNDcxNzA3ZWRmYzVhMjM=
@@ -134,6 +134,7 @@ module Occi
134
134
  # @param cats_only [Boolean] look only for categories
135
135
  # @return [Occi::Core::Category]
136
136
  def get_by_id(id, cats_only = false)
137
+ raise "Cannot do a look-up with a blank id!" if id.blank?
137
138
  object = self.categories.select { |category| category.type_identifier == id }
138
139
  object = self.entities.select { |entity| entity.id == id } if !cats_only && object.empty?
139
140
  object.first
@@ -141,10 +142,11 @@ module Occi
141
142
 
142
143
  # Returns the category corresponding to a given location
143
144
  #
144
- # @param [URI] location
145
+ # @param [String] location
145
146
  # @return [Occi::Core::Category]
146
147
  def get_by_location(location)
147
- self.categories.select { |category| category.location == location }.first
148
+ raise "Cannot do a look-up with a blank location!" if location.blank?
149
+ self.categories.select { |category| category.location == instance2cat(location) }.first
148
150
  end
149
151
 
150
152
  # @return [true,false] true if collection is empty, false otherwise
@@ -154,9 +156,10 @@ module Occi
154
156
 
155
157
  # Returns a collection with all categories related to the specified category
156
158
  #
157
- # @param [Occi::Core::Category] category
159
+ # @param [Occi::Core::Category, String] category
158
160
  # @return [Occi::Core::Collection]
159
161
  def get_related_to(category)
162
+ raise "Cannot do a look-up with a blank category!" if category.blank?
160
163
  collection = self.class.new
161
164
  collection.kinds = @kinds.get_related_to(category)
162
165
  collection.mixins = @mixins.get_related_to(category)
@@ -194,14 +197,14 @@ module Occi
194
197
  text = ""
195
198
 
196
199
  if standalone_links?
197
- raise "Only one standalone link allowed for rendering to text/plain" if self.links.size > 1
200
+ raise "Only one standalone link allowed for rendering to text/plain!" if self.links.size > 1
198
201
  text << self.links.first.to_text
199
202
  elsif standalone_action_instance?
200
203
  text << self.action.to_text
201
204
  else
202
205
  text << self.categories.collect { |category| category.to_text }.join("\n")
203
206
  text << "\n" if self.categories.any?
204
- raise "Only one resource allowed for rendering to text/plain" if self.resources.size > 1
207
+ raise "Only one resource allowed for rendering to text/plain!" if self.resources.size > 1
205
208
  text << self.resources.first.to_text if self.resources.any?
206
209
  text << self.links.collect { |link| link.to_text_link }.join("\n")
207
210
  text << self.action.to_text if self.action
@@ -214,13 +217,13 @@ module Occi
214
217
  header = Hashie::Mash.new
215
218
 
216
219
  if standalone_links?
217
- raise "Only one standalone link allowed for rendering to text/occi" if self.links.size > 1
220
+ raise "Only one standalone link allowed for rendering to text/occi!" if self.links.size > 1
218
221
  header = self.links.first.to_header
219
222
  elsif standalone_action_instance?
220
223
  header = self.action.to_header
221
224
  else
222
225
  header['Category'] = self.categories.collect { |category| category.to_string_short }.join(',') if self.categories.any?
223
- raise "Only one resource allowed for rendering to text/occi" if self.resources.size > 1
226
+ raise "Only one resource allowed for rendering to text/occi!" if self.resources.size > 1
224
227
  header = self.class.header_merge(header, self.resources.first.to_header) if self.resources.any?
225
228
  header['Link'] = self.links.collect { |link| link.to_string }.join(',') if self.links.any?
226
229
  header = self.class.header_merge(header, self.action.to_header) if self.action
@@ -250,5 +253,12 @@ module Occi
250
253
  !self.action.blank? && self.categories.blank? && self.entities.blank?
251
254
  end
252
255
 
256
+ def instance2cat(location)
257
+ return location if location.start_with?('/') && location.end_with?('/')
258
+ cat_relative_uri = "#{File.dirname(URI.parse(location).path)}/"
259
+ raise "Supplied location is invalid! #{cat_relative_uri.inspect}" unless cat_relative_uri =~ /\/.+\//
260
+ cat_relative_uri
261
+ end
262
+
253
263
  end
254
264
  end
@@ -185,9 +185,13 @@ module Occi
185
185
  entity = Hashie::Mash.new
186
186
  entity.kind = @kind.to_s if @kind
187
187
  entity.mixins = @mixins.join(' ').split(' ') if @mixins.any?
188
- entity.actions = @actions.as_json if @actions.any?
188
+
189
+ action_strings = @actions.collect { |action| action.to_s if action.to_s }.compact
190
+ entity.actions = action_strings unless action_strings.empty?
191
+
189
192
  entity.attributes = @attributes.as_json if @attributes.as_json.any?
190
193
  entity.id = id.to_s if id
194
+
191
195
  entity
192
196
  end
193
197
 
@@ -15,6 +15,7 @@ module Occi
15
15
  link = Occi::Core::Link.new(*args)
16
16
  link.model = @model if @model
17
17
  self << link
18
+
18
19
  link
19
20
  end
20
21
 
@@ -22,10 +23,12 @@ module Occi
22
23
 
23
24
  def convert(link)
24
25
  if link.kind_of? String
25
- target = link
26
- link = Occi::Core::Link.new
27
- link.target = target
26
+ link_location = link
27
+ link = Occi::Core::Link.new
28
+ link.id = link_location.split('/').last
29
+ link.location = link_location
28
30
  end
31
+
29
32
  link
30
33
  end
31
34
 
@@ -44,8 +44,15 @@ module Occi
44
44
  resource.attributes.merge! attribute(line)
45
45
  when /^Link:/
46
46
  link = link_string(line, resource)
47
- resource.links << link
48
- links << link
47
+
48
+ if link.kind_of? Occi::Core::Link
49
+ resource.links << link
50
+ links << link
51
+ elsif link.kind_of? Occi::Core::Action
52
+ resource.actions << link
53
+ else
54
+ raise Occi::Errors::ParserInputError, "Could not recognize resource link! #{link.inspect}"
55
+ end
49
56
  end
50
57
  }
51
58
  lines.respond_to?(:each) ? lines.each(&block) : lines.each_line(&block)
@@ -169,8 +176,22 @@ module Occi
169
176
 
170
177
  raise Occi::Errors::ParserInputError, "Could not match #{string}" unless match
171
178
 
179
+ if match[:uri].include?('?action=')
180
+ link_string_action match
181
+ else
182
+ link_string_link match, source
183
+ end
184
+ end
185
+
186
+ def link_string_action(match)
187
+ scheme, term = match[:rel].split('#')
188
+ Occi::Core::Action.new scheme, term
189
+ end
190
+
191
+ def link_string_link(match, source)
172
192
  target = match[:uri]
173
193
  rel = match[:rel]
194
+
174
195
  if match[:category].blank?
175
196
  kind = Occi::Core::Link.kind
176
197
  else
@@ -183,7 +204,7 @@ module Occi
183
204
 
184
205
  # create an array of the list of attributes
185
206
  attributes = []
186
- regexp=Regexp.new '(\\s*'+REGEXP_ATTRIBUTE_REPR.to_s+')'
207
+ regexp = Regexp.new '(\\s*'+REGEXP_ATTRIBUTE_REPR.to_s+')'
187
208
  attr_line = match[:attributes].sub(/^\s*;\s*/, ' ')
188
209
  attributes = attr_line.scan(regexp).collect {|matches| matches.first}
189
210
 
@@ -191,6 +212,7 @@ module Occi
191
212
  attributes = attributes.inject(Hashie::Mash.new) { |hsh, attribute|
192
213
  hsh.merge!(Occi::Parser::Text.attribute("X-OCCI-Attribute: #{attribute}"))
193
214
  }
215
+
194
216
  Occi::Core::Link.new kind, mixins, attributes, actions, rel, target, source, location
195
217
  end
196
218
 
data/lib/occi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Occi
2
- VERSION = "4.2.10" unless defined?(::Occi::VERSION)
2
+ VERSION = "4.2.11" unless defined?(::Occi::VERSION)
3
3
  end
data/lib/occi-core.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
 
3
3
  require 'set'
4
+ require 'uri'
4
5
  require 'hashie/mash'
5
6
 
6
7
  require 'active_support/core_ext'
@@ -71,14 +71,22 @@ module Occi
71
71
  }
72
72
  it 'gets Entity as a related kind' do
73
73
  expect(collection.get_related_to(Occi::Core::Entity.kind)).to eql collection
74
+ expect(collection.get_related_to(Occi::Core::Entity.kind.type_identifier)).to eql collection
74
75
  end
75
76
 
76
77
  it 'gets Resource as a related kind' do
77
78
  expect(collection.get_related_to(Occi::Core::Resource.kind).kinds.first).to eql Occi::Core::Resource.kind
79
+ expect(collection.get_related_to(Occi::Core::Resource.kind.type_identifier).kinds.first).to eql Occi::Core::Resource.kind
78
80
  end
79
81
 
80
82
  it 'gets Link as a related kind' do
81
83
  expect(collection.get_related_to(Occi::Core::Link.kind).kinds.first).to eql Occi::Core::Link.kind
84
+ expect(collection.get_related_to(Occi::Core::Link.kind.type_identifier).kinds.first).to eql Occi::Core::Link.kind
85
+ end
86
+
87
+ it 'fails loudly when no category is given' do
88
+ expect { collection.get_related_to("") } .to raise_error RuntimeError
89
+ expect { collection.get_related_to(nil) } .to raise_error RuntimeError
82
90
  end
83
91
  end
84
92
 
@@ -716,6 +724,11 @@ module Occi
716
724
  expect(collection.get_by_id("ID.notexist")).to eql nil
717
725
  end
718
726
 
727
+ it 'fails loudly when no id is given' do
728
+ expect { collection.get_by_id("") } .to raise_error RuntimeError
729
+ expect { collection.get_by_id(nil) } .to raise_error RuntimeError
730
+ end
731
+
719
732
  end
720
733
 
721
734
  context '#get_by_location' do
@@ -723,9 +736,18 @@ module Occi
723
736
  expect(collection.get_by_location("/mixin/my_mixin/")).to eql collection.mixins.first
724
737
  end
725
738
 
739
+ it 'finds category by instance location' do
740
+ expect(collection.get_by_location("/compute/1")).to eql collection.kinds.first
741
+ end
742
+
726
743
  it 'fails gracefully' do
727
744
  expect(collection.get_by_location("/notexist/")).to eql nil
728
745
  end
746
+
747
+ it 'fails loudly when no location is given' do
748
+ expect { collection.get_by_location("") } .to raise_error RuntimeError
749
+ expect { collection.get_by_location(nil) } .to raise_error RuntimeError
750
+ end
729
751
  end
730
752
  end
731
753
 
@@ -85,7 +85,7 @@ module Occi
85
85
  entities << entity2
86
86
  expected = []
87
87
  hash=Hashie::Mash.new JSON.parse('{"kind":"http://schemas.ogf.org/occi/core#entity","attributes":{"occi":{"core":{"id":"e1testid"}}},"id":"e1testid"}')
88
- hash2= Hashie::Mash.new JSON.parse('{"kind":"http://example.org/test/schema#entity2","actions":[{"scheme":"http://schemas.ogf.org/occi/core/entity/action#","term":"testaction","title":"testaction action","attributes":{}}],"attributes":{"occi":{"core":{"id":"e2testid"}}},"id":"e2testid"}')
88
+ hash2= Hashie::Mash.new JSON.parse('{"kind":"http://example.org/test/schema#entity2","actions":["http://schemas.ogf.org/occi/core/entity/action#testaction"],"attributes":{"occi":{"core":{"id":"e2testid"}}},"id":"e2testid"}')
89
89
  expected << hash
90
90
  expected << hash2
91
91
  expect(entities.as_json).to eql expected
@@ -174,6 +174,15 @@ Link: </TestLoc/1?action=testaction>;rel="http://schemas.ogf.org/occi/core/entit
174
174
  end
175
175
  end
176
176
 
177
+ context '#as_json' do
178
+ it 'renders element as JSON' do
179
+ entity.actions << testaction
180
+
181
+ expected = Hashie::Mash.new JSON.parse('{"kind":"http://schemas.ogf.org/occi/core#entity","actions":["http://schemas.ogf.org/occi/core/entity/action#testaction"],"attributes":{"occi":{"core":{"id":"baf1"}}},"id":"baf1"}')
182
+ expect(entity.as_json).to eql expected
183
+ end
184
+ end
185
+
177
186
  context '#check' do
178
187
  let(:defs){
179
188
  defs = Occi::Core::Attributes.new
@@ -35,9 +35,11 @@ module Occi
35
35
  expect(links.count).to eql 2
36
36
  end
37
37
 
38
- it 'populates target in the link' do
39
- links = Occi::Core::Links.new ["target1"]
40
- expect(links.first.target).to eql "target1"
38
+ it 'populates Links with correctly initialized links' do
39
+ links = Occi::Core::Links.new ["/link/9c3b83bd-2456-45e9-8ce5-91a7d5c7bb85"]
40
+
41
+ expect(links.first.id).to eql "9c3b83bd-2456-45e9-8ce5-91a7d5c7bb85"
42
+ expect(links.first.location).to eql "/link/9c3b83bd-2456-45e9-8ce5-91a7d5c7bb85"
41
43
  end
42
44
 
43
45
  it 'produces the right number of members, string/link combination' do
@@ -237,12 +237,10 @@ module Occi
237
237
  expect(link).to eql expected
238
238
  end
239
239
 
240
- it 'parses string with category unset' do
240
+ it 'parses string with action link' do
241
241
  link_string = 'Link: </compute/04106bce-87eb-4f8f-a665-2f624e54ba46?action=restart>; rel="http://schemas.ogf.org/occi/infrastructure/compute/action#restart"'
242
242
  link = Occi::Parser::Text.link_string(link_string, "source")
243
- expected = Marshal.restore("\x04\bo:\x15Occi::Core::Link\x0E:\n@kindo:\x15Occi::Core::Kind\r:\f@schemeI\"&http://schemas.ogf.org/occi/core#\x06:\x06EF:\n@termI\"\tlink\x06;\tF:\v@titleI\"\tlink\x06;\tF:\x10@attributesC:\eOcci::Core::Attributes{\x06I\"\tocci\x06;\tFC;\r{\x06I\"\tcore\x06;\tFC;\r{\rI\"\aid\x06;\tFo:\eOcci::Core::Properties\v:\r@default0:\n@typeI\"\vstring\x06;\tF:\x0E@requiredF:\r@mutableF:\r@patternI\"A[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\x06;\tF:\x11@description0I\"\b_id\x06;\tFo;\x0E\v;\x0F0;\x10@\x11;\x11F;\x12F;\x13@\x12;\x140I\"\ntitle\x06;\tFo;\x0E\v;\x0F0;\x10I\"\vstring\x06;\tF;\x11F;\x12T;\x13I\"\a.*\x06;\tF;\x140I\"\v_title\x06;\tFo;\x0E\v;\x0F0;\x10@\x17;\x11F;\x12T;\x13@\x18;\x140I\"\vtarget\x06;\tFo;\x0E\v;\x0F0;\x10I\"\vstring\x06;\tF;\x11F;\x12T;\x13I\"\a.*\x06;\tF;\x140I\"\f_target\x06;\tFo;\x0E\v;\x0F0;\x10@\x1D;\x11F;\x12T;\x13@\x1E;\x140I\"\vsource\x06;\tFo;\x0E\v;\x0F0;\x10I\"\vstring\x06;\tF;\x11F;\x12T;\x13I\"\a.*\x06;\tF;\x140I\"\f_source\x06;\tFo;\x0E\v;\x0F0;\x10@#;\x11F;\x12T;\x13@$;\x140:\f@parento;\a\r;\bI\"&http://schemas.ogf.org/occi/core#\x06;\tF;\nI\"\ventity\x06;\tF;\vI\"\ventity\x06;\tF;\fC;\r{\x06@\vC;\r{\x06@\rC;\r{\t@\x0F@\x10@\x13@\x14@\x15@\x16@\x19@\x1A;\x150:\r@actionso:\x18Occi::Core::Actions\x06:\n@hash{\x00:\x0E@entitieso:\x19Occi::Core::Entities\x06;\x18{\x00:\x0E@locationI\"\r/entity/\x06;\tF;\x16o;\x17\x06;\x18{\x00;\x19o;\x1A\x06;\x18{\x00;\eI\"\v/link/\x06;\tF:\f@mixinso:\x17Occi::Core::Mixins\a;\x18{\x00:\f@entity@\x00;\fIC;\r{\x06@\vIC;\r{\x06@\rIC;\r{\r@\x0F0@\x13@\x14@\x150@\x19@\x1A@\e0@\x1F@ @!0@%@&\x06:\x0F@convertedT\x06;\x1FT\x06;\x1FT;\x16o;\x17\x06;\x18{\x00;\e0:\t@relo;\a\r;\bI\"?http://schemas.ogf.org/occi/infrastructure/compute/action#\x06;\tT;\nI\"\frestart\x06;\tT;\v0;\fC;\r{\x00;\x15@';\x16o;\x17\x06;\x18{\x00;\x19o;\x1A\x06;\x18{\x00;\eI\"\x0E/restart/\x06;\tF:\f@sourceI\"\vsource\x06;\tT:\f@targetI\"A/compute/04106bce-87eb-4f8f-a665-2f624e54ba46?action=restart\x06;\tT:\b@id0")
244
- expected.id = 'epmtied'
245
- link.id = 'epmtied'
243
+ expected = Marshal.restore("\x04\bo:\x17Occi::Core::Action\t:\f@schemeI\"?http://schemas.ogf.org/occi/infrastructure/compute/action#\x06:\x06ET:\n@termI\"\frestart\x06;\aT:\v@title0:\x10@attributesC:\eOcci::Core::Attributes{\x00")
246
244
  expect(link).to eql expected
247
245
  end
248
246
  end
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: 4.2.10
4
+ version: 4.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Feldhaus
@@ -10,48 +10,48 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-02-15 00:00:00.000000000 Z
13
+ date: 2014-03-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - '>='
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - '>='
26
+ - - ! '>='
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: hashie
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - '>='
33
+ - - ! '>='
34
34
  - !ruby/object:Gem::Version
35
35
  version: '0'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - '>='
40
+ - - ! '>='
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: uuidtools
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - '>='
47
+ - - ! '>='
48
48
  - !ruby/object:Gem::Version
49
49
  version: 2.1.3
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - '>='
54
+ - - ! '>='
55
55
  - !ruby/object:Gem::Version
56
56
  version: 2.1.3
57
57
  - !ruby/object:Gem::Dependency
@@ -72,14 +72,14 @@ dependencies:
72
72
  name: settingslogic
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - '>='
75
+ - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  type: :runtime
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - '>='
82
+ - - ! '>='
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  description: OCCI is a collection of classes to simplify the implementation of the
@@ -231,12 +231,12 @@ require_paths:
231
231
  - lib
232
232
  required_ruby_version: !ruby/object:Gem::Requirement
233
233
  requirements:
234
- - - '>='
234
+ - - ! '>='
235
235
  - !ruby/object:Gem::Version
236
236
  version: 1.9.3
237
237
  required_rubygems_version: !ruby/object:Gem::Requirement
238
238
  requirements:
239
- - - '>='
239
+ - - ! '>='
240
240
  - !ruby/object:Gem::Version
241
241
  version: '0'
242
242
  requirements: []