Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Parser

- fixed parsing of links if there is only one resource present in the collection
- added to_s method to entity
- improved rendering of source in json representation of link
  • Loading branch information...
commit be2cdc7b8580e7820046f1050c86851bbeddee25 1 parent ce4ac07
@ffeldhaus authored
View
4 lib/occi/core/entity.rb
@@ -190,6 +190,10 @@ def to_header
header
end
+ def to_s
+ self.location
+ end
+
def inspect
JSON.pretty_generate(JSON.parse(to_json))
end
View
2  lib/occi/core/link.rb
@@ -77,7 +77,7 @@ def check(model)
def as_json(options={ })
link = super
link.rel = @rel if @rel
- link.source = self.source.to_s if self.source.kind_of? String if self.source
+ link.source = self.source.to_s if self.source.to_s
link.target = self.target.to_s if self.target
link
end
View
21 lib/occi/parser.rb
@@ -190,11 +190,28 @@ def self.text_entity(text, entity_type)
# @return [OCCI::Collection]
def self.json(json)
collection = OCCI::Collection.new
- hash = Hashie::Mash.new(JSON.parse(json))
+ hash = Hashie::Mash.new(JSON.parse(json))
collection.kinds.concat hash.kinds.collect { |kind| OCCI::Core::Kind.new(kind.scheme, kind.term, kind.title, kind.attributes, kind.related, kind.actions) } if hash.kinds
collection.mixins.concat hash.mixins.collect { |mixin| OCCI::Core::Mixin.new(mixin.scheme, mixin.term, mixin.title, mixin.attributes, mixin.related, mixin.actions) } if hash.mixins
+ collection.actions.concat hash.actions.collect { |action| OCCI::Core::Action.new(action.scheme, action.term, action.title, action.attributes) } if hash.actions
collection.resources.concat hash.resources.collect { |resource| OCCI::Core::Resource.new(resource.kind, resource.mixins, resource.attributes, resource.actions, resource.links) } if hash.resources
- collection.links.concat hash.links.collect { |link| OCCI::Core::Link.new(link.kind, link.mixins, link.attributes) } if hash.links
+ collection.links.concat hash.links.collect { |link| OCCI::Core::Link.new(link.kind, link.mixins, link.attributes, [], nil, link.target) } if hash.links
+
+ if collection.resources.size == 1 && collection.links.size > 0
+ if collection.resources.first.links.empty?
+ collection.links.each { |link| link.source = collection.resources.first }
+ collection.resources.first.links = collection.links
+ end
+ end
+
+ # TODO: replace the following mechanism with one in the Links class
+ # replace link locations with link objects in all resources
+ collection.resources.each do |resource|
+ resource.links.collect! do |resource_link|
+ lnk = collection.links.select { |link| resource_link == link.to_s }.first
+ lnk ||= resource_link
+ end
+ end
collection
end
Please sign in to comment.
Something went wrong with that request. Please try again.