Coder Social home page Coder Social logo

acts_as_sane_tree's Introduction

acts_as_sane_tree

(Building trees with a dash of sanity)

<img src=“https://secure.travis-ci.org/chrisroberts/acts_as_sane_tree.png” />

This is a drop in replacement for acts_as_tree on systems with Postgresql >= 8.4

What this provides

A fast way to build trees.

What version of Rails

  • Rails ~> 4.1.0

  • Rails ~> 4.0.0

  • Rails ~> 3.2.0

  • Rails ~> 3.1.0

  • Rails ~> 3.0.0

  • Rails ~> 2.3.0

Requirements

  • PostgreSQL version >= 8.4

  • ActiveRecord

Configuration

Same as acts_as_tree. Basically: Specify a parent_id or the column that holds the parent ID information.

class MyFancyTree < ActiveRecord::Base
  acts_as_sane_tree
end

Extras

A few extras are provided. Of note are:

  • #depth -> depth from root of the current node

  • #descendents -> all descendents of the current node (provided in either scope or nested hash)

  • nodes_within?(src, chk) - Returns true if chk contains any nodes found within src and all ancestors of nodes within src

  • nodes_within(src, chk) - Returns any matching nodes from chk found within src and all ancestors within src

  • nodes_and_descendents(*args) - Returns all nodes and descendents for given IDs or records. Provided in either scope or nested hash.

  • Works properly with STI

  • Adds ‘depth’ attribute to returned model instances

Documentation

Yes, there is documentation. Please read it and find all the fun tools at your fingertips:

chrisroberts.github.com/acts_as_sane_tree

Thanks

  • Thanks to David Hansson for the original

  • Thanks to PostgreSQL for providing tools for sanity

License

A (now not so large) majority of this was copied directly from the original acts as tree, with the original license:

  • Copyright © 2007 David Heinemeier Hansson, released under the MIT license

The new additions continue:

  • Copyright © 2011 Chris Roberts, released under the MIT license

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.