Return-Path: X-Original-To: apmail-deltacloud-commits-archive@www.apache.org Delivered-To: apmail-deltacloud-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7E65F9792 for ; Thu, 14 Mar 2013 18:19:04 +0000 (UTC) Received: (qmail 76049 invoked by uid 500); 14 Mar 2013 18:19:04 -0000 Delivered-To: apmail-deltacloud-commits-archive@deltacloud.apache.org Received: (qmail 76004 invoked by uid 500); 14 Mar 2013 18:19:04 -0000 Mailing-List: contact commits-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 commits@deltacloud.apache.org Received: (qmail 75848 invoked by uid 99); 14 Mar 2013 18:19:04 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 Mar 2013 18:19:04 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 0B87916D94; Thu, 14 Mar 2013 18:19:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: lutter@apache.org To: commits@deltacloud.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [7/15] git commit: DB Entity: make sure we instantiate the correct subclass Message-Id: <20130314181904.0B87916D94@tyr.zones.apache.org> Date: Thu, 14 Mar 2013 18:19:03 +0000 (UTC) DB Entity: make sure we instantiate the correct subclass We only ever instantiated Database::Entity, but never any of its subclasses. We now keep a map of CIMI::Model => Database::Entity subclass and call new on the appropriate subclass of Entity. Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/d86e0667 Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/d86e0667 Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/d86e0667 Branch: refs/heads/master Commit: d86e0667c2881186750dbcc0d5116d3e8e965f56 Parents: 7f53cad Author: David Lutterkort Authored: Mon Mar 11 15:39:50 2013 -0700 Committer: David Lutterkort Committed: Wed Mar 13 17:28:13 2013 -0700 ---------------------------------------------------------------------- server/lib/db/entity.rb | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/deltacloud/blob/d86e0667/server/lib/db/entity.rb ---------------------------------------------------------------------- diff --git a/server/lib/db/entity.rb b/server/lib/db/entity.rb index 45a7f30..7f32161 100644 --- a/server/lib/db/entity.rb +++ b/server/lib/db/entity.rb @@ -44,6 +44,7 @@ module Deltacloud end def after_initialize + super if ent_properties self.properties = JSON::parse(ent_properties) else @@ -61,11 +62,25 @@ module Deltacloud entity = Provider::lookup.entities_dataset.first(h) unless entity h[:provider_id] = Provider::lookup.id - entity = Entity.new(h) + entity = @@model_entity_map[model.class].new(h) end entity end + def self.inherited(subclass) + super + # Build a map from CIMI::Model class to Entity subclass. This only + # works if the two classes have the same name in their respective + # modules. + # The map is used to determine what Entity subclass to instantiate + # for a given model in +retrieve+ + @@model_entity_map ||= Hash.new(Entity) + n = subclass.name.split('::').last + if k = CIMI::Model::const_get(n) + @@model_entity_map[k] = subclass + end + end + private def self.model_hash(model) { :be_kind => model.class.name,