Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added .gitignore

Continued RDoc
  • Loading branch information...
commit 94aff79afe21d40f0f9b22972dea42274b33b534 1 parent 79671c4
@stefankroes authored
Showing with 46 additions and 45 deletions.
  1. +1 −0  .gitignore
  2. +45 −45 README.rdoc
View
1  .gitignore
@@ -0,0 +1 @@
+doc
View
90 README.rdoc
@@ -6,18 +6,18 @@ Ancestry allows the records of a ActiveRecord model to be organised in a tree st
To apply Ancestry to any ActiveRecord model, follow these simple steps:
-1. INSTALL GEM
- > Add to config/environment.rb: config.gem 'ancestry'
- > Install required gems: sudo rake gems:install
- > Alternatively: sudo gem install ancestry
+== Install Gem
+ * Add to config/environment.rb: config.gem 'ancestry'
+ * Install required gems: sudo rake gems:install
+ * Alternatively: sudo gem install ancestry
-2. ADD ANCESTRY COLUMN TO YOUR TABLE
- > Create migration: ./script/generate migration add_ancestry_to_[table] ancestry:string
- > Add index to migration: add_index [table], :ancestry / remove_index [table], :ancestry
- > Migrate your database: rake db:migrate
+== Add Ancestry Column to Your Table
+ * Create migration: ./script/generate migration add_ancestry_to_[table] ancestry:string
+ * Add index to migration: add_index [table], :ancestry / remove_index [table], :ancestry
+ * Migrate your database: rake db:migrate
-3. ADD ANCESTRY TO YOUR MODEL
- > Add to app/models/[model].rb: acts_as_tree
+== Add Ancestry to Your Model
+ * Add to app/models/[model].rb: acts_as_tree
Your model is now a tree!
@@ -31,26 +31,26 @@ TreeNode.create!(:name => 'Stinky', :parent => TreeNode.create!(:name => 'Squeek
To navigate an Ancestry model, use the following methods on any instance / record:
-parent Returns the parent of the record
-root Returns the root of the tree the record is in
-root_id Returns the id of the root of the tree the record is in
-is_root? Returns true if the record is a root node, false otherwise
-ancestor_ids Returns a list of ancestor ids, starting with the root id and ending with the parent id
-ancestors Scopes the model on ancestors of the record
-path_ids Returns a list the path ids, starting with the root is and ending with the node's own id
-path Scopes model on path records of the record
-children Scopes the model on children of the record
-child_ids Returns a list of child ids
-has_children? Returns true if the record has any children, false otherwise
-is_childless? Returns true is the record has no childen, false otherwise
-siblings Scopes the model on siblings of the record, the record itself is included
-sibling_ids Returns a list of sibling ids
-has_siblings? Returns true if the record's parent has more than one child
-is_only_child? Returns true if the record is the only child of its parent
-descendants Scopes the model on direct and indirect children of the record
-descendant_ids Returns a list of a descendant ids
-subtree Scopes the model on descendants and itself
-subtree_ids Returns a list of all ids in the record's subtree
+[parent] Returns the parent of the record
+[root] Returns the root of the tree the record is in
+[root_id] Returns the id of the root of the tree the record is in
+[is_root?] Returns true if the record is a root node, false otherwise
+[ancestor_ids] Returns a list of ancestor ids, starting with the root id and ending with the parent id
+[ancestors] Scopes the model on ancestors of the record
+[path_ids] Returns a list the path ids, starting with the root is and ending with the node's own id
+[path] Scopes model on path records of the record
+[children] Scopes the model on children of the record
+[child_ids] Returns a list of child ids
+[has_children?] Returns true if the record has any children, false otherwise
+[is_childless?] Returns true is the record has no childen, false otherwise
+[siblings] Scopes the model on siblings of the record, the record itself is included
+[sibling_ids] Returns a list of sibling ids
+[has_siblings?] Returns true if the record's parent has more than one child
+[is_only_child?] Returns true if the record is the only child of its parent
+[descendants] Scopes the model on direct and indirect children of the record
+[descendant_ids] Returns a list of a descendant ids
+[subtree] Scopes the model on descendants and itself
+[subtree_ids] Returns a list of all ids in the record's subtree
= Scopes
@@ -64,21 +64,21 @@ node.descendants.count
For convenience, a couple of named scopes are included as class level:
-root Only root nodes
-ancestor_of(node) Only ancestors of node, node can be either a record or an id
-child_of(node) Only children of node, node can be either a record or an id
-descendant_of(node) Only descendants of node, node can be either a record or an id
-sibling_of(node) Only siblings of node, node can be either a record or an id
+[root] Only root nodes
+ancestor_of([node)] Only ancestors of node, node can be either a record or an id
+child_of([node)] Only children of node, node can be either a record or an id
+[descendant_of(node)] Only descendants of node, node can be either a record or an id
+[sibling_of(node)] Only siblings of node, node can be either a record or an id
= acts_as_tree Options
The acts_as_tree methods supports two options:
-ancestry_column Pass in a symbol to instruct Ancestry to use a different column name to store record ancestry
-orphan_strategy Instruct Ancestry what to do with children of a node that is destroyed:
- :destroy All children are destroyed as well (default)
- :rootify The children of the destroyed node become root nodes
- :restrict An AncestryException is raised if any children exist
+[ancestry_column] Pass in a symbol to instruct Ancestry to use a different column name to store record ancestry
+[orphan_strategy] Instruct Ancestry what to do with children of a node that is destroyed:
+ :destroy All children are destroyed as well (default)
+ :rootify The children of the destroyed node become root nodes
+ :restrict An AncestryException is raised if any children exist
= Arrangement
@@ -103,17 +103,17 @@ I currently don't see any way Ancestry tree integrity could get compromised with
For example, from IRB:
>> stinky = TreeNode.create :name => 'Stinky'
-=> #<TreeNode id: 1, name: "Stinky", ancestry: nil>
+ $ #<TreeNode id: 1, name: "Stinky", ancestry: nil>
>> squeeky = TreeNode.create :name => 'Squeeky', :parent => stinky
-=> #<TreeNode id: 2, name: "Squeeky", ancestry: "1">
+ $ #<TreeNode id: 2, name: "Squeeky", ancestry: "1">
>> stinky.update_attribute :parent, squeeky
-=> true
+ $ true
>> TreeNode.all
-=> [#<TreeNode id: 1, name: "Stinky", ancestry: "1/2">, #<TreeNode id: 2, name: "Squeeky", ancestry: "1/2/1">]
+ $ [#<TreeNode id: 1, name: "Stinky", ancestry: "1/2">, #<TreeNode id: 2, name: "Squeeky", ancestry: "1/2/1">]
>> TreeNode.check_ancestry_integrity
!! Ancestry::AncestryIntegrityException: Conflicting parent id in node 1: 2 for node 1, expecting nil
>> TreeNode.restore_ancestry_integrity
-=> [#<TreeNode id: 1, name: "Stinky", ancestry: 2>, #<TreeNode id: 2, name: "Squeeky", ancestry: nil>]
+ $ [#<TreeNode id: 1, name: "Stinky", ancestry: 2>, #<TreeNode id: 2, name: "Squeeky", ancestry: nil>]
= Testing
Please sign in to comment.
Something went wrong with that request. Please try again.