Sha256: 70b9f545e4b50ac7075beeaea637054528daf436db0ac8eac9012560ee320cbb

Contents?: true

Size: 1.78 KB

Versions: 4

Compression:

Stored size: 1.78 KB

Contents

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

module RTM::AR
  class Construct < TMDelegator
    include RTM::Construct

    def self.abstract_class?
      self == Construct
    end
    property_set :item_identifiers, :aka => [:ii, :iid, :source_locators], :type => :ItemIdentifier, :wrap => true,
      #:create => :item_identifier, :create_aka => :cii
      :add => true, :remove => true
    alias :getItemIdentifiers :item_identifiers
    
    delegate :remove, :to => :destroy

    delegate :id
    #    property_parent :parent # mmh..

    property :topic_map, :rw => true, :type => :TopicMap, :wrap => true

    #class_delegate :create

    def self.wrap(obj)
      return nil unless obj
      raise "Double wrapping" if obj.respond_to?(:__getobj__)
      case obj.class.name
      when "RTM::AR::TMDM::Topic"
        Topic.wrap(obj)
      when "RTM::AR::TMDM::Variant"
        Variant.wrap(obj)
      when "RTM::AR::TMDM::Name"
        Name.wrap(obj)
      when "RTM::AR::TMDM::Occurrence"
        Occurrence.wrap(obj)
      when "RTM::AR::TMDM::Association"
        Association.wrap(obj)
      when "RTM::AR::TMDM::Role"
        Role.wrap(obj)
      when "RTM::AR::TMDM::TopicMap"
        TopicMap.wrap(obj)
      else
        raise "Can't wrap object. Class for wrapping #{obj.class} unknown (object: #{obj})"
      end
    end
    
    def self.find(*args)
      res = RTM::AR::TMDM.const_get(name.split("::").last).find(*args)
      if res.respond_to? :each
        Constructs.wrap(res)
      else
        Construct.wrap(res)
      end
    end
  end

  class Reifiable < Construct
    include RTM::Reifiable

    def self.abstract_class?
      self == Reifiable
    end
    property :reifier, :type => :Topic, :rw => :true, :wrap => true
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rtm-activerecord-0.3.1 lib/rtm/activerecord/tm_construct.rb
rtm-activerecord-0.3.0 lib/rtm/activerecord/tm_construct.rb
rtm-activerecord-0.2.1 lib/rtm/activerecord/tm_construct.rb
rtm-activerecord-0.2.0 lib/rtm/activerecord/tm_construct.rb