deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michal Fojtik <mfoj...@redhat.com>
Subject Re: [PATCH core 2/2] CIMI: Moved helper methods out of db.rb to separe helper file
Date Tue, 11 Dec 2012 11:04:17 GMT
On 12/10, David Lutterkort wrote:
> I needed to make a small change:

Yes, sorry for that. I found it when I get home, but you was faster :)

  -- Michal

> 
> On Mon, 2012-12-10 at 11:11 +0100, mfojtik@redhat.com wrote:
> > diff --git a/server/lib/cimi/helpers/database_helper.rb b/server/lib/cimi/helpers/database_helper.rb
> > new file mode 100644
> > index 0000000..d6aa55b
> > --- /dev/null
> > +++ b/server/lib/cimi/helpers/database_helper.rb
> > @@ -0,0 +1,46 @@
> > +module Deltacloud
> > +  module Helpers
> > +
> > +    module Database
> > +
> > +      def test_environment?
> > +        Deltacloud.test_environment?
> > +      end
> > +
> > +      def store_attributes_for(model, values={})
> > +        return if test_environment?
> > +        return if model.nil? or values.empty?
> > +        current_db.entities.first_or_create(:be_kind => model.to_entity, :be_id
=> model.id).update(values)
> > +      end
> > +
> > +      def load_attributes_for(model)
> > +        return {} if test_environment?
> > +        entity = get_entity(model)
> > +        entity.nil? ? {} : entity.to_hash
> > +      end
> > +
> > +      def delete_attributes_for(model)
> > +        return if test_environment?
> > +        entity = get_entity(model)
> > +        !entity.nil? && entity.destroy!
> > +      end
> > +
> > +      def get_entity(model)
> > +        current_db.entities.first(:be_kind => model.to_entity, :be_id =>
model.id)
> > +      end
> > +
> > +      def current_provider
> > +        Thread.current[:provider] || ENV['API_PROVIDER'] || 'default'
> > +      end
> > +
> > +      # This method allows to store things into database based on current driver
> > +      # and provider.
> > +      #
> > +      def current_db
> > +        Provider.first_or_create(:driver => driver_symbol.to_s, :url => current_provider)
> > +      end
> 
> Had to qualify Provider as Deltacloud::Database::Provider for this to
> work; pushed as e6c46db6
> 
> David
> 
> 

-- 
Michal Fojtik <mfojtik@redhat.com>
Deltacloud API, CloudForms

Mime
View raw message