Class: InterMine::PathQuery::SubClassConstraint

Inherits:
Object
  • Object
show all
Includes:
PathFeature
Defined in:
lib/intermine/query.rb

Instance Attribute Summary collapse

Attributes included from PathFeature

#path

Instance Method Summary collapse

Instance Attribute Details

#sub_classObject

Returns the value of attribute sub_class.



985
986
987
# File 'lib/intermine/query.rb', line 985

def sub_class
  @sub_class
end

Instance Method Details

#to_elemObject



987
988
989
990
991
992
993
994
995
# File 'lib/intermine/query.rb', line 987

def to_elem
    attributes = {
        "path" => @path,
        "type" => @sub_class
    }
    elem = REXML::Element.new("constraint")
    elem.add_attributes(attributes)
    return elem
end

#validateObject



997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
# File 'lib/intermine/query.rb', line 997

def validate 
    if @path.elements.last.is_a?(InterMine::Metadata::AttributeDescriptor)
        raise ArgumentError, "#{self.class.name}s must be on objects or references to objects"
    end
    if @sub_class.length > 1
        raise ArgumentError, "#{self.class.name} expects sub-classes to be named as bare class names"
    end
    model = @path.model
    cdA = model.get_cd(@path.end_type)
    cdB = model.get_cd(@sub_class.end_type)
    unless ((cdB == cdA) or cdB.subclass_of?(cdA))
        raise ArgumentError, "The subclass in a #{self.class.name} must be a subclass of its path, but #{cdB} is not a subclass of #{cdA}"
    end

end