Return-Path: X-Original-To: apmail-deltacloud-dev-archive@www.apache.org Delivered-To: apmail-deltacloud-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0D9E0D0E1 for ; Wed, 10 Oct 2012 21:42:33 +0000 (UTC) Received: (qmail 58102 invoked by uid 500); 10 Oct 2012 21:42:32 -0000 Delivered-To: apmail-deltacloud-dev-archive@deltacloud.apache.org Received: (qmail 58085 invoked by uid 500); 10 Oct 2012 21:42:32 -0000 Mailing-List: contact dev-help@deltacloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@deltacloud.apache.org Delivered-To: mailing list dev@deltacloud.apache.org Received: (qmail 58077 invoked by uid 99); 10 Oct 2012 21:42:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Oct 2012 21:42:32 +0000 X-ASF-Spam-Status: No, hits=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lutter@redhat.com designates 209.132.183.28 as permitted sender) Received: from [209.132.183.28] (HELO mx1.redhat.com) (209.132.183.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Oct 2012 21:42:25 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9ALg46C007053 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 10 Oct 2012 17:42:04 -0400 Received: from melon.watzmann.net (ovpn-113-83.phx2.redhat.com [10.3.113.83]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9ALg20C013688 for ; Wed, 10 Oct 2012 17:42:04 -0400 From: lutter@redhat.com To: dev@deltacloud.apache.org Subject: [PATCH 3/7] CIMI models: let the schema convert raw values for model objects Date: Wed, 10 Oct 2012 14:41:53 -0700 Message-Id: <1349905317-14381-4-git-send-email-lutter@redhat.com> In-Reply-To: <1349905317-14381-1-git-send-email-lutter@redhat.com> References: <1349905317-14381-1-git-send-email-lutter@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 From: David Lutterkort This is a noop for now --- server/lib/cimi/models/base.rb | 9 +++++++-- server/lib/cimi/models/schema.rb | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/server/lib/cimi/models/base.rb b/server/lib/cimi/models/base.rb index 4c9b2dc..eefa868 100644 --- a/server/lib/cimi/models/base.rb +++ b/server/lib/cimi/models/base.rb @@ -161,14 +161,19 @@ class CIMI::Model::Base end def []=(a, v) - @attribute_values[a] = v + @attribute_values[a] = self.class.schema.convert(a, v) + end end # # Factory methods # def initialize(values = {}) - @attribute_values = values + names = self.class.schema.attribute_names + @attribute_values = names.inject({}) do |hash, name| + hash[name] = self.class.schema.convert(name, values[name]) + hash + end end # Construct a new object from the XML representation +xml+ diff --git a/server/lib/cimi/models/schema.rb b/server/lib/cimi/models/schema.rb index ed3541a..e679b2e 100644 --- a/server/lib/cimi/models/schema.rb +++ b/server/lib/cimi/models/schema.rb @@ -46,6 +46,10 @@ class CIMI::Model::Schema def to_json(model, json) json[@json_name] = model[@name] if model and model[@name] end + + def convert(value) + value + end end class Scalar < Attribute @@ -222,6 +226,12 @@ class CIMI::Model::Schema @attributes = [] end + def convert(name, value) + attr = @attributes.find { |a| a.name == name } + raise "Unknown attribute #{name}" unless attr + attr.convert(value) + end + def from_xml(xml, model = {}) @attributes.freeze @attributes.each { |attr| attr.from_xml(xml, model) } -- 1.7.7.6