On Thu, 2012-09-06 at 14:39 +0200, [email protected] wrote:
> From: Michal Fojtik <[email protected]>
>
>
> Signed-off-by: Michal fojtik <[email protected]>
> ---
> server/lib/cimi/models/schema.rb | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/server/lib/cimi/models/schema.rb
> b/server/lib/cimi/models/schema.rb
> index 088e111..4aa512a 100644
> --- a/server/lib/cimi/models/schema.rb
> +++ b/server/lib/cimi/models/schema.rb
> @@ -139,12 +139,8 @@ class CIMI::Model::Schema
> private
> 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)
> - end
> + ::Struct.send(:remove_const, cname) if ::Struct.const_defined?(cname)
> + @struct_class ||= ::Struct.new(cname, *@schema.attribute_names)
Almost .. since having a name for the Struct class is useless for our
pruproses, the code should be
def struct
@struct_class ||= ::Struct.new(nil,
*@schema.attribute_names)
end
IOW, we never create a Struct::XXX name for the class, and therefore do
not need to remove it.
David