Class: InterMine::Metadata::Path
- Inherits:
-
Object
- Object
- InterMine::Metadata::Path
- Defined in:
- lib/intermine/model.rb
Overview
A representation of a path through the data model, starting at a table/class, and descending ultimately to an attribute. A path represents a valid sequence of joins and column accesses according to the webservice’s database schema.
In string format, a path can be represented using dotted notation:
Gene.proteins.proteinDomains.name
Which is a valid path through the data-model, starting in the gene table, following a reference to the protein table (via x-to-many relationship) and then to the protein-domain table and then finally to the name column in the protein domain table. Joins are implicitly implied.
:include:contact_header.rdoc
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
The objects represented by each section of the path.
-
#model ⇒ Object
readonly
The data model that this path describes.
-
#rootClass ⇒ Object
readonly
The root class of this path.
-
#subclasses ⇒ Object
readonly
The subclass information used to create this path.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two paths can be said to be equal when they stringify to the same representation.
-
#end_cd ⇒ Object
call-seq: end_cd => ClassDescriptor.
-
#end_type ⇒ Object
call-seq: end_type => String.
-
#initialize(pathstring, model = nil, subclasses = {}) ⇒ Path
constructor
Construct a Path.
-
#is_attribute? ⇒ Boolean
Return true if the Path ends in an attribute.
-
#is_class? ⇒ Boolean
Return true if the last element is a class (ie. a path of length 1).
-
#is_collection? ⇒ Boolean
Return true if the last element is a collection.
-
#is_reference? ⇒ Boolean
Return true if the last element is a reference.
-
#length ⇒ Object
Get the number of elements in the path.
-
#to_headless_s ⇒ Object
Returns a string as to_s without the first element.
-
#to_s ⇒ Object
Return the string representation of this path, eg: “Gene.proteins.name”.
Constructor Details
#initialize(pathstring, model = nil, subclasses = {}) ⇒ Path
Construct a Path
The standard mechanism is to parse a string representing a path with information about the model and the subclasses that are in force. However, it is also possible to clone a path by passing a Path through as the first element, and also to construct a path from a ClassDescriptor. In both cases the new Path will inherit the model of the object used to construct it, this avoid the need for a model in these cases.
749 750 751 752 753 754 755 |
# File 'lib/intermine/model.rb', line 749 def initialize(pathstring, model=nil, subclasses={}) @model = model @subclasses = subclasses @elements = [] @rootClass = nil parse(pathstring) end |
Instance Attribute Details
#elements ⇒ Object (readonly)
The objects represented by each section of the path. The first is always a ClassDescriptor.
732 733 734 |
# File 'lib/intermine/model.rb', line 732 def elements @elements end |
#model ⇒ Object (readonly)
The data model that this path describes.
729 730 731 |
# File 'lib/intermine/model.rb', line 729 def model @model end |
#rootClass ⇒ Object (readonly)
The root class of this path. This is the same as the first element.
738 739 740 |
# File 'lib/intermine/model.rb', line 738 def rootClass @rootClass end |
#subclasses ⇒ Object (readonly)
The subclass information used to create this path.
735 736 737 |
# File 'lib/intermine/model.rb', line 735 def subclasses @subclasses end |
Instance Method Details
#==(other) ⇒ Object
Two paths can be said to be equal when they stringify to the same representation.
804 805 806 |
# File 'lib/intermine/model.rb', line 804 def ==(other) return self.to_s == other.to_s end |
#end_cd ⇒ Object
call-seq:
end_cd => ClassDescriptor
Return the last ClassDescriptor mentioned in this path. eg:
Gene-
Gene
Gene.symbol-
Gene
Gene.proteins-
Protein
Gene.proteins.name-
Protein
787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 |
# File 'lib/intermine/model.rb', line 787 def end_cd last = @elements.last if last.is_a?(ClassDescriptor) return last elsif last.respond_to?(:referencedType) return last.referencedType else penult = @elements[-2] if penult.is_a?(ClassDescriptor) return penult else return penult.referencedType end end end |
#end_type ⇒ Object
call-seq:
end_type => String
Return the string that describes the kind of thing this path represents. eg:
Gene-
“Gene”
Gene.symbol-
“java.lang.String”
Gene.proteins-
“Protein”
766 767 768 769 770 771 772 773 774 775 |
# File 'lib/intermine/model.rb', line 766 def end_type last = @elements.last if last.is_a?(ClassDescriptor) return last.name elsif last.respond_to?(:referencedType) return last.referencedType.name else return last.dataType end end |
#is_attribute? ⇒ Boolean
Return true if the Path ends in an attribute
824 825 826 |
# File 'lib/intermine/model.rb', line 824 def is_attribute? return @elements.last.is_a?(AttributeDescriptor) end |
#is_class? ⇒ Boolean
Return true if the last element is a class (ie. a path of length 1)
829 830 831 |
# File 'lib/intermine/model.rb', line 829 def is_class? return @elements.last.is_a?(ClassDescriptor) end |
#is_collection? ⇒ Boolean
Return true if the last element is a collection
839 840 841 |
# File 'lib/intermine/model.rb', line 839 def is_collection? return @elements.last.is_a?(CollectionDescriptor) end |
#is_reference? ⇒ Boolean
Return true if the last element is a reference.
834 835 836 |
# File 'lib/intermine/model.rb', line 834 def is_reference? return @elements.last.is_a?(ReferenceDescriptor) end |
#length ⇒ Object
Get the number of elements in the path
809 810 811 |
# File 'lib/intermine/model.rb', line 809 def length return @elements.length end |
#to_headless_s ⇒ Object
Returns a string as to_s without the first element. eg: “proteins.name”
819 820 821 |
# File 'lib/intermine/model.rb', line 819 def to_headless_s return @elements[1, @elements.size - 1].map {|x| x.name}.join(".") end |
#to_s ⇒ Object
Return the string representation of this path, eg: “Gene.proteins.name”
814 815 816 |
# File 'lib/intermine/model.rb', line 814 def to_s return @elements.map {|x| x.name}.join(".") end |