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.
717 718 719 720 721 722 723 |
# File 'lib/intermine/model.rb', line 717 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.
700 701 702 |
# File 'lib/intermine/model.rb', line 700 def elements @elements end |
#model ⇒ Object (readonly)
The data model that this path describes.
697 698 699 |
# File 'lib/intermine/model.rb', line 697 def model @model end |
#rootClass ⇒ Object (readonly)
The root class of this path. This is the same as the first element.
706 707 708 |
# File 'lib/intermine/model.rb', line 706 def rootClass @rootClass end |
#subclasses ⇒ Object (readonly)
The subclass information used to create this path.
703 704 705 |
# File 'lib/intermine/model.rb', line 703 def subclasses @subclasses end |
Instance Method Details
#==(other) ⇒ Object
Two paths can be said to be equal when they stringify to the same representation.
772 773 774 |
# File 'lib/intermine/model.rb', line 772 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
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 |
# File 'lib/intermine/model.rb', line 755 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”
734 735 736 737 738 739 740 741 742 743 |
# File 'lib/intermine/model.rb', line 734 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
792 793 794 |
# File 'lib/intermine/model.rb', line 792 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)
797 798 799 |
# File 'lib/intermine/model.rb', line 797 def is_class? return @elements.last.is_a?(ClassDescriptor) end |
#is_collection? ⇒ Boolean
Return true if the last element is a collection
807 808 809 |
# File 'lib/intermine/model.rb', line 807 def is_collection? return @elements.last.is_a?(CollectionDescriptor) end |
#is_reference? ⇒ Boolean
Return true if the last element is a reference.
802 803 804 |
# File 'lib/intermine/model.rb', line 802 def is_reference? return @elements.last.is_a?(ReferenceDescriptor) end |
#length ⇒ Object
Get the number of elements in the path
777 778 779 |
# File 'lib/intermine/model.rb', line 777 def length return @elements.length end |
#to_headless_s ⇒ Object
Returns a string as to_s without the first element. eg: “proteins.name”
787 788 789 |
# File 'lib/intermine/model.rb', line 787 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”
782 783 784 |
# File 'lib/intermine/model.rb', line 782 def to_s return @elements.map {|x| x.name}.join(".") end |