On Sep 6, 2012, at 1:30 AM, David Lutterkort <[email protected]> wrote:
> On Wed, 2012-09-05 at 15:15 +0200, [email protected] wrote: >> From: Michal Fojtik <[email protected]> >> >> * This should fix DTACLOUD-311 >> >> Signed-off-by: Michal fojtik <[email protected]> >> --- >> server/lib/cimi/models/schema.rb | 6 ++---- >> 1 file changed, 2 insertions(+), 4 deletions(-) >> >> diff --git a/server/lib/cimi/models/schema.rb >> b/server/lib/cimi/models/schema.rb >> index 088e111..a7dc0f2 100644 >> --- a/server/lib/cimi/models/schema.rb >> +++ b/server/lib/cimi/models/schema.rb >> @@ -140,11 +140,9 @@ class CIMI::Model::Schema >> def struct >> cname = "CIMI_#{json_name.upcase_first}" >> if ::Struct.const_defined?(cname) >> - ::Struct.const_get(cname) >> - else >> - ::Struct.new("CIMI_#{json_name.upcase_first}", >> - *@schema.attribute_names) >> + ::Struct.send(:remove_const, "CIMI_#{json_name.upcase_first}") >> end >> + ::Struct.new("CIMI_#{json_name.upcase_first}", >> *@schema.attribute_names) > > Nice catch - instead of defining a constant Struct::Foo and then > undefining it, and continually defining new classes, we should just save > it in an instance variable, i.e. do the following > > def struct > @struct_class ||= Struct.new(nil, *@schema.attribute_names) > end Cool, that can work too. Also we can use OpenStruct class if we don't want to use name for the struct. Do you want me to send a new rev with instance variable? -- Michal Michal Fojtik http://deltacloud.org [email protected]
