1 class OrvosBase < ActiveRecord::Base
2 self.abstract_class = true
5 return @columns unless @columns.nil?
7 return @columns if $orvos_api_client.orvos_schema[self.to_s.to_sym].nil?
8 $orvos_api_client.orvos_schema[self.to_s.to_sym].each do |coldef|
9 k = coldef[:name].to_sym
10 if coldef[:type] == coldef[:type].downcase
11 @columns << column(k, coldef[:type].to_sym)
13 @columns << column(k, :text)
14 serialize k, coldef[:type].constantize
22 def self.column(name, sql_type = nil, default = nil, null = true)
23 ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
26 new($orvos_api_client.api(self, '/' + uuid))
29 OrvosResourceList.new(self).where(*args)
32 OrvosResourceList.new(self).eager(*args)
35 OrvosResourceList.new(self).all(*args)
39 self.class.columns.each do |col|
40 obdata[col.name.to_sym] = self.send(col.name.to_sym)
44 postdata = { self.class.to_s.underscore => obdata }
46 postdata['_method'] = 'PUT'
47 resp = $orvos_api_client.api(self.class, '/' + uuid, postdata)
49 resp = $orvos_api_client.api(self.class, '', postdata)
51 return false if !resp[:etag] || !resp[:uuid]
54 self.uuid ||= resp[:uuid]
58 self.save or raise Exception.new("Save failed")
61 @etag = h.delete :etag
62 @kind = h.delete :kind
67 o.merge!(args.pop) if args[-1].is_a? Hash
68 o[:metadata_class] ||= args.shift
69 o[:name] ||= args.shift
70 o[:head_kind] ||= args.shift
71 o[:tail_kind] = self.kind
74 return all_metadata.select do |m|
79 if (v.respond_to?(:uuid) ? v.uuid : v.to_s) != (test_v.respond_to?(:uuid) ? test_v.uuid : test_v.to_s)
87 @metadata = $orvos_api_client.api Metadatum, '', { _method: 'GET', where: o, eager: true }
88 @metadata = $orvos_api_client.unpack_api_response(@metadata)
91 return @all_metadata if @all_metadata
92 res = $orvos_api_client.api Metadatum, '', {
100 @all_metadata = $orvos_api_client.unpack_api_response(res)
103 raise "No such object" if !uuid
104 $orvos_api_client.api(self, '/' + uuid).each do |k,v|
105 self.instance_variable_set('@' + k.to_s, v)