Class methods added to the model that has been made acts_as_annotatable (ie: the mixin annotatable type).
Helper finder to get all annotations for all objects of the mixin annotatable type, by the source specified. E.g: Book.find_annotations_by(‘User’, 10) will give all annotations for all Books by User with ID 10.
# File lib/annotations/acts_as_annotatable.rb, line 55 55: def find_annotations_by(source_type, source_id) 56: obj_type = ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s 57: 58: Annotation.find(:all, 59: :conditions => { :annotatable_type => obj_type, 60: :source_type => source_type, 61: :source_id => source_id }, 62: :order => "created_at DESC") 63: end
Helper finder to get all annotations for an object of the mixin annotatable type with the ID provided. This is the same as object.annotations with the added benefit that the object doesnt have to be loaded. E.g: Book.find_annotations_for(34) will give all annotations for the Book with ID 34.
# File lib/annotations/acts_as_annotatable.rb, line 44 44: def find_annotations_for(id) 45: obj_type = ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s 46: 47: Annotation.find(:all, 48: :conditions => { :annotatable_type => obj_type, 49: :annotatable_id => id }, 50: :order => "created_at DESC") 51: end
Helper finder to get all objects of the mixin annotatable type that have the specified attribute name and value.
NOTE (1): both the attribute name and the value will be treated case insensitively.
# File lib/annotations/acts_as_annotatable.rb, line 27 27: def with_annotations_with_attribute_name_and_value(attribute_name, value) 28: return [ ] if attribute_name.blank? or value.nil? 29: 30: obj_type = ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s 31: 32: anns = Annotation.find(:all, 33: :joins => :attribute, 34: :conditions => { :annotatable_type => obj_type, 35: :annotation_attributes => { :name => attribute_name.strip.downcase }, 36: :value => value.strip.downcase }) 37: 38: return anns.map{|a| a.annotatable} 39: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.