Module: MongoTree::Strategies::MaterializedPath
- Includes:
- Base
- Defined in:
- lib/mongo_tree/strategies/materialized_path.rb
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mongo_tree/strategies/materialized_path.rb', line 6 def self.included(base) base.class_eval do class << self attr_accessor :mongo_tree_options end @mongo_tree_options = { :path_attribute => :id, :path_delimiter => ',' }.merge(@mongo_tree_options) key :path, String, :index => true key :depth, Integer, :default => 0 validates_presence_of @mongo_tree_options[:path_attribute].to_sym before_save :update_path_and_depth, :if => Proc.new{ |doc| doc.changes.has_key? "path" } after_save :update_children, :if => Proc.new{ |doc| doc.changes.has_key? "path" } end base.extend ClassMethods base.send :include, InstanceMethods end |