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.



1081
1082
1083
# File 'lib/intermine/query.rb', line 1081

def sub_class
  @sub_class
end

Instance Method Details

#to_elemObject



1083
1084
1085
1086
1087
1088
1089
1090
1091
# File 'lib/intermine/query.rb', line 1083

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

#validateObject



1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
# File 'lib/intermine/query.rb', line 1093

def validate 
    if @path.elements.last.is_a?(InterMine::::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