Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleanup to remove deprecation warnings

  • Loading branch information...
commit de62bf7d42af7bf811749efe7130e673622d8706 1 parent b051904
Chad Humphries and Jon Distad authored
Showing with 30 additions and 4,373 deletions.
  1. +1 −0  .gitignore
  2. +2 −1  Gemfile
  3. +4 −2 Gemfile.lock
  4. +2 −2 test/fixtures/votes.yml
  5. +3 −3 test/functional/comments_controller_test.rb
  6. +4 −4 test/functional/examples_controller_test.rb
  7. +7 −7 test/functional/main_controller_test.rb
  8. +3 −3 test/functional/user_controller_test.rb
  9. +2 −2 test/test_helper.rb
  10. +0 −122 vendor/please_remove_me_gems/rubytree-0.7.0/.specification
  11. +0 −42 vendor/please_remove_me_gems/rubytree-0.7.0/API-CHANGES
  12. +0 −43 vendor/please_remove_me_gems/rubytree-0.7.0/COPYING
  13. +0 −68 vendor/please_remove_me_gems/rubytree-0.7.0/History.txt
  14. +0 −12 vendor/please_remove_me_gems/rubytree-0.7.0/Manifest.txt
  15. +0 −220 vendor/please_remove_me_gems/rubytree-0.7.0/README
  16. +0 −124 vendor/please_remove_me_gems/rubytree-0.7.0/Rakefile
  17. +0 −52 vendor/please_remove_me_gems/rubytree-0.7.0/TODO
  18. +0 −857 vendor/please_remove_me_gems/rubytree-0.7.0/lib/tree.rb
  19. +0 −144 vendor/please_remove_me_gems/rubytree-0.7.0/lib/tree/binarytree.rb
  20. +0 −1,585 vendor/please_remove_me_gems/rubytree-0.7.0/setup.rb
  21. +0 −182 vendor/please_remove_me_gems/rubytree-0.7.0/test/test_binarytree.rb
  22. +0 −896 vendor/please_remove_me_gems/rubytree-0.7.0/test/test_tree.rb
  23. +2 −2 vendor/plugins/acts_as_voteable/lib/acts_as_voteable.rb
1  .gitignore
View
@@ -8,3 +8,4 @@ coverage.data
test/coverage
.bundle
config/database.yml
+tags
3  Gemfile
View
@@ -5,6 +5,7 @@ gem "rails", "2.3.5"
gem "ruby-openid", "2.1.7"
gem "rack-openid", "1.0.3", :require => nil
gem "pg", "0.9.0"
+gem "rubytree", "0.7.0"
gem "rdiscount", "1.6.5"
gem "chronic", "0.2.3"
@@ -12,7 +13,7 @@ gem 'will_paginate', '2.3.12'
gem 'levenshtein', '0.2.0'
group :test do
- gem "shoulda", "2.11.1"
+ gem "shoulda", "2.11.3"
gem "flexmock", "0.8.7"
gem "rcov", "0.9.9", :require => nil
end
6 Gemfile.lock
View
@@ -37,7 +37,8 @@ GEM
ruby-openid (2.1.7)
rubyforge (2.0.4)
json_pure (>= 1.1.7)
- shoulda (2.11.1)
+ rubytree (0.7.0)
+ shoulda (2.11.3)
will_paginate (2.3.12)
PLATFORMS
@@ -54,5 +55,6 @@ DEPENDENCIES
rcov (= 0.9.9)
rdiscount (= 1.6.5)
ruby-openid (= 2.1.7)
- shoulda (= 2.11.1)
+ rubytree (= 0.7.0)
+ shoulda (= 2.11.3)
will_paginate (= 2.3.12)
4 test/fixtures/votes.yml
View
@@ -1,6 +1,6 @@
vote_map_to_dummy_see_also_up:
id: 1
- vote: 1
+ vote: true
created_at: 2010-08-13 01:06:03
voteable_id: 1
- user_id: 1
+ user_id: 1
6 test/functional/comments_controller_test.rb
View
@@ -14,7 +14,7 @@ class CommentsControllerTest < ActionController::TestCase
end
should respond_with 302
- should_set_the_flash_to "Comment successfully deleted."
+ should set_the_flash.to "Comment successfully deleted."
end
context "without a logged in user" do
@@ -23,7 +23,7 @@ class CommentsControllerTest < ActionController::TestCase
end
should respond_with 302
- should_set_the_flash_to "There was a problem deleting that comment."
+ should set_the_flash.to "There was a problem deleting that comment."
end
context "without a valid comment id" do
@@ -32,7 +32,7 @@ class CommentsControllerTest < ActionController::TestCase
end
should respond_with 302
- should_set_the_flash_to "There was a problem deleting that comment."
+ should set_the_flash.to "There was a problem deleting that comment."
end
end
end
8 test/functional/examples_controller_test.rb
View
@@ -109,9 +109,9 @@ class ExamplesControllerTest < ActionController::TestCase
get :view_changes, :id => 1
end
- should_assign_to :example
- should_assign_to :versions
- should_render_template :view_changes
+ should assign_to :example
+ should assign_to :versions
+ should render_template :view_changes
should respond_with :success
end
@@ -121,7 +121,7 @@ class ExamplesControllerTest < ActionController::TestCase
end
should set_the_flash
- should_redirect_to "/"
+ should redirect_to "/"
end
end
14 test/functional/main_controller_test.rb
View
@@ -20,7 +20,7 @@ class MainControllerTest < ActionController::TestCase
get :function_short_link, :id => -1
end
- should_respond_with 404
+ should respond_with 404
end
context "with a valid function, but an invalid library" do
@@ -28,7 +28,7 @@ class MainControllerTest < ActionController::TestCase
get :function_short_link, :id => 2
end
- should_respond_with 404
+ should respond_with 404
end
end
@@ -40,7 +40,7 @@ class MainControllerTest < ActionController::TestCase
get :ns, :lib => 'not found', :ns => 'clojure.core'
end
- should_respond_with 404
+ should respond_with 404
end
context "with a valid library and an invalid ns" do
@@ -48,7 +48,7 @@ class MainControllerTest < ActionController::TestCase
get :ns, :lib => 'Clojure Core', :ns => 'not found'
end
- should_respond_with 404
+ should respond_with 404
end
end
@@ -60,7 +60,7 @@ class MainControllerTest < ActionController::TestCase
get :lib, :lib => "not found"
end
- should_respond_with 404
+ should respond_with 404
end
end
@@ -71,7 +71,7 @@ class MainControllerTest < ActionController::TestCase
get :quick_ref_shortdesc, :lib => 'not found'
end
- should_respond_with 404
+ should respond_with 404
end
should_succeed :quick_ref_vars_only, :lib => 'Clojure Core'
@@ -80,7 +80,7 @@ class MainControllerTest < ActionController::TestCase
get :quick_ref_vars_only, :lib => 'not found'
end
- should_respond_with 404
+ should respond_with 404
end
end
6 test/functional/user_controller_test.rb
View
@@ -12,7 +12,7 @@ class UserControllerTest < ActionController::TestCase
get :profile, :login => 'not found'
end
- should_respond_with 404
+ should respond_with 404
end
context "A login with a space in it" do
@@ -20,7 +20,7 @@ class UserControllerTest < ActionController::TestCase
get :profile, :login => 'Brian Marick'
end
- should_respond_with :success
+ should respond_with :success
end
context "Where the current user and the profile page user are the same" do
@@ -30,7 +30,7 @@ class UserControllerTest < ActionController::TestCase
get :profile, :login => 'zkim'
end
- should_respond_with :success
+ should respond_with :success
end
context "updating a user with a valid email" do
4 test/test_helper.rb
View
@@ -42,7 +42,7 @@ def self.should_response(action_name, response, params = {})
get action_name, params
end
- should_respond_with response
+ should respond_with response
end
end
@@ -62,4 +62,4 @@ def self.should_have_json_prop(property, value)
end
-end
+end
122 vendor/please_remove_me_gems/rubytree-0.7.0/.specification
View
@@ -1,122 +0,0 @@
---- !ruby/object:Gem::Specification
-name: rubytree
-version: !ruby/object:Gem::Version
- version: 0.7.0
-platform: ruby
-authors:
-- Anupam Sengupta
-autorequire:
-bindir: bin
-cert_chain: []
-
-date: 2010-05-03 00:00:00 -06:00
-default_executable:
-dependencies:
-- !ruby/object:Gem::Dependency
- name: rubyforge
- type: :development
- version_requirement:
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: 2.0.4
- version:
-- !ruby/object:Gem::Dependency
- name: hoe-yard
- type: :development
- version_requirement:
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: 0.1.2
- version:
-- !ruby/object:Gem::Dependency
- name: hoe
- type: :development
- version_requirement:
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: 2.6.0
- version:
-description: |-
- RubyTree is a Ruby implementation of the generic tree data structure. It provides a node-based model to store keyed
- node-elements in the tree and simple APIs to access, modify and traverse the structure. RubyTree is node-centric, where
- individual nodes on the tree are the primary compositional and structural elements.
-
- This implementation also mixes in the Enumerable module to allow standard access to the tree as a collection.
-email:
-- anupamsg@gmail.com
-executables: []
-
-extensions: []
-
-extra_rdoc_files:
-- History.txt
-- Manifest.txt
-- COPYING
-- API-CHANGES
-files:
-- COPYING
-- History.txt
-- Manifest.txt
-- README
-- API-CHANGES
-- Rakefile
-- TODO
-- lib/tree.rb
-- lib/tree/binarytree.rb
-- setup.rb
-- test/test_binarytree.rb
-- test/test_tree.rb
-has_rdoc: true
-homepage: http://rubytree.rubyforge.org
-licenses: []
-
-post_install_message: |
- ========================================================================
-
- Thank you for installing rubytree.
-
- Please note that a few APIs have been deprecated since Version 0.6.1.
-
- Specifically, the 'Tree::TreeNode#depth' method is now deprecated, and
- a new nodeDepth() method has been introduced.
-
- Details of the API changes are documented in the API-CHANGES file.
-
- ========================================================================
-
-rdoc_options:
-- --files
-- COPYING,API-CHANGES
-- --title
-- Rubytree Documentation
-- --quiet
-require_paths:
-- lib
-required_ruby_version: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: "0"
- version:
-required_rubygems_version: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: "0"
- version:
-requirements: []
-
-rubyforge_project: rubytree
-rubygems_version: 1.3.5
-signing_key:
-specification_version: 3
-summary: RubyTree is a Ruby implementation of the generic tree data structure
-test_files:
-- test/test_binarytree.rb
-- test/test_tree.rb
42 vendor/please_remove_me_gems/rubytree-0.7.0/API-CHANGES
View
@@ -1,42 +0,0 @@
-= API Changes in RubyTree
-
-This file documents various API level changes that have been made to the RubyTree package.
-
-Note: API level changes are expected to reduce dramatically after the 1.x release. In most cases, an alternative will
-be provided to ensure relatively smooth transition to the new APIs.
-
-== Release 0.7.0 Changes
-
-- Converted all exceptions thrown on invalid method arguments to from 'RuntimeError' to 'ArgumentError'. This impacts the
- following methods:
-
- - {Tree::TreeNode#initialize}
- - {Tree::TreeNode#add}
- - {Tree::TreeNode#[]}
- - {Tree::BinaryTreeNode#add}
-
-- Added {Tree::TreeNode#level} as an alias for {Tree::TreeNode#nodeDepth}
-
-- Added new methods {Tree::TreeNode#in_degree} and {Tree::TreeNode#out_degree} to report the node's degree stats
-
-- {Tree::TreeNode#isOnlyChild?} now returns +true+ for a root node.
-
-- {Tree::TreeNode#nextSibling} and {Tree::TreeNode#previousSibling} now return +nil+ for a root node.
-
-- {Tree::TreeNode#add} and {Tree::TreeNode#<<} now throw an ArgumentError exception if a +nil+ node is passed as an argument.
-
-- Added new methods {Tree::TreeNode#to_json} and {Tree::TreeNode::json_create} to convert to/from the JSON format.
- Thanks to Dirk[http://github.com/railsbros-dirk] for this change.
-
-== Release 0.6.1 Changes
-
-- Deprecated the {Tree::TreeNode#depth} method as it was returning an incorrect depth value. Have introduced a new replacement
- method {Tree::TreeNode#nodeDepth} which returns the correct result.
-
-
-
-
-# Local Variables:
-# mode: text
-# coding: utf-8-unix
-# End:
43 vendor/please_remove_me_gems/rubytree-0.7.0/COPYING
View
@@ -1,43 +0,0 @@
-= RubyTree
-
-http://rubytree.rubyforge.org
-
-Copyright (c) 2006, 2007, 2008, 2009, 2010 Anupam Sengupta (anupamsg at gmail dot com)
-
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
-following conditions are met:
-
-- Redistributions of source code must retain the above copyright notice, this list of conditions and the following
- disclaimer.
-
-- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided with the distribution.
-
-- Neither the name of the organization nor the names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-$Id$
-
-
-
-
-
-
-
-
-
-
-# Local Variables:
-# mode: text
-# coding: utf-8-unix
-# End:
68 vendor/please_remove_me_gems/rubytree-0.7.0/History.txt
View
@@ -1,68 +0,0 @@
-=== 0.7.0 / 2010-05-03
-
-* Added new methods to report the degree statistics of a node.
-
-* Added a convenience method alias 'level' to 'nodeDepth'.
-
-* Converted the exceptions thrown on invalid arguments to 'ArgumentError' instead of 'RuntimeError'.
-
-* Converted the documentation to Yard format.
-
-* Added new methods for converting from/to JSON formats. Thanks to Dirk Breuer[http://github.com/railsbros-dirk] for
- this fork[http://github.com/galaxycats/].
-
-* Added a separate API-CHANGES documentation file.
-
-* Added fixes for root related edge conditions to 'isOnlyChild?', 'nextSibling', 'previousSibling' and 'remove' methods.
-
-* Removed the 'ChangeLog' file as this can now be generated from the git logs.
-
-* Other minor code cleanup.
-
-=== 0.6.2 / 2010-01-30
-
-* Updated the documentation.
-
-=== 0.6.1 / 2010-01-04
-
-* Changed the hard-dependency on the 'structured_warnings' RubyGem to a soft-dependency - which lets Rubytree still
- work if this RubyGem is not available. The rationale for this is that we should not require the user to install a
- separate library just for one single edge-case function (in this case, to indicate a deprecated method). However, if
- the library _is_ available on the user's system, then it will get used.
-
-=== 0.6.0 / 2010-01-03
-
-* Fixed the bug#22535[http://rubyforge.org/tracker/index.php?func=detail&aid=22535&group_id=1215&atid=4793] where the
- depth method was actually returning height+1 (not the depth).
-
-* Marked the Tree::TreeNode#depth method as *deprecated* (and introduced the run-time dependency on
- structured-warnings[http://github.com/schmidt/structured_warnings] gem).
-
-=== 0.5.3 / 2009-12-31
-
-* Cleanup of the build system to exclusively use Hoe.
-* Modifications and reformatting to the documentation.
-* No user visible changes.
-
-=== 0.5.2 / 2007-12-21
-
-* Added more test cases and enabled ZenTest compatibility for the test case
- names.
-
-=== 0.5.1 / 2007-12-20
-
-* Minor code refactoring.
-
-=== 0.5.0 / 2007-12-18
-
-* Fixed the marshalling code to correctly handle non-string content.
-
-=== 0.4.3 / 2007-10-09
-
-* Changes to the build mechanism (now uses Hoe).
-
-=== 0.4.2 / 2007-10-01
-
-* Minor code refactoring. Changes in the Rakefile.
-
-$Id$
12 vendor/please_remove_me_gems/rubytree-0.7.0/Manifest.txt
View
@@ -1,12 +0,0 @@
-COPYING
-History.txt
-Manifest.txt
-README
-API-CHANGES
-Rakefile
-TODO
-lib/tree.rb
-lib/tree/binarytree.rb
-setup.rb
-test/test_binarytree.rb
-test/test_tree.rb
220 vendor/please_remove_me_gems/rubytree-0.7.0/README
View
@@ -1,220 +0,0 @@
-= RubyTree
- __ _ _
- /__\_ _| |__ _ _| |_ _ __ ___ ___
- / \// | | | '_ \| | | | __| '__/ _ \/ _ \
- / _ \ |_| | |_) | |_| | |_| | | __/ __/
- \/ \_/\__,_|_.__/ \__, |\__|_| \___|\___|
- |___/
-
-Copyright (c) 2006, 2007, 2008, 2009, 2010 Anupam Sengupta (anupamsg at gmail dot com)
-
-http://rubytree.rubyforge.org
-
-== DESCRIPTION:
-
-RubyTree is a Ruby implementation of the generic tree data structure. It provides a node-based model to store keyed
-node-elements in the tree and simple APIs to access, modify and traverse the structure. RubyTree is node-centric, where
-individual nodes on the tree are the primary compositional and structural elements.
-
-This implementation also mixes in the Enumerable module to allow standard access to the tree as a collection.
-
-== SYNOPSIS:
-
-As an example, the following code-snippet implements this tree structure:
-
- +------------+
- | ROOT |
- +-----+------+
- +-------------+------------+
- | |
- +-------+-------+ +-------+-------+
- | CHILD 1 | | CHILD 2 |
- +-------+-------+ +---------------+
- |
- |
- +-------+-------+
- | GRANDCHILD 1 |
- +---------------+
-
- # ..... Example starts.
- require 'tree' # Load the library
-
- # ..... Create the root node first. Note that every node has a name and an optional content payload.
- root_node = Tree::TreeNode.new("ROOT", "Root Content")
-
- # ..... Now insert the child nodes. Note that you can "chain" the child insertions for a given path to any depth.
- root_node << Tree::TreeNode.new("CHILD1", "Child1 Content") << Tree::TreeNode.new("GRANDCHILD1", "GrandChild1 Content")
- root_node << Tree::TreeNode.new("CHILD2", "Child2 Content")
-
- # ..... Lets print the representation to stdout. This is primarily used for debugging purposes.
- root_node.printTree
-
- # ..... Lets directly access children and grandchildren of the root. The can be "chained" for a given path to any depth.
- child1 = root_node["CHILD1"]
- grand_child1 = root_node["CHILD1"]["GRANDCHILD1"]
-
- # ..... Lets retrieve siblings of the current node as an array.
- siblings_of_child1 = child1.siblings
-
- # ..... Lets retrieve immediate children of the root node as an array.
- children_of_root = root_node.children
-
- # ..... This is a depth-first and L-to-R pre-ordered traversal.
- root_node.each { |node| node.content.reverse }
-
- # ..... Lets remove a child node from the root node.
- root_node.remove!(child1)
-
-
-== REQUIREMENTS:
-
-* Ruby 1.8+ (http://www.ruby-lang.org)
-
-* Optional but recommended:
- * structured_warnings (http://github.com/schmidt/structured_warnings) Rubygem
- * Yard (http://yardoc.org) Rubygem for the documentation
- * JSON (http://flori.github.com/json) Rubygem for converting to/from the JSON format
-
-* Development dependencies (not required for installing the gem):
- * Hoe (http://seattlerb.rubyforge.org/hoe/Hoe.html) Rubygem
- * gemcutter (http://gemcutter.org/gems/gemcutter) Rubygem
- * Rubyforge (http://codeforpeople.rubyforge.org/rubyforge) Rubygem
-
-== INSTALL:
-
-RubyTree is an open source project and is hosted at:
-
-http://rubytree.rubyforge.org
-
-RubyTree can be downloaded as a Rubygem or as a tar/zip file from:
-
-http://rubyforge.org/frs/?group_id=1215&release_id=8817
-
-The file-name is one of:
-
- rubytree-<VERSION>.gem - The Rubygem
- rubytree-<VERSION>.tgz - GZipped source files
- rubytree-<VERSION>.zip - Zipped source files
-
-Download the appropriate file-type for your system.
-
-It is recommended to install RubyTree as a Ruby Gem, as this is an easy way to keep the version updated, and keep
-multiple versions of the library available on your system.
-
-=== Installing the Gem
-
-To Install the Gem, from a Terminal/CLI command prompt, issue the command:
-
- $ gem install rubytree
-
-This should install the gem file for RubyTree. Note that you may need to be a super-user (root) to successfully install
-the gem.
-
-=== Installing from the tgz/zip file
-
-Extract the archive file (tgz or zip) and run the following command from the top-level source directory:
-
- ruby ./setup.rb
-
-You may need administrator/super-user privileges to complete the setup using this method.
-
-== DOCUMENTATION:
-
-The primary class for this implementation is Tree::TreeNode. See the class documentation for an usage example.
-
-From a command line/terminal prompt, you can issue the following command to view the text mode ri documentation:
-
- ri Tree::TreeNode
-
-Documentation for the latest released version is available at:
-
-http://rubytree.rubyforge.org/rdoc
-
-Documentation for the latest git HEAD is available at:
-
-http://rdoc.info/projects/evolve75/RubyTree
-
-Note that the documentation is formatted for Yard (http://yardoc.org).
-
-== DEVELOPERS:
-
-You can download the latest released source code using the tar or zip version as mentioned above in the installation
-section.
-
-Alternatively, you can checkout the latest commit/revision from the version control system. Note that RubyTree's
-primary SCM[http://en.wikipedia.org/wiki/Source_Code_Management] is on git[http://git-scm.com] and is
-also mirrored on github[http://www.github.com].
-
-=== Using the Git repository
-
-For checking out from the primary Git repository, use the following command:
-
- $ git clone git://rubyforge.org/rubytree.git
-
-The Git repository is available for browsing on the web at: http://fisheye2.atlassian.com/browse/rubytree
-
-=== Using the Git repository on http://github.com
-
-For cloning the git repository, use one of the following commands:
-
- $ git clone git://github.com/evolve75/RubyTree.git
-
-or
- $ git clone http://github.com/evolve75/RubyTree.git
-
-The git repository is available on the web at: http://github.com/evolve75/RubyTree
-
-=== Setting up the development environment
-
-After checking out the source, run:
-
- $ rake newb
-
-This task will install any missing dependencies, run the tests/specs, and generate the RDoc.
-
-Note that you need to have the Rubygem Hoe[http://seattlerb.rubyforge.org/hoe/Hoe.html] to successfully run the rake
-tasks. Installing Hoe may also install additional pre-requisite gems. See the REQUIREMENTS section in this document for
-details.
-
-For generating the documentation, it is strongly suggested that the Yard[http://yardoc.org] gem be installed.
-
-== ACKNOWLEDGMENTS:
-
-I would like to acknowledge the following contributors for helping improve RubyTree:
-
-1. Dirk Breuer (http://github.com/railsbros-dirk) for contributing the JSON conversion code.
-
-== LICENSE:
-
-RubyTree is licensed under the BSD[http://www.opensource.org/licenses/bsd-license.php] license.
-
-Copyright (c) 2006, 2007, 2008, 2009, 2010 Anupam Sengupta
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
-following conditions are met:
-
-- Redistributions of source code must retain the above copyright notice, this list of conditions and the following
- disclaimer.
-
-- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
- disclaimer in the documentation and/or other materials provided with the distribution.
-
-- Neither the name of the organization nor the names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-(Document Revision: $Revision$ by $Author$)
-
-# Local Variables:
-# mode: text
-# coding: utf-8-unix
-# End:
124 vendor/please_remove_me_gems/rubytree-0.7.0/Rakefile
View
@@ -1,124 +0,0 @@
-# -*- mode: ruby; -*-
-#
-# Rakefile - This file is part of the RubyTree package.
-#
-# $Revision$ by $Author$ on $Date$
-#
-# Copyright (c) 2006, 2007, 2009, 2010 Anupam Sengupta
-#
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-#
-# - Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# - Redistributions in binary form must reproduce the above copyright notice, this
-# list of conditions and the following disclaimer in the documentation and/or
-# other materials provided with the distribution.
-#
-# - Neither the name of the organization nor the names of its contributors may
-# be used to endorse or promote products derived from this software without
-# specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-PKG_NAME = "rubytree"
-
-# Default is to create a rubygem.
-desc "Default Task (create the gem)"
-task :default => :gem
-
-# Use Hoe to define the rake tasks.
-begin
- require 'hoe'
- Hoe.plugin :yard
-
- Hoe.spec PKG_NAME do
- # The GemSpec settings
- self.rubyforge_name = PKG_NAME
- developer "Anupam Sengupta", "anupamsg@gmail.com"
-
- self.url = "http://rubytree.rubyforge.org"
- self.readme_file = 'README'
-
- # Set the Yard Options
- extra_docs = ["COPYING", "API-CHANGES"]
- extra_docs.each { |file| self.yard_files << file }
- self.yard_options = ["--files", extra_docs.join(",") ]
-
- # Now the publishing settings
- self.remote_rdoc_dir = 'rdoc'
-
- # Support additional package formats
- self.need_tar = true
- self.need_zip = true
-
- # Post installation message
- self.post_install_message = <<MSGEND
-========================================================================
-
- Thank you for installing #{PKG_NAME}.
-
- Please note that a few APIs have been deprecated since Version 0.6.1.
-
- Specifically, the 'Tree::TreeNode#depth' method is now deprecated, and
- a new nodeDepth() method has been introduced.
-
- Details of the API changes are documented in the API-CHANGES file.
-
-========================================================================
-MSGEND
-
- # Code Metrics ...
- self.flay_threshold = timebomb 1200, 100 # Default is 1200, 100
- self.flog_threshold = timebomb 1200, 100 # Default is 1200, 100
- end
-
-rescue LoadError # If Hoe is not found ...
- $stderr.puts <<-END
- ERROR!!! You do not seem to have Hoe installed!
-
- The Hoe gem is required for running the rake tasks for building the rubytree gem.
-
- You can download Hoe as a Rubygem by running as root (or sudo):
-
- $ gem install hoe
-
- More details can be found at http://seattlerb.rubyforge.org/hoe/Hoe.html
-
- END
-end
-
-
-# The following tasks are loaded independently of Hoe
-# ===================================================
-
-# Optional TAGS Task.
-# Needs http://rubyforge.org/projects/rtagstask/
-begin
- require 'rtagstask'
- RTagsTask.new do |rd|
- rd.vi = false
- end
-rescue LoadError
- $stderr.puts <<-END
- ERROR!!! You need to have the rtagstask (https://rubyforge.org/projects/rtagstask/) for generating the TAGS file.
-
- You can install the rtags gem by running the following command as root (or sudo):
-
- $ gem install rtagstask
-
- END
-end
52 vendor/please_remove_me_gems/rubytree-0.7.0/TODO
View
@@ -1,52 +0,0 @@
-# -*- mode: org; coding: utf-8-unix; -*-
-
-
-* R0.7.0
-*** TODO Start using signed tags from R0.7.0
-*** DONE Add a check in the Tree::TreeNode.add method to prevent addition of nil child nodes
- CLOSED: [2010-02-23 Tue 23:07]
-*** DONE Fix the edge condition for Tree::TreeNode.isOnlyChild? when the root node is the receiver.
- CLOSED: [2010-02-23 Tue 22:03]
- There really is no good default to this situation. We will return 'true' simply because there is no other sibling
- to a root. However, a good case can be made that a root node does not have any parent either.
-*** DONE Add a convenience 'level' method to the TreeNode class (will be an alias to nodeDepth)
- CLOSED: [2010-02-21 Sun 01:02]
-*** DONE Add a API-CHANGES file to document the various API changes made till date
- CLOSED: [2010-01-31 Sun 00:52]
-*** DONE Add new methods to return the degree counts of the receiver node (in-degree and out-degree)
- CLOSED: [2010-01-30 Sat 23:56]
-
-* R0.8.0
-*** TODO Convert all method names to the canonical /^[_a-z<>=\[|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/ pattern
- See Roodi report at http://getcaliper.com/caliper/tool?tool=roodi&repo=git://github.com/evolve75/RubyTree.git
-*** TODO Fix the inconsistency of returning root as its first sibling, and returning a nil instead. Ditto for last sibling.
-*** TODO fix the inconsistency of returning nil for the root, and an empty array for nodes which have no siblings.
-*** TODO We should perhaps return nil as root's root.
-*** TODO The semantic of length is probably unclear. Should return the node_depth instead (or remove the method)
- The current equivalence of length to size should also be removed.
-
-
-* Unplanned / Not assigned to any release
-*** TODO Fix the TreeNode#root method to return nil for root's root.
-*** TODO Fix the marshal_load method. This probably needs to be a class method.
-*** TODO Fix the semantic inconsistency between the TreeNode#first|lastSibling method and the siblings method w.r.t. the root
-*** TODO Create the basic UML diagrams and upload to the Site
- DEADLINE: <2010-01-04 Mon>
-
-*** DONE Fix bug # [[http://rubyforge.org/tracker/index.php%3Ffunc%3Ddetail&aid%3D22535&group_id%3D1215&atid%3D4793][22535]]: The method Tree::TreeNode#depth is a misnomer. The current definition actually provides the height function.
- DEADLINE: <2010-01-09 Sat> CLOSED: [2010-01-03 Sun 22:15]
-
-*** TODO Add a YAML export method to the TreeNode class.
-
-*** DONE Get the version control moved from CVS to Subversion (request submitted to RubyForge)
- CLOSED: [2010-01-02 Sat 17:58]
-
-*** DONE Add logic in Rakefile to read the file list from Manifest.txt file.
- CLOSED: [2009-12-31 Thu 23:37]
-*** TODO Fix the inconsistency of returning root as its last sibling, and returning a nil array for siblings of the node
-*** TODO marshal_load method probably should be a class method. It currently clobbers self.
-*** TODO Fix the inconsistency of returning root as its first/last sibling, and returning a nil array for siblings of the node
-
-$Id$
-
-
857 vendor/please_remove_me_gems/rubytree-0.7.0/lib/tree.rb
View
@@ -1,857 +0,0 @@
-# tree.rb - This file is part of the RubyTree package.
-#
-# $Revision$ by $Author$ on $Date$
-#
-# = tree.rb - Generic implementation of an N-ary tree data structure.
-#
-# Provides a generic tree data structure with ability to
-# store keyed node elements in the tree. This implementation
-# mixes in the Enumerable module.
-#
-# Author:: Anupam Sengupta (anupamsg@gmail.com)
-#
-
-# Copyright (c) 2006, 2007, 2008, 2009, 2010 Anupam Sengupta
-#
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-#
-# - Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# - Redistributions in binary form must reproduce the above copyright notice, this
-# list of conditions and the following disclaimer in the documentation and/or
-# other materials provided with the distribution.
-#
-# - Neither the name of the organization nor the names of its contributors may
-# be used to endorse or promote products derived from this software without
-# specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-# This module provides a TreeNode class which is the primary class for representing
-# nodes in the tree.
-#
-# This module also acts as the namespace for all classes in the RubyTree package.
-module Tree
-
- # Rubytree Package Version
- VERSION = '0.7.0'
-
- # == TreeNode Class Description
- #
- # This class models the nodes for an *N-ary* tree data structue. The nodes are *named*
- # and have a place-holder for the node data (i.e., _content_ of the node). The node
- # names are required to be *unique* within the tree.
- #
- # The node's _content_ is *not* required to be unique across different nodes in the tree, and
- # can be +nil+ as well.
- #
- # The class provides various methods to navigate the tree, traverse the structure,
- # modify contents of the node, change position of the node in the tree,
- # and to make structural changes to the tree.
- #
- # A node can have any number of *child* nodes attached to it and hence can be used to create N-ary trees.
- # Access to the child nodes can be made in order (with the conventional left to right access), or
- # randomly.
- #
- # The node also provides direct access to its *parent* node as well as other superior parents in the path to
- # root of the tree. In addition, a node can also access its *sibling* nodes, if present.
- #
- # Note that while this implementation does not _explicitly_ support directed graphs, the class itself makes
- # no restrictions on associating a node's *content* with multiple nodes in the tree.
- #
- #
- # == Example
- #
- # The following example implements this tree structure:
- #
- # +------------+
- # | ROOT |
- # +-----+------+
- # +-------------+------------+
- # | |
- # +-------+-------+ +-------+-------+
- # | CHILD 1 | | CHILD 2 |
- # +-------+-------+ +---------------+
- # |
- # |
- # +-------+-------+
- # | GRANDCHILD 1 |
- # +---------------+
- #
- # # ..... Example starts.
- # require 'tree' # Load the library
- #
- # # ..... Create the root node first. Note that every node has a name and an optional content payload.
- # root_node = Tree::TreeNode.new("ROOT", "Root Content")
- #
- # # ..... Now insert the child nodes. Note that you can "chain" the child insertions for a given path to any depth.
- # root_node << Tree::TreeNode.new("CHILD1", "Child1 Content") << Tree::TreeNode.new("GRANDCHILD1", "GrandChild1 Content")
- # root_node << Tree::TreeNode.new("CHILD2", "Child2 Content")
- #
- # # ..... Lets print the representation to stdout. This is primarily used for debugging purposes.
- # root_node.printTree
- #
- # # ..... Lets directly access children and grandchildren of the root. The can be "chained" for a given path to any depth.
- # child1 = root_node["CHILD1"]
- # grand_child1 = root_node["CHILD1"]["GRANDCHILD1"]
- #
- # # ..... Now lets retrieve siblings of the current node as an array.
- # siblings_of_child1 = child1.siblings
- #
- # # ..... Lets retrieve immediate children of the root node as an array.
- # children_of_root = root_node.children
- #
- # # ..... This is a depth-first and L-to-R pre-ordered traversal.
- # root_node.each { |node| node.content.reverse }
- #
- # # ..... Lets remove a child node from the root node.
- # root_node.remove!(child1)
- #
- # @author Anupam Sengupta
- class TreeNode
- include Enumerable
-
- # Name of this node. Expected to be unique within the tree.
- attr_reader :name
-
- # Content of this node. Can be +nil+.
- attr_accessor :content
-
- # Parent of this node. Will be +nil+ for a root node.
- attr_reader :parent
-
-
- # Creates a new node with a name and optional content.
- # The node name is expected to be unique within the tree.
- #
- # The content can be of any type, and defaults to +nil+.
- #
- # @param [Object] name Name of the node. Usual usage is to pass a String.
- # @param [Object] content Content of the node.
- #
- # @raise [ArgumentError] Raised if the node name is empty.
- def initialize(name, content = nil)
- raise ArgumentError, "Node name HAS to be provided!" if name == nil
- @name, @content = name, content
-
- self.setAsRoot!
- @childrenHash = Hash.new
- @children = []
- end
-
- # Returns a copy of the receiver node, with its parent and children links removed.
- # The original node remains attached to its tree.
- #
- # @return [Tree::TreeNode] A copy of the receiver node.
- def detached_copy
- Tree::TreeNode.new(@name, @content ? @content.clone : nil)
- end
-
- # Returns string representation of the receiver node.
- # This method is primarily meant for debugging purposes.
- #
- # @return [String] A string representation of the node.
- def to_s
- "Node Name: #{@name}" +
- " Content: " + (@content || "<Empty>") +
- " Parent: " + (isRoot?() ? "<None>" : @parent.name) +
- " Children: #{@children.length}" +
- " Total Nodes: #{size()}"
- end
-
- # Returns an array of ancestors of the receiver node in reversed order
- # (the first element is the immediate parent of the receiver).
- #
- # Returns +nil+ if the receiver is a root node.
- #
- # @return [Array, nil] An array of ancestors of the receiver node, or +nil+ if this is a root node.
- def parentage
- return nil if isRoot?
-
- parentageArray = []
- prevParent = self.parent
- while (prevParent)
- parentageArray << prevParent
- prevParent = prevParent.parent
- end
-
- parentageArray
- end
-
- # Protected method to set the parent node for the receiver node.
- # This method should *NOT* be invoked by client code.
- #
- # @param [Tree::TreeNode] parent The parent node.
- #
- # @return [Tree::TreeNode] The parent node.
- def parent=(parent) # :nodoc:
- @parent = parent
- end
-
- # Convenience synonym for {Tree::TreeNode#add} method.
- #
- # This method allows an easy mechanism to add node hierarchies to the tree
- # on a given path via chaining the method calls to successive child nodes.
- #
- # @example Add a child and grand-child to the root
- # root << child << grand_child
- #
- # @param [Tree::TreeNode] child the child node to add.
- #
- # @return [Tree::TreeNode] The added child node.
- #
- # @see Tree::TreeNode#add
- def <<(child)
- add(child)
- end
-
- # Adds the specified child node to the receiver node.
- #
- # This method can also be used for *grafting* a subtree into the receiver node's tree, if the specified child node
- # is the root of a subtree (i.e., has child nodes under it).
- #
- # The receiver node becomes parent of the node passed in as the argument, and
- # the child is added as the last child ("right most") in the current set of
- # children of the receiver node.
- #
- # @param [Tree::TreeNode] child The child node to add.
- #
- # @return [Tree::TreeNode] The added child node.
- #
- # @raise [RuntimeError] This exception is raised if another child node with the same
- # name exists.
- # @raise [ArgumentError] This exception is raised if a +nil+ node is passed as the argument.
- #
- # @see #<<
- def add(child)
- raise ArgumentError, "Attempting to add a nil node" unless child
- raise "Child #{child.name} already added!" if @childrenHash.has_key?(child.name)
-
- @childrenHash[child.name] = child
- @children << child
- child.parent = self
- return child
- end
-
- # Removes the specified child node from the receiver node.
- #
- # This method can also be used for *pruning* a sub-tree, in cases where the removed child node is
- # the root of the sub-tree to be pruned.
- #
- # The removed child node is orphaned but accessible if an alternate reference exists. If accessible via
- # an alternate reference, the removed child will report itself as a root node for its sub-tree.
- #
- # @param [Tree::TreeNode] child The child node to remove.
- #
- # @return [Tree::TreeNode] The removed child node, or +nil+ if a +nil+ was passed in as argument.
- #
- # @see #removeFromParent!
- # @see #removeAll!
- def remove!(child)
- return nil unless child
-
- @childrenHash.delete(child.name)
- @children.delete(child)
- child.setAsRoot!
- child
- end
-
- # Removes the receiver node from its parent. The reciever node becomes the new root for its subtree.
- #
- # If this is the root node, then does nothing.
- #
- # @return [Tree:TreeNode] +self+ (the removed receiver node) if the operation is successful, +nil+ otherwise.
- #
- # @see #removeAll!
- def removeFromParent!
- @parent.remove!(self) unless isRoot?
- end
-
- # Removes all children from the receiver node. If an indepedent reference exists to the child
- # nodes, then these child nodes report themselves as roots after this operation.
- #
- # @return [Tree::TreeNode] The receiver node (+self+)
- #
- # @see #remove!
- # @see #removeFromParent!
- def removeAll!
- for child in @children
- child.setAsRoot!
- end
- @childrenHash.clear
- @children.clear
- self
- end
-
- # Returns +true+ if the receiver node has content.
- #
- # @return [Boolean] +true+ if the node has content.
- def hasContent?
- @content != nil
- end
-
- # Protected method which sets the receiver node as a root node.
- #
- # @return +nil+.
- def setAsRoot! # :nodoc:
- @parent = nil
- end
-
- # Returns +true+ if the receiver is a root node. Note that
- # orphaned children will also be reported as root nodes.
- #
- # @return [Boolean] +true+ if this is a root node.
- def isRoot?
- @parent == nil
- end
-
- # Returns +true+ if the receiver node has any child node.
- #
- # @return [Boolean] +true+ if child nodes exist.
- #
- # @see #isLeaf?
- def hasChildren?
- @children.length != 0
- end
-
- # Returns +true+ if the receiver node is a 'leaf' - i.e., one without
- # any children.
- #
- # @return [Boolean] +true+ if this is a leaf node.
- #
- # @see #hasChildren?
- def isLeaf?
- !hasChildren?
- end
-
- # Returns an array of all the immediate children of the receiver node. The child nodes are ordered
- # "left-to-right" in the returned array.
- #
- # If a block is given, yields each child node to the block traversing from left to right.
- #
- # @yield [child] Each child is passed to the block, if given
- # @yieldparam [Tree::TreeNode] child Each child node.
- #
- # @return [Array<Tree::TreeNode>] An array of the child nodes, if no block is given.
- def children
- if block_given?
- @children.each {|child| yield child}
- else
- @children
- end
- end
-
- # Returns the first child of the receiver node.
- #
- # Will return +nil+ if no children are present.
- #
- # @return [Tree::TreeNode] The first child, or +nil+ if none is present.
- def firstChild
- children.first
- end
-
- # Returns the last child of the receiver node.
- #
- # Will return +nil+ if no children are present.
- #
- # @return [Tree::TreeNode] The last child, or +nil+ if none is present.
- def lastChild
- children.last
- end
-
- # Traverses each node (including the receiver node) of the (sub)tree rooted at this node
- # by yielding the nodes to the specified block.
- #
- # The traversal is *depth-first* and from *left-to-right* in pre-ordered sequence.
- #
- # @yield [child] Each node is passed to the block.
- # @yieldparam [Tree::TreeNode] child Each node.
- #
- # @see #preordered_each
- # @see #breadth_each
- def each(&block) # :yields: node
- yield self
- children { |child| child.each(&block) }
- end
-
- # Traverses the (sub)tree rooted at the receiver node in pre-ordered sequence.
- # This is a synonym of {Tree::TreeNode#each}.
- #
- # @yield [child] Each child is passed to the block.
- # @yieldparam [Tree::TreeNode] node Each node.
- #
- # @see #each
- # @see #breadth_each
- def preordered_each(&block) # :yields: node
- each(&block)
- end
-
- # Performs breadth-first traversal of the (sub)tree rooted at the receiver node. The
- # traversal at a given level is from *left-to-right*. The receiver node itself is the first
- # node to be traversed.
- #
- # @yield [child] Each node is passed to the block.
- # @yieldparam [Tree::TreeNode] node Each node.
- #
- # @see #preordered_each
- # @see #breadth_each
- def breadth_each(&block)
- node_queue = [self] # Create a queue with self as the initial entry
-
- # Use a queue to do breadth traversal
- until node_queue.empty?
- node_to_traverse = node_queue.shift
- yield node_to_traverse
- # Enqueue the children from left to right.
- node_to_traverse.children { |child| node_queue.push child }
- end
- end
-
- # Yields every leaf node of the (sub)tree rooted at the receiver node to the specified block.
- #
- # May yield this node as well if this is a leaf node.
- # Leaf traversal is *depth-first* and *left-to-right*.
- #
- # @yield [node] Each leaf node is passed to the block.
- # @yieldparam [Tree::TreeNode] node Each leaf node.
- #
- # @see #each
- # @see #breadth_each
- def each_leaf &block
- self.each { |node| yield(node) if node.isLeaf? }
- end
-
- # Returns the requested node from the set of immediate children.
- #
- # If the argument is _numeric_, then the in-sequence array of children is accessed using
- # the argument as the *index* (zero-based).
- #
- # If the argument is *NOT* _numeric_, then it is taken to be the *name* of the child node to be returned.
- #
- # An ArgumentError exception is raised if neither name nor an index is provided.
- #
- # @param [String|Number] name_or_index Name of the child, or its positional index in the array of child nodes.
- #
- # @return [Tree::TreeNode] the requested child node. If the index in not in range, or the name is not
- # present, then a +nil+ is returned.
- #
- # @raise [ArgumentError] Raised if neither name nor index is provided.
- #
- # @see #add
- def [](name_or_index)
- raise ArgumentError, "Name_or_index needs to be provided!" if name_or_index == nil
-
- if name_or_index.kind_of?(Integer)
- @children[name_or_index]
- else
- @childrenHash[name_or_index]
- end
- end
-
- # Returns the total number of nodes in this (sub)tree, including the receiver node.
- #
- # Size of the tree is defined as:
- #
- # Size:: Total number nodes in the subtree including the receiver node.
- #
- # @return [Number] Total number of nodes in this (sub)tree.
- def size
- @children.inject(1) {|sum, node| sum + node.size}
- end
-
- # Convenience synonym for {Tree::TreeNode#size}.
- #
- # @todo The semantic of length is probably unclear. Should return the node depth instead
- # to reflect the path length.
- #
- # @deprecated This method name is ambiguous and may be removed. Use TreeNode#size instead.
- #
- # @return [Number] The total number of nodes in this (sub)tree.
- # @see #size
- def length
- size()
- end
-
- # Pretty prints the (sub)tree rooted at the receiver node.
- #
- # @param [Number] level The indentation level (4 spaces) to start with.
- def printTree(level = 0)
-
- if isRoot?
- print "*"
- else
- print "|" unless parent.isLastSibling?
- print(' ' * (level - 1) * 4)
- print(isLastSibling? ? "+" : "|")
- print "---"
- print(hasChildren? ? "+" : ">")
- end
-
- puts " #{name}"
-
- children { |child| child.printTree(level + 1)}
- end
-
- # Returns root node for the (sub)tree to which the receiver node belongs.
- #
- # Note that a root node's root is itself (*beware* of any loop construct that may become infinite!)
- #
- # @todo We should perhaps return nil as root's root.
- #
- # @return [Tree::TreeNode] Root of the (sub)tree.
- def root
- root = self
- root = root.parent while !root.isRoot?
- root
- end
-
- # Returns the first sibling of the receiver node. If this is the root node, then returns
- # itself.
- #
- # 'First' sibling is defined as follows:
- # First sibling:: The left-most child of the receiver's parent, which may be the receiver itself
- #
- # @todo Fix the inconsistency of returning root as its first sibling, and returning
- # a +nil+ array for siblings of the node.
- #
- # @return [Tree::TreeNode] The first sibling node.
- #
- # @see #isFirstSibling?
- # @see #lastSibling
- def firstSibling
- isRoot? ? self : parent.children.first
- end
-
- # Returns +true+ if the receiver node is the first sibling at its level.
- #
- # @return [Boolean] +true+ if this is the first sibling.
- #
- # @see #isLastSibling?
- # @see #firstSibling
- def isFirstSibling?
- firstSibling == self
- end
-
- # Returns the last sibling of the receiver node. If this is the root node, then returns
- # itself.
- #
- # 'Last' sibling is defined as follows:
- # Last sibling:: The right-most child of the receiver's parent, which may be the receiver itself
- #
- # @todo Fix the inconsistency of returning root as its last sibling, and returning
- # a +nil+ array for siblings of the node.
- #
- # @return [Tree::TreeNode] The last sibling node.
- #
- # @see #isLastSibling?
- # @see #firstSibling
- def lastSibling
- isRoot? ? self : parent.children.last
- end
-
- # Returns +true+ if the receiver node is the last sibling at its level.
- #
- # @return [Boolean] +true+ if this is the last sibling.
- #
- # @see #isFirstSibling?
- # @see #lastSibling
- def isLastSibling?
- lastSibling == self
- end
-
- # Returns an array of siblings for the receiver node. The receiver node is excluded.
- #
- # If a block is provided, yields each of the sibling nodes to the block.
- # The root always has +nil+ siblings.
- #
- # @todo Fix the inconsistency of returning root as its own first/last sibling, and returning
- # a +nil+ array for siblings of the same root node.
- # @todo Also fix the inconsistency of returning +nil+ for a root node, and an empty array for nodes
- # which have no siblings.
- #
- # @yield [sibling] Each sibling is passed to the block.
- # @yieldparam [Tree::TreeNode] sibling Each sibling node.
- #
- # @return [Array<Tree::TreeNode>] Array of siblings of this node.
- #
- # @see #firstSibling
- # @see #lastSibling
- def siblings
- return nil if isRoot?
-
- if block_given?
- for sibling in parent.children
- yield sibling if sibling != self
- end
- else
- siblings = []
- parent.children {|my_sibling| siblings << my_sibling if my_sibling != self}
- siblings
- end
- end
-
- # Returns +true+ if the receiver node is the only child of its parent.
- #
- # As a special case, a root node will always return +true+.
- #
- # @return [Boolean] +true+ if this is the only child of its parent.
- #
- # @see #siblings
- def isOnlyChild?
- isRoot? ? true : parent.children.size == 1
- end
-
- # Returns the next sibling for the receiver node.
- # The 'next' node is defined as the node to right of the receiver node.
- #
- # Will return +nil+ if no subsequent node is present, or if the receiver is a root node.
- #
- # @return [Tree::treeNode] the next sibling node, if present.
- #
- # @see #previousSibling
- # @see #siblings
- def nextSibling
- return nil if isRoot?
- if myidx = parent.children.index(self)
- parent.children.at(myidx + 1)
- end
- end
-
- # Returns the previous sibling of the receiver node.
- # 'Previous' node is defined to be the node to left of the receiver node.
- #
- # Will return +nil+ if no predecessor node is present, or if the receiver is a root node.
- #
- # @return [Tree::treeNode] the previous sibling node, if present.
- #
- # @see #nextSibling
- # @see #siblings
- def previousSibling
- return nil if isRoot?
- if myidx = parent.children.index(self)
- parent.children.at(myidx - 1) if myidx > 0
- end
- end
-
- # Provides a comparision operation for the nodes.
- #
- # Comparision is based on the natural character-set ordering of the node name.
- #
- # @param [Tree::TreeNode] other The other node to compare against.
- #
- # @return [Number] +1 if this node is a 'successor', 0 if equal and -1 if this node is a 'predecessor'.
- def <=>(other)
- return +1 if other == nil
- self.name <=> other.name
- end
-
- # Freezes all nodes in the (sub)tree rooted at the receiver node.
- #
- # The nodes become immutable after this operation. In effect, the entire tree's
- # structure and contents become _read-only_ and cannot be changed.
- def freezeTree!
- each {|node| node.freeze}
- end
-
- # Returns a marshal-dump represention of the (sub)tree rooted at the receiver node.
- def marshal_dump
- self.collect { |node| node.createDumpRep }
- end
-
- # Creates a dump representation of the reciever node and returns the same as a hash.
- def createDumpRep # :nodoc:
- { :name => @name, :parent => (isRoot? ? nil : @parent.name), :content => Marshal.dump(@content)}
- end
-
- # Loads a marshalled dump of a tree and returns the root node of the
- # reconstructed tree. See the Marshal class for additional details.
- #
- #
- # @todo This method probably should be a class method. It currently clobbers self
- # and makes itself the root.
- #
- def marshal_load(dumped_tree_array)
- nodes = { }
- for node_hash in dumped_tree_array do
- name = node_hash[:name]
- parent_name = node_hash[:parent]
- content = Marshal.load(node_hash[:content])
-
- if parent_name then
- nodes[name] = current_node = Tree::TreeNode.new(name, content)
- nodes[parent_name].add current_node
- else
- # This is the root node, hence initialize self.
- initialize(name, content)
-
- nodes[name] = self # Add self to the list of nodes
- end
- end
- end
-
- # Creates a JSON representation of this node including all it's children. This requires the JSON gem to be
- # available, or else the operation fails with a warning message.
- #
- # @author Dirk Breuer (http://github.com/railsbros-dirk)
- # @since 0.7.0
- #
- # @return The JSON representation of this subtree.
- #
- # @see Tree::TreeNode.json_create
- # @see http://flori.github.com/json
- def to_json(*a)
- begin
- require 'json'
-
- json_hash = {
- "name" => name,
- "content" => content,
- JSON.create_id => self.class.name
- }
-
- if hasChildren?
- json_hash["children"] = children
- end
-
- return json_hash.to_json
-
- rescue LoadError => e
- warn "The JSON gem couldn't be loaded. Due to this we cannot serialize the tree to a JSON representation"
- end
- end
-
- # Creates a Tree::TreeNode object instance from a given JSON Hash representation. This requires the JSON gem to be
- # available, or else the operation fails with a warning message.
- #
- # @author Dirk Breuer (http://github.com/railsbros-dirk)
- # @since 0.7.0
- #
- # @param [Hash] json_hash The JSON hash to convert from.
- #
- # @return [Tree::TreeNode] The created tree.
- #
- # @see #to_json
- # @see http://flori.github.com/json
- def self.json_create(json_hash)
- begin
- require 'json'
-
- node = new(json_hash["name"], json_hash["content"])
-
- json_hash["children"].each do |child|
- node << child
- end if json_hash["children"]
-
- return node
- rescue LoadError => e
- warn "The JSON gem couldn't be loaded. Due to this we cannot serialize the tree to a JSON representation."
- end
- end
-
- # Returns height of the (sub)tree from the receiver node. Height of a node is defined as:
- #
- # Height:: Length of the longest downward path to a leaf from the node.
- #
- # - Height from a root node is height of the entire tree.
- # - The height of a leaf node is zero.
- #
- # @return [Number] Height of the node.
- def nodeHeight
- return 0 if isLeaf?
- 1 + @children.collect { |child| child.nodeHeight }.max
- end
-
- # Returns depth of the receiver node in its tree. Depth of a node is defined as:
- #
- # Depth:: Length of the node's path to its root. Depth of a root node is zero.
- #
- # 'level' is an alias for this method.
- #
- # @return [Number] Depth of this node.
- def nodeDepth
- return 0 if isRoot?
- 1 + parent.nodeDepth
- end
-
- alias level nodeDepth # Aliased level() method to the nodeDepth().
-
- # Returns depth of the tree from the receiver node. A single leaf node has a depth of 1.
- #
- # This method is *DEPRECATED* and may be removed in the subsequent releases.
- # Note that the value returned by this method is actually the:
- #
- # _height_ + 1 of the node, *NOT* the _depth_.
- #
- # For correct and conventional behavior, please use {Tree::TreeNode#nodeDepth} and
- # {Tree::TreeNode#nodeHeight} methods instead.
- #
- # @return [Number] depth of the node.
- # @deprecated This method returns an incorrect value. Use the 'nodeDepth' method instead.
- #
- # @see #nodeDepth
- def depth
- begin
- require 'structured_warnings' # To enable a nice way of deprecating of the depth method.
- warn DeprecatedMethodWarning, 'This method is deprecated. Please use nodeDepth() or nodeHeight() instead (bug # 22535)'
- rescue LoadError
- # Oh well. Will use the standard Kernel#warn. Behavior will be identical.
- warn 'Tree::TreeNode#depth() method is deprecated. Please use nodeDepth() or nodeHeight() instead (bug # 22535)'
- end
-
- return 1 if isLeaf?
- 1 + @children.collect { |child| child.depth }.max
- end
-
- # Returns breadth of the tree at the receiver node's level.
- # A single node without siblings has a breadth of 1.
- #
- # Breadth is defined to be:
- # Breadth:: Number of sibling nodes to this node + 1 (this node itself),
- # i.e., the number of children the parent of this node has.
- #
- # @return [Number] breadth of the node's level.
- def breadth
- isRoot? ? 1 : parent.children.size
- end
-
- # Returns the incoming edge-count of the receiver node.
- #
- # In-degree is defined as:
- # In-degree:: The number of edges arriving at the node (0 for root, 1 for all other nodes)
- #
- # - In-degree = 0 for a root or orphaned node
- # - In-degree = 1 for a node which has a parent
- #
- # @return [Number] The in-degree of this node.
- def in_degree
- isRoot? ? 0 : 1
- end
-
- # Returns the outgoing edge-count of the receiver node.
- #
- # Out-degree is defined as:
- # Out-degree:: The number of edges leaving the node (zero for leafs)
- #
- # @return [Number] The out-degree of this node.
- def out_degree
- isLeaf? ? 0 : children.size
- end
-
- protected :parent=, :setAsRoot!, :createDumpRep
-
- end
-end
144 vendor/please_remove_me_gems/rubytree-0.7.0/lib/tree/binarytree.rb
View
@@ -1,144 +0,0 @@
-# binarytree.rb - This file is part of the RubyTree package.
-#
-# $Revision$ by $Author$ on $Date$
-#
-# = binarytree.rb - An implementation of the binary tree data structure.
-#
-# Provides a binary tree data structure with ability to
-# store two node elements as children at each node in the tree.
-#
-# Author:: Anupam Sengupta (anupamsg@gmail.com)
-#
-
-# Copyright (c) 2007, 2008, 2009, 2010 Anupam Sengupta
-#
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-#
-# - Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# - Redistributions in binary form must reproduce the above copyright notice, this
-# list of conditions and the following disclaimer in the documentation and/or
-# other materials provided with the distribution.
-#
-# - Neither the name of the organization nor the names of its contributors may
-# be used to endorse or promote products derived from this software without
-# specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-require 'tree'
-
-module Tree
-
- # Provides a Binary tree implementation. This node allows only two child nodes (left and right child). It also
- # provides direct access to the left or right child, including assignment to the same.
- #
- # This inherits from the {Tree::TreeNode} class.
- #
- # @author Anupam Sengupta
- #
- class BinaryTreeNode < TreeNode
-
- # Adds the specified child node to the receiver node. The child node's parent is set to be the receiver.
- #
- # The child nodes are added in the order of addition, i.e., the first child added becomes the left node, and the
- # second child added will be the second node.
- #
- # If only one child is present, then this will be the left child.
- #
- # @param [Tree::BinaryTreeNode] child The child to add.
- #
- # @raise [ArgumentError] This exception is raised if two children are already present.
- def add(child)
- raise ArgumentError, "Already has two child nodes" if @children.size == 2
-
- super(child)
- end
-
- # Returns the left child of the receiver node. Note that left Child == first Child.
- #
- # @return [Tree::BinaryTreeNode] The left most (or first) child.
- #
- # @see #rightChild
- def leftChild
- children.first
- end
-
- # Returns the right child of the receiver node. Note that right child == last child unless there is only one child.
- #
- # Returns +nil+ if the right child does not exist.
- #
- # @return [Tree::BinaryTreeNode] The right child, or +nil+ if the right side child does not exist.
- #
- # @see #leftChild
- def rightChild
- children[1]
- end
-
- # Sets the left child of the receiver node. If a previous child existed, it is replaced.
- #
- # @param [Tree::BinaryTreeNode] child The child to add as the left-side node.
- #
- # @return [Tree::BinaryTreeNode] The assigned child node.
- #
- # @see #leftChild
- # @see #rightChild=
- def leftChild=(child)
- @children[0] = child
- @childrenHash[child.name] = child if child # Assign the name mapping
- end
-
- # Sets the right child of the receiver node. If a previous child existed, it is replaced.
- #
- # @param [Tree::BinaryTreeNode] child The child to add as the right-side node.
- #
- # @return [Tree::BinaryTreeNode] The assigned child node.
- #
- # @see #rightChild
- # @see #leftChild=
- def rightChild=(child)
- @children[1] = child
- @childrenHash[child.name] = child if child # Assign the name mapping
- end
-
- # Returns +true+ if the receiver node is the left child of its parent.
- # Always returns +false+ if it is a root node.
- #
- # @return [Boolean] +true+ if this is the left child of its parent.
- def isLeftChild?
- return false if isRoot?
- self == parent.leftChild
- end
-
- # Returns +true+ if the receiver node is the right child of its parent.
- # Always returns +false+ if it is a root node.
- #
- # @return [Boolean] +true+ if this is the right child of its parent.
- def isRightChild?
- return false if isRoot?
- self == parent.rightChild
- end
-
- # Swaps the left and right child nodes of the receiver node with each other.
- #
- # @todo Define the return value.
- def swap_children
- self.leftChild, self.rightChild = self.rightChild, self.leftChild
- end
- end
-
-end
1,585 vendor/please_remove_me_gems/rubytree-0.7.0/setup.rb
View
@@ -1,1585 +0,0 @@
-#
-# setup.rb
-#
-# Copyright (c) 2000-2005 Minero Aoki
-#
-# This program is free software.
-# You can distribute/modify this program under the terms of
-# the GNU LGPL, Lesser General Public License version 2.1.
-#
-
-unless Enumerable.method_defined?(:map) # Ruby 1.4.6
- module Enumerable
- alias map collect
- end
-end
-
-unless File.respond_to?(:read) # Ruby 1.6
- def File.read(fname)
- open(fname) {|f|
- return f.read
- }
- end
-end
-
-unless Errno.const_defined?(:ENOTEMPTY) # Windows?
- module Errno
- class ENOTEMPTY
- # We do not raise this exception, implementation is not needed.
- end
- end
-end
-
-def File.binread(fname)
- open(fname, 'rb') {|f|
- return f.read
- }
-end
-
-# for corrupted Windows' stat(2)
-def File.dir?(path)
- File.directory?((path[-1,1] == '/') ? path : path + '/')
-end
-
-
-class ConfigTable
-
- include Enumerable
-
- def initialize(rbconfig)
- @rbconfig = rbconfig
- @items = []
- @table = {}
- # options
- @install_prefix = nil
- @config_opt = nil
- @verbose = true
- @no_harm = false
- end
-
- attr_accessor :install_prefix
- attr_accessor :config_opt
-
- attr_writer :verbose
-
- def verbose?
- @verbose
- end
-
- attr_writer :no_harm
-
- def no_harm?
- @no_harm
- end
-
- def [](key)
- lookup(key).resolve(self)
- end
-
- def []=(key, val)
- lookup(key).set val
- end
-
- def names
- @items.map {|i| i.name }
- end
-
- def each(&block)
- @items.each(&block)
- end
-
- def key?(name)
- @table.key?(name)
- end
-
- def lookup(name)
- @table[name] or setup_rb_error "no such config item: #{name}"
- end
-
- def add(item)
- @items.push item
- @table[item.name] = item
- end
-
- def remove(name)
- item = lookup(name)
- @items.delete_if {|i| i.name == name }
- @table.delete_if {|name, i| i.name == name }
- item
- end
-
- def load_script(path, inst = nil)
- if File.file?(path)
- MetaConfigEnvironment.new(self, inst).instance_eval File.read(path), path
- end
- end
-
- def savefile
- '.config'
- end
-
- def load_savefile
- begin
- File.foreach(savefile()) do |line|
- k, v = *line.split(/=/, 2)
- self[k] = v.strip
- end
- rescue Errno::ENOENT
- setup_rb_error $!.message + "\n#{File.basename($0)} config first"
- end
- end
-
- def save
- @items.each {|i| i.value }
- File.open(savefile(), 'w') {|f|
- @items.each do |i|
- f.printf "%s=%s\n", i.name, i.value if i.value? and i.value
- end
- }
- end
-
- def load_standard_entries
- standard_entries(@rbconfig).each do |ent|
- add ent
- end
- end
-
- def standard_entries(rbconfig)
- c = rbconfig
-
- rubypath = File.join(c['bindir'], c['ruby_install_name'] + c['EXEEXT'])
-
- major = c['MAJOR'].to_i
- minor = c['MINOR'].to_i
- teeny = c['TEENY'].to_i
- version = "#{major}.#{minor}"
-
- # ruby ver. >= 1.4.4?
- newpath_p = ((major >= 2) or
- ((major == 1) and
- ((minor >= 5) or
- ((minor == 4) and (teeny >= 4)))))
-
- if c['rubylibdir']
- # V > 1.6.3
- libruby = "#{c['prefix']}/lib/ruby"
- librubyver = c['rubylibdir']
- librubyverarch = c['archdir']
- siteruby = c['sitedir']
- siterubyver = c['sitelibdir']
- siterubyverarch = c['sitearchdir']
- elsif newpath_p
- # 1.4.4 <= V <= 1.6.3
- libruby = "#{c['prefix']}/lib/ruby"
- librubyver = "#{c['prefix']}/lib/ruby/#{version}"
- librubyverarch = "#{c['prefix']}/lib/ruby/#{version}/#{c['arch']}"
- siteruby = c['sitedir']
- siterubyver = "$siteruby/#{version}"
- siterubyverarch = "$siterubyver/#{c['arch']}"
- else
- # V < 1.4.4
- libruby = "#{c['prefix']}/lib/ruby"
- librubyver = "#{c['prefix']}/lib/ruby/#{version}"
- librubyverarch = "#{c['prefix']}/lib/ruby/#{version}/#{c['arch']}"
- siteruby = "#{c['prefix']}/lib/ruby/#{version}/site_ruby"
- siterubyver = siteruby
- siterubyverarch = "$siterubyver/#{c['arch']}"
- end
- parameterize = lambda {|path|
- path.sub(/\A#{Regexp.quote(c['prefix'])}/, '$prefix')
- }
-
- if arg = c['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg }
- makeprog = arg.sub(/'/, '').split(/=/, 2)[1]
- else
- makeprog = 'make'
- end
-
- [
- ExecItem.new('installdirs', 'std/site/home',
- 'std: install under libruby; site: install under site_ruby; home: install under $HOME')\
- {|val, table|
- case val
- when 'std'
- table['rbdir'] = '$librubyver'
- table['sodir'] = '$librubyverarch'
- when 'site'
- table['rbdir'] = '$siterubyver'
- table['sodir'] = '$siterubyverarch'
- when 'home'
- setup_rb_error '$HOME was not set' unless ENV['HOME']
- table['prefix'] = ENV['HOME']
- table['rbdir'] = '$libdir/ruby'
- table['sodir'] = '$libdir/ruby'
- end
- },
- PathItem.new('prefix', 'path', c['prefix'],
- 'path prefix of target environment'),
- PathItem.new('bindir', 'path', parameterize.call(c['bindir']),
- 'the directory for commands'),
- PathItem.new('libdir', 'path', parameterize.call(c['libdir']),
- 'the directory for libraries'),
- PathItem.new('datadir', 'path', parameterize.call(c['datadir']),
- 'the directory for shared data'),
- PathItem.new('mandir', 'path', parameterize.call(c['mandir']),
- 'the directory for man pages'),
- PathItem.new('sysconfdir', 'path', parameterize.call(c['sysconfdir']),
- 'the directory for system configuration files'),
- PathItem.new('localstatedir', 'path', parameterize.call(c['localstatedir']),
- 'the directory for local state data'),
- PathItem.new('libruby', 'path', libruby,
- 'the directory for ruby libraries'),
- PathItem.new('librubyver', 'path', librubyver,
- 'the directory for standard ruby libraries'),
- PathItem.new('librubyverarch', 'path', librubyverarch,
- 'the directory for standard ruby extensions'),
- PathItem.new('siteruby', 'path', siteruby,
- 'the directory for version-independent aux ruby libraries'),
- PathItem.new('siterubyver', 'path', siterubyver,
- 'the directory for aux ruby libraries'),
- PathItem.new('siterubyverarch', 'path', siterubyverarch,
- 'the directory for aux ruby binaries'),
- PathItem.new('rbdir', 'path', '$siterubyver',
- 'the directory for ruby scripts'),
- PathItem.new('sodir', 'path', '$siterubyverarch',
- 'the directory for ruby extentions'),
- PathItem.new('rubypath', 'path', rubypath,
- 'the path to set to #! line'),
- ProgramItem.new('rubyprog', 'name', rubypath,
- 'the ruby program using for installation'),
- ProgramItem.new('makeprog', 'name', makeprog,
- 'the make program to compile ruby extentions'),
- SelectItem.new('shebang', 'all/ruby/never', 'ruby',
- 'shebang line (#!) editing mode'),
- BoolItem.new('without-ext', 'yes/no', 'no',
- 'does not compile/install ruby extentions')
- ]
- end
- private :standard_entries
-
- def load_multipackage_entries
- multipackage_entries().each do |ent|
- add ent
- end
- end
-
- def multipackage_entries
- [
- PackageSelectionItem.new('with', 'name,name...', '', 'ALL',
- 'package names that you want to install'),
- PackageSelectionItem.new('without', 'name,name...', '', 'NONE',
- 'package names that you do not want to install')
- ]
- end
- private :multipackage_entries
-
- ALIASES = {
- 'std-ruby' => 'librubyver',
- 'stdruby' => 'librubyver',
- 'rubylibdir' => 'librubyver',
- 'archdir' => 'librubyverarch',
- 'site-ruby-common' => 'siteruby', # For backward compatibility
- 'site-ruby' => 'siterubyver', # For backward compatibility
- 'bin-dir' => 'bindir',
- 'bin-dir' => 'bindir',
- 'rb-dir' => 'rbdir',
- 'so-dir' => 'sodir',
- 'data-dir' => 'datadir',
- 'ruby-path' => 'rubypath',
- 'ruby-prog' => 'rubyprog',
- 'ruby' => 'rubyprog',
- 'make-prog' => 'makeprog',
- 'make' => 'makeprog'
- }
-
- def fixup
- ALIASES.each do |ali, name|
- @table[ali] = @table[name]
- end
- @items.freeze
- @table.freeze
- @options_re = /\A--(#{@table.keys.join('|')})(?:=(.*))?\z/
- end
-
- def parse_opt(opt)
- m = @options_re.match(opt) or setup_rb_error "config: unknown option #{opt}"
- m.to_a[1,2]
- end
-
- def dllext
- @rbconfig['DLEXT']
- end
-
- def value_config?(name)
- lookup(name).value?
- end
-
- class Item
- def initialize(name, template, default, desc)
- @name = name.freeze
- @template = template
- @value = default
- @default = default
- @description = desc
- end
-
- attr_reader :name
- attr_reader :description
-
- attr_accessor :default
- alias help_default default
-
- def help_opt
- "--#{@name}=#{@template}"
- end
-
- def value?
- true
- end
-
- def value
- @value
- end
-
- def resolve(table)
- @value.gsub(%r<\$([^/]+)>) { table[$1] }
- end
-
- def set(val)
- @value = check(val)
- end
-
- private
-
- def check(val)
- setup_rb_error "config: --#{name} requires argument" unless val
- val
- end
- end
-
- class BoolItem < Item
- def config_type
- 'bool'
- end
-
- def help_opt
- "--#{@name}"
- end
-
- private
-
- def check(val)
- return 'yes' unless val
- case val
- when /\Ay(es)?\z/i, /\At(rue)?\z/i then 'yes'
- when /\An(o)?\z/i, /\Af(alse)\z/i then 'no'
- else
- setup_rb_error "config: --#{@name} accepts only yes/no for argument"
- end
- end
- end
-
- class PathItem < Item
- def config_type
- 'path'
- end
-
- private
-
- def check(path)
- setup_rb_error "config: --#{@name} requires argument" unless path
- path[0,1] == '$' ? path : File.expand_path(path)
- end
- end
-
- class ProgramItem < Item
- def config_type
- 'program'
- end
- end
-
- class SelectItem < Item
- def initialize(name, selection, default, desc)
- super
- @ok = selection.split('/')
- end
-
- def config_type
- 'select'
- end
-
- private
-
- def check(val)
- unless @ok.include?(val.strip)
- setup_rb_error "config: use --#{@name}=#{@template} (#{val})"
- end
- val.strip
- end
- end
-
- class ExecItem < Item
- def initialize(name, selection, desc, &block)
- super name, selection, nil, desc
- @ok = selection.split('/')
- @action = block
- end
-
- def config_type
- 'exec'
- end
-
- def value?
- false
- end
-
- def resolve(table)
- setup_rb_error "$#{name()} wrongly used as option value"
- end
-
- undef set
-
- def evaluate(val, table)
- v = val.strip.downcase
- unless @ok.include?(v)
- setup_rb_error "invalid option --#{@name}=#{val} (use #{@template})"
- end
- @action.call v, table
- end
- end
-
- class PackageSelectionItem < Item
- def initialize(name, template, default, help_default, desc)
- super name, template, default, desc
- @help_default = help_default
- end
-
- attr_reader :help_default
-
- def config_type
- 'package'
- end
-
- private
-
- def check(val)
- unless File.dir?("packages/#{val}")
- setup_rb_error "config: no such package: #{val}"
- end
- val
- end
- end
-
- class MetaConfigEnvironment
- def initialize(config, installer)
- @config = config
- @installer = installer
- end
-
- def config_names
- @config.names
- end
-
- def config?(name)
- @config.key?(name)
- end
-
- def bool_config?(name)
- @config.lookup(name).config_type == 'bool'
- end
-
- def path_config?(name)
- @config.lookup(name).config_type == 'path'
- end
-
- def value_config?(name)
- @config.lookup(name).config_type != 'exec'
- end
-
- def add_config(item)
- @config.add item
- end
-
- def add_bool_config(name, default, desc)
- @config.add BoolItem.new(name, 'yes/no', default ? 'yes' : 'no', desc)
- end
-
- def add_path_config(name, default, desc)
- @config.add PathItem.new(name, 'path', default, desc)
- end
-
- def set_config_default(name, default)
- @config.lookup(name).default = default
- end
-
- def remove_config(name)
- @config.remove(name)
- end
-
- # For only multipackage
- def packages
- raise '[setup.rb fatal] multi-package metaconfig API packages() called for single-package; contact application package vendor' unless @installer
- @installer.packages
- end
-
- # For only multipackage
- def declare_packages(list)
- raise '[setup.rb fatal] multi-package metaconfig API declare_packages() called for single-package; contact application package vendor' unless @installer
- @installer.packages = list
- end
- end
-
-end # class ConfigTable
-
-
-# This module requires: #verbose?, #no_harm?
-module FileOperations
-
- def mkdir_p(dirname, prefix = nil)
- dirname = prefix + File.expand_path(dirname) if prefix
- $stderr.puts "mkdir -p #{dirname}" if verbose?
- return if no_harm?
-
- # Does not check '/', it's too abnormal.
- dirs = File.expand_path(dirname).split(%r<(?=/)>)
- if /\A[a-z]:\z/i =~ dirs[0]
- disk = dirs.shift
- dirs[0] = disk + dirs[0]
- end
- dirs.each_index do |idx|
- path = dirs[0..idx].join('')
- Dir.mkdir path unless File.dir?(path)
- end
- end
-
- def rm_f(path)
- $stderr.puts "rm -f #{path}" if verbose?
- return if no_harm?
- force_remove_file path
- end
-
- def rm_rf(path)
- $stderr.puts "rm -rf #{path}" if verbose?
- return if no_harm?
- remove_tree path
- end
-
- def remove_tree(path)
- if File.symlink?(path)
- remove_file path
- elsif File.dir?(path)
- remove_tree0 path
- else
- force_remove_file path
- end
- end
-
- def remove_tree0(path)
- Dir.foreach(path) do |ent|
- next if ent == '.'
- next if ent == '..'
- entpath = "#{path}/#{ent}"
- if File.symlink?(entpath)
- remove_file entpath
- elsif File.dir?(entpath)
- remove_tree0 entpath
- else
- force_remove_file entpath
- end
- end
- begin
- Dir.rmdir path
- rescue Errno::ENOTEMPTY
- # directory may not be empty
- end
- end
-
- def move_file(src, dest)
- force_remove_file dest
- begin
- File.rename src, dest
- rescue
- File.open(dest, 'wb') {|f|
- f.write File.binread(src)
- }
- File.chmod File.stat(src).mode, dest
- File.unlink src
- end
- end
-
- def force_remove_file(path)
- begin
- remove_file path
- rescue
- end
- end
-
- def remove_file(path)
- File.chmod 0777, path
- File.unlink path
- end
-
- def install(from, dest, mode, prefix = nil)
- $stderr.puts "install #{from} #{dest}" if verbose?
- return if no_harm?
-
- realdest = prefix ? prefix + File.expand_path(dest) : dest
- realdest = File.join(realdest, File.basename(from)) if File.dir?(realdest)
- str = File.binread(from)
- if diff?(str, realdest)
- verbose_off {
- rm_f realdest if File.exist?(realdest)
- }
- File.open(realdest, 'wb') {|f|
- f.write str
- }
- File.chmod mode, realdest
-
- File.open("#{objdir_root()}/InstalledFiles", 'a') {|f|
- if prefix
- f.puts realdest.sub(prefix, '')
- else
- f.puts realdest
- end
- }
- end
- end
-
- def diff?(new_content, path)
- return true unless File.exist?(path)
- new_content != File.binread(path)
- end
-
- def command(*args)
- $stderr.puts args.join(' ') if verbose?
- system(*args) or raise RuntimeError,
- "system(#{args.map{|a| a.inspect }.join(' ')}) failed"
- end
-
- def ruby(*args)
- command config('rubyprog'), *args
- end
-
- def make(task = nil)
- command(*[config('makeprog'), task].compact)
- end
-
- def extdir?(dir)
- File.exist?("#{dir}/MANIFEST") or File.exist?("#{dir}/extconf.rb")
- end
-
- def files_of(dir)
- Dir.open(dir) {|d|
- return d.select {|ent| File.file?("#{dir}/#{ent}") }
- }
- end
-
- DIR_REJECT = %w( . .. CVS SCCS RCS CVS.adm .svn )
-
- def directories_of(dir)
- Dir.open(dir) {|d|