app/models/taxonomy_term.rb in daengine-0.4.6 vs app/models/taxonomy_term.rb in daengine-0.4.6.2
- old
+ new
@@ -1,21 +1,17 @@
require 'mongoid'
-require 'memoist'
class TaxonomyTerm
-
include Mongoid::Document
include Mongoid::Timestamps
field :label, type: String
field :term_id, type: String
field :term_type, :type => Hash, :default => {}
key :term_id
-
# index "term_type.FUND_CODE", sparse: true
-
has_and_belongs_to_many :child_terms, :class_name => 'TaxonomyTerm', :inverse_of => :parent_term
belongs_to :parent_term, :class_name => 'TaxonomyTerm', :inverse_of => :child_terms
#validations
validates_presence_of :term_id, :label
@@ -29,17 +25,16 @@
def self.purge!
TaxonomyTerm.destroy_all
end
def self.label_for_term(term_id)
- find_term_by_id(term_id).try(:label)
+ where(term_id: term_id).try(:first).try(:label) if term_id
end
-
+
def self.find_term_by_id(term_id)
self.term_id_is(term_id).try(:first)
end
- class << self; extend Memoist; self; end.memoize :find_term_by_id
def fund_code
term_type['FUND_CODE']
end
@@ -56,7 +51,6 @@
term_id = term.is_a?(String) ? term : term.try(:term_id)
# loop thru child terms and look for the id
child_term_ids.index(term_id) or child_terms.detect {|c| c.descendant? term_id }
end
-
end