Try to replace:
instance = model.entities.add_instance(component_definition, Geom::Transformation.new)
by
model.place_component component_definition, false
as @dezmo suggested in this post Insert dynamic component from the component folder by a plugin - #6 by dezmo
(edited following @dezmo post below)