Permalink
Browse files

code from existing svn repo

  • Loading branch information...
ffmike committed Sep 27, 2008
0 parents commit 91a7fb680353b1dc832cdfe69dba60909b14a34b
Showing with 1,073 additions and 0 deletions.
  1. +14 −0 CHANGELOG
  2. +137 −0 README
  3. +24 −0 Rakefile
  4. +2 −0 init.rb
  5. +446 −0 lib/acts_as_ordered_tree.rb
  6. +3 −0 lib/person.rb
  7. +15 −0 test/abstract_unit.rb
  8. +413 −0 test/acts_as_ordered_tree_test.rb
  9. +11 −0 test/database.yml
  10. +8 −0 test/schema.rb
@@ -0,0 +1,14 @@
+
+v.1.2 - Wed May 17 2007
+ - renamed syblings to siblings
+ - renamed self_and_syblings to self_and_siblings
+ - some other minor code changes
+ - updated tests
+
+ Note:
+ I attempted to rewrite the tests using fixtures,
+ but some of the tests were failing.
+ I presume this is due to fixtures not supporting
+ nested transactions. The results of this effort
+ can be found in the fixtures_not_working/ branch.
+
137 README
@@ -0,0 +1,137 @@
+= ActsAsOrderedTree
+ v.1.2
+ +----+-----------+----------+---------+
+ node_1 | id | parent_id | position | name |
+ \_ node_2 +----+-----------+----------+---------+
+ \_ node_3 | 1 | 0 | 1 | Node_1 |
+ | \_ node_4 | 2 | 1 | 1 | Node_2 |
+ | \_ node_5 | 3 | 1 | 2 | Node_3 |
+ | | \_ node_8 | 4 | 3 | 1 | Node_4 |
+ | | \_ node_9 | 5 | 3 | 2 | Node_5 |
+ | \_ node_10 | 6 | 1 | 3 | Node_6 |
+ | \_ node_11 | 7 | 1 | 4 | Node_7 |
+ \_ node_6 | 8 | 5 | 1 | Node_8 |
+ \_ node_7 | 9 | 5 | 2 | Node_9 |
+ | | 10 | 3 | 3 | Node_10 |
+ | | 11 | 3 | 4 | Node_11 |
+ node_12 | 12 | 0 | 2 | Node_12 |
+ \_ node_13 | 13 | 12 | 1 | Node_13 |
+ \_ node_14 | 14 | 12 | 2 | Node_14 |
+ | \_ node_15 | 15 | 14 | 1 | Node_15 |
+ | \_ node_16 | 16 | 14 | 2 | Node_16 |
+ | | \_ node_19 | 17 | 12 | 3 | Node_17 |
+ | | \_ node_20 | 18 | 12 | 4 | Node_18 |
+ | \_ node_21 | 19 | 16 | 1 | Node_19 |
+ | \_ node_22 | 20 | 16 | 2 | Node_20 |
+ \_ node_17 | 21 | 14 | 3 | Node_21 |
+ \_ node_18 | 22 | 14 | 4 | Node_22 |
+ +----+-----------+----------+---------+
+
+
+ class Person < ActiveRecord::Base
+ acts_as_ordered_tree :foreign_key => :parent_id,
+ :order => :position
+ end
+
+ class CreatePeople < ActiveRecord::Migration
+ def self.up
+ create_table :people do |t|
+ t.column :parent_id ,:integer ,:null => false ,:default => 0
+ t.column :position ,:integer
+ end
+ add_index(:people, :parent_id)
+ end
+ end
+
+ Which "in effect" sets up the following:
+
+ belongs_to :parent,
+ :class_name => Person,
+ :foreign_key => :parent_id
+
+ has_many :children,
+ :class_name => Person,
+ :foreign_key => :parent_id,
+ :order => :position
+
+
+
+= Overview
+
+ Actions Tree Methods List Method
+ --------------------------------------------------------------------------------------------------
+ Create
+ To create a child object at a specific position,
+ use one of the following:
+ Person.create(:parent_id => parent.id, :position => 2)
+ parent.children << Person.new(:position => 3)
+ parent.children.create(:position => 5)
+
+ To create a new 'root', use:
+ Person.create(:position => 2)
+
+ :position will default to the bottom of the parent's list
+ :parent_id defaults to 0 (Class.roots)
+
+ Read
+ roots (class method) self_and_siblings
+
+ root siblings
+
+ parent position_in_list
+
+ ancestors
+
+ children
+
+ descendants
+
+ Update
+ shift_to(parent = nil, position = nil) move_above(sibling = nil)
+
+ orphan move_higher
+
+ orphan_children move_lower
+
+ parent_adopts_children move_to_top
+
+ orphan_self_and_children move_to_bottom
+
+ orphan_self_and_parent_adopts_children
+
+ Destroy
+ destroy (deletes all descendants)
+
+ destroy_and_orphan_children
+
+ destroy_and_parent_adopts_children
+
+= Install
+
+ ./script/plugin install svn://rubyforge.org/var/svn/ordered-tree/acts_as_ordered_tree
+
+ To test, run 'rake test:plugins', or 'rake' from the plugin's directory.
+
+ There is a drag-n-drop demo located at svn://rubyforge.org/var/svn/ordered-tree/demo
+
+= License
+
+Copyright (c) 2006,2007 Brian D. Burns <wizard.rb@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
@@ -0,0 +1,24 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/clean'
+require 'rake/rdoctask'
+
+desc 'Default: run acts_as_ordered_tree unit tests.'
+task :default => :test
+
+desc 'Test the acts_as_ordered_tree plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the acts_as_ordered_tree plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'ActsAsOrderedTree'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+ rdoc.rdoc_files.exclude('lib/person.rb')
+end
@@ -0,0 +1,2 @@
+require File.dirname(__FILE__) + '/lib/acts_as_ordered_tree'
+ActiveRecord::Base.send(:include, WizardActsAsOrderedTree::Acts::OrderedTree)
Oops, something went wrong.

0 comments on commit 91a7fb6

Please sign in to comment.