Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
66 lines (54 sloc) 1.82 KB
# -*- ruby -*-
#--
# Copyright 2008 Danny Coates, Ashkan Farhadtouski
# All rights reserved.
# See LICENSE for permissions.
#++
#AUTOGENERATED Thing extension
# Make sure to load the original
require File.join(HEALTHVAULT_ROOT, 'lib', 'generated', 'health_vault', 'wc_data', 'thing', 'thing')
module HealthVault
module WCData
module Thing
class Thing
@@class_hash = Hash.new
<%- class_hash.each do |key, val| -%>
@@class_hash['<%= key %>'] = '<%= val %>'
<%- end -%>
class << self
def guid_to_class(guid)
@@class_hash[guid].constantize
end
def class_to_guid(klass)
@@class_hash.index(klass.to_s)
end
def from_data(data)
guid = class_to_guid(data.class)
raise "No Guid for #{data.class}" if guid.nil?
new(:guid => guid){|t| t.add_data_xml(HealthVault::WCData::Thing::DataXml.new(:anything => data)) }
end
end
def guid
type_id && type_id.data
end
def guid=(val)
self.type_id = HealthVault::WCData::Thing::ThingType.new(:data => HealthVault::WCData::Types::Guid.new(val))
end
add_child_method :guid
def relate(other)
self.data_xml.first.common ||= HealthVault::WCData::Thing::Common.new
self.data_xml.first.common.add_related_thing(HealthVault::WCData::Thing::RelatedThing.new(
:thing_id => other.thing_id.data,
:version_stamp => other.thing_id.version_stamp
))
other
end
def put(connection)
result = connection.put_thing(self)
self.thing_id = result.info.thing_id.first # Set id and update version
result
end
end
end
end
end