Sha256: e650659af5726926471849b8671819ed997c3862fbc334002d46d9513fc69abc

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

# Copyright: Copyright 2009 Topic Maps Lab, University of Leipzig.
# License:   Apache License, Version 2.0

module RTM::Sugar::TopicMap
  module Remove

    # Removes all variants, names, occurrences, roles, asssociations and
    # topics (esp. reifier) from this topic map.
    def clear
      # This is supported by some backends (e.g. Ontopia) and should be faster than the procedure below.
      if self.respond_to?(:wrapped) && self.wrapped.respond_to?(:clear)
        self.wrapped.clear
        return
      end

      raise("should not be called on majortom topic maps") if self.respond_to?(:store)
      
      set_reifier(nil)

      variants.to_a.each do |v|
        v.set_reifier(nil)
        v.remove
      end

      names.to_a.each do |n|
        n.set_reifier(nil)
        n.remove
      end

      occurrences.to_a.each do |o|
        o.set_reifier(nil)
        o.remove
      end

      roles.to_a.each do |r|
        r.set_reifier(nil)
        # Roles should not be removed here! They are removed when the association is removed
        #r.remove
      end

      associations.to_a.each do |a|
        a.set_reifier(nil)
        a.remove
      end

      types.to_a.each do |type|
        type.instances.to_a.each do |instance|
          instance.remove_type(type)
        end
      end

      topics.to_a.each do |t|
        t.remove
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rtm-0.3.1 lib/rtm/sugar/topic_map/remove.rb