A base class for all Taxonifi::Models that represent “individuals” (as opposed to collections of indviduals).
Optionally store an id representing the original id usef for this record.
The id of this object.
Optionly store the row this came from
The ids only of ancestors. Immediate ancestor id is in [].last
# File lib/models/base.rb, line 31 def ancestor_ids i = 0 # check for recursion ids = [] p = parent while !p.nil? ids.unshift p.id p = p.parent i += 1 raise Taxonifi::ModelError, "Infite recursion in parent string detected for Base model object #{id}." if i > 100 end ids end
Ancestor objects for subclasses that have a parent property. TODO: check for parent attributes
# File lib/models/base.rb, line 47 def ancestors i = 0 # check for recursion ancestors = [] p = parent while !p.nil? ancestors.unshift p p = p.parent i += 1 raise Taxonifi::ModelError, "Infite recursion in parent string detected for Base model object #{id.display_name}." if i > 100 end ancestors end
Assign on new() all attributes for the ATTRIBUTES constant in a given subclass. !! Check validity prior to building.
# File lib/models/base.rb, line 18 def build(attributes, opts) attributes.each do |c| self.send("#{c}=",opts[c]) if !opts[c].nil? end end
# File lib/models/base.rb, line 24 def id=(id) raise Taxonifi::ModelError, "Base model objects must have Fixnum ids." if !id.nil? && id.class != Fixnum @id = id end
Determines identity base ONLY on attributes in ATTRIBUTES.
# File lib/models/base.rb, line 62 def identical?(obj) raise Taxonifi::ModelError, "Objects are not comparible." if obj.class != self.class self.class::ATTRIBUTES.each do |a| next if a == :id # don't compare return false if obj.send(a) != self.send(a) end return true end