Changeset 6

Show
Ignore:
Timestamp:
08/09/06 17:24:18 (2 years ago)
Author:
jcm
Message:

#4 exceptions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/better_nested_set.rb

    r4 r6  
    5959      # Usage is to name them 'lft' and 'rgt' for instance. 
    6060      # 
    61       module ClassMethods                       
     61      module ClassMethods                 
    6262        # Configuration options are: 
    6363        # 
     
    8787          class_inheritable_reader :acts_as_nested_set_options 
    8888         
    89           attr_accessor acts_as_nested_set_options[:left_column].intern, acts_as_nested_set_options[:right_column].intern 
     89          # no bulk assignment 
     90          attr_protected  acts_as_nested_set_options[:left_column].intern, 
     91                          acts_as_nested_set_options[:right_column].intern, 
     92                          acts_as_nested_set_options[:parent_column].intern 
     93          # no assignment to structure fields 
     94          module_eval <<-"end_eval", __FILE__, __LINE__ 
     95            def #{acts_as_nested_set_options[:left_column]}=(x) 
     96              raise ActiveRecord::ActiveRecordError, "Unauthorized assignment to #{acts_as_nested_set_options[:left_column]}: it's an internal field handled by acts_as_nested_set code, use move_to_* methods instead." 
     97            end 
     98            def #{acts_as_nested_set_options[:right_column]}=(x) 
     99             raise ActiveRecord::ActiveRecordError, "Unauthorized assignment to #{acts_as_nested_set_options[:right_column]}: it's an internal field handled by acts_as_nested_set code, use move_to_* methods instead." 
     100            end 
     101            def #{acts_as_nested_set_options[:parent_column]}=(x) 
     102             raise ActiveRecord::ActiveRecordError, "Unauthorized assignment to #{acts_as_nested_set_options[:parent_column]}: it's an internal field handled by acts_as_nested_set code, use move_to_* methods instead." 
     103            end 
     104          end_eval 
    90105         
    91106          include SymetrieCom::Acts::NestedSet::InstanceMethods 
     
    153168 
    154169          if child.root? 
    155             raise "Adding sub-tree isn\'t currently supported" 
     170            raise ActiveRecord::ActiveRecordError, "Adding sub-tree isn\'t currently supported" 
    156171          else 
    157172            if ( (self[acts_as_nested_set_options[:left_column]] == nil) || (self[acts_as_nested_set_options[:right_column]] == nil) ) 
     
    282297        protected  
    283298        def move_to(target, position) 
    284           raise ActiveRecordError, "You cannot move a new node" if self.id.nil? 
     299          raise ActiveRecord::ActiveRecordError, "You cannot move a new node" if self.id.nil? 
    285300         
    286301          # use shorter names for readability: current left and right 
     
    298313          # detect impossible move 
    299314          if ((cur_left <= target_left) && (target_left <= cur_right)) or ((cur_left <= target_right) && (target_right <= cur_right)) 
    300             raise ActiveRecordError, "Impossible move, target node cannot be inside moved tree." 
     315            raise ActiveRecord::ActiveRecordError, "Impossible move, target node cannot be inside moved tree." 
    301316          end 
    302317         
     
    327342            end 
    328343          else 
    329             raise ActiveRecordError, "Position should be either left or right ('#{position}' received)." 
     344            raise ActiveRecord::ActiveRecordError, "Position should be either left or right ('#{position}' received)." 
    330345          end 
    331346