Remove snippet

This commit is contained in:
chris2tof committed 2011-12-05 10:27:22 +08:00
1 parent f3f405c1b4
commit 962bf03af2
5 files changed
-123

No files matched your search

-38
View File
@@ -1,38 +0,0 @@
class Snippet
include Mongoid::Document
include Mongoid::Timestamps
field :name, :index => true
field :full_name, :index => true
field :parent_id, :index => true
field :parent_name
field :content
before_validation :setup_default_value
validates_presence_of :name, :full_name, :parent_id
validates_uniqueness_of :name, :scope => :parent_id
referenced_in :parent, :class_name => "Item", :foreign_key => :parent_id
# Get an array of ancestors
def ancestors
node, nodes = self, []
nodes << node = node.parent while !node.parent.blank? rescue nil
nodes.reverse
end
def setup_default_value
# Set the parent value
self.parent_name = Item.find( self.parent_id ).name rescue nil
# Build the full_name from the ancestors array
full_node = self.ancestors.map{ |a| a.name }.push( self.name )
# Remove root node if not root
full_node.shift if full_node.size >= 2
self.full_name = full_node.join("/")
end
end