74: def acts_as_nested_set(options = {})
75: if options[:scope].is_a?(Symbol)
76: if options[:scope].to_s !~ /_id$/
77: options[:scope] = "#{options[:scope]}_id".intern
78: end
79: options[:scope] = %(#{options[:scope].to_s}.nil? ? "#{options[:scope].to_s} IS NULL" : "#{options[:scope].to_s} = \#{#{options[:scope].to_s}}")
80: end
81:
82:
83:
84: write_inheritable_attribute(:acts_as_nested_set_options,
85: { :parent_column => (options[:parent_column] || 'parent_id'),
86: :left_column => (options[:left_column] || 'lft'),
87: :right_column => (options[:right_column] || 'rgt'),
88: :scope => (options[:scope] || '1 = 1'),
89: :text_column => (options[:text_column] || columns.collect{|c| (c.type == :string) ? c.name : nil }.compact.first)
90: } )
91:
92: class_inheritable_reader :acts_as_nested_set_options
93:
94:
95: attr_protected acts_as_nested_set_options[:left_column].intern,
96: acts_as_nested_set_options[:right_column].intern,
97: acts_as_nested_set_options[:parent_column].intern
98:
99: module_eval "def \#{acts_as_nested_set_options[:left_column]}=(x)\nraise 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.\"\nend\ndef \#{acts_as_nested_set_options[:right_column]}=(x)\nraise 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.\"\nend\ndef \#{acts_as_nested_set_options[:parent_column]}=(x)\nraise 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.\"\nend\n", __FILE__, __LINE__
100:
101: include SymetrieCom::Acts::NestedSet::InstanceMethods
102: extend SymetrieCom::Acts::NestedSet::ClassMethods
103:
104:
105:
106:
107:
108:
109: end