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


1077
1078
1079
# File 'lib/intermine/query.rb', line 1077

def sub_class
  @sub_class
end

Instance Method Details

#to_elemObject


1079
1080
1081
1082
1083
1084
1085
1086
1087
# File 'lib/intermine/query.rb', line 1079

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

#validateObject


1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
# File 'lib/intermine/query.rb', line 1089

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