deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "marios@redhat.com" <mandr...@redhat.com>
Subject Re: [PATCH core 1/3] CIMI: Fixed inheriting schema properties in various models problem
Date Wed, 23 Nov 2011 14:12:35 GMT
ACK to all 3 patches


On 22/11/11 15:26, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mfojtik@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mfojtik@redhat.com>
> ---
>  server/lib/cimi/model/base.rb |   25 ++++++++++++++++++++-----
>  1 files changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/server/lib/cimi/model/base.rb b/server/lib/cimi/model/base.rb
> index 7cc3f49..8218fac 100644
> --- a/server/lib/cimi/model/base.rb
> +++ b/server/lib/cimi/model/base.rb
> @@ -77,20 +77,35 @@ class CIMI::Model::Base
>    # attribute, we also define a getter and a setter to access/change the
>    # value for that attribute
>    class << self
> -    def schema
> +    def base_schema
>        @schema ||= CIMI::Model::Schema.new
>      end
>  
> -    def schema=(s)
> -      @schema = s
> +    def clone_base_schema
> +      @schema_duped = true
> +      @schema = Marshal::load(Marshal.dump(superclass.base_schema))
>      end
>  
> +    def base_schema_cloned?
> +      @schema_duped
> +    end
> +
> +    private :'clone_base_schema', :'base_schema_cloned?'
> +
>      def inherited(child)
> -      child.schema = self.schema.dup
> +      child.instance_eval do
> +        def schema
> +          base_schema_cloned? ? @schema : clone_base_schema
> +        end
> +      end
>      end
>  
>      def add_attributes!(names, attr_klass, &block)
> -      schema.add_attributes!(names, attr_klass, &block)
> +      if self.respond_to? :schema
> +        schema.add_attributes!(names, attr_klass, &block)
> +      else
> +        base_schema.add_attributes!(names, attr_klass, &block)
> +      end
>        names.each do |name|
>          define_method(name) { @attribute_values[name] }
>          define_method(:"#{name}=") { |newval| @attribute_values[name] = newval }


Mime
View raw message