Module: PathFinder
- Defined in:
- lib/path_finder.rb
Overview
Usage: path_finder :column => ‘path’, :uid => ‘to_param’, :deliminator => ‘/’
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Instance Method Summary collapse
Instance Method Details
#path_finder(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/path_finder.rb', line 9 def path_finder( = {}) raise "Options for path_finder must be a Hash" unless .is_a? Hash .each do |key, value| unless [:column, :uid, :deliminator].include? key raise "Unknown option for path_finder: #{key.inspect} => #{value.inspect}." end end send :include, InstanceMethods send :extend, ClassMethods = { :column => 'path', :uid => 'to_param', :deliminator => '/' }.merge() # Create class attributes for options and set defaults self.cattr_accessor :path_finder_column self.path_finder_column = [:column] #|| 'path' self.cattr_accessor :path_finder_uid self.path_finder_uid = [:uid] #|| 'to_param' self.cattr_accessor :path_finder_deliminator self.path_finder_deliminator = [:deliminator] #|| '/' before_validation_on_create :set_path validates_presence_of self.path_finder_column.to_sym if [:set_depth] # add before_save to set depth column end end |