lib/capitate/plugins/base.rb in capitate-0.2.11 vs lib/capitate/plugins/base.rb in capitate-0.2.13

- old
+ new

@@ -3,22 +3,21 @@ # Capitate base capistrano plugin module Capitate::Plugins::Base # Project root. Fetch from :project_root, or fall back to RAILS_ROOT. - # def root - if respond_to?(:fetch) - return fetch(:project_root) - else - RAILS_ROOT - end + return fetch(:project_root) if exists?(:project_root) + RAILS_ROOT end # Path relative to project root. - # Project root is set via, set :project_root, "path/to/project" in Capfile. # + # To set the project root: + # + # set :project_root, "path/to/project" in Capfile. + # # ==== Options # +path+:: Relative path # +check_exist+:: Whether to check its existence and throw error if not found # # ==== Examples @@ -46,11 +45,11 @@ end # Usage for current task. # # ==== Options - # +variable+:: Missing variable setting + # +variable+:: Missing variable setting (to display as not set) # # ==== Examples # usage(:gem_list) => "Description from task definition." # def usage(variable = nil) @@ -84,40 +83,46 @@ return nil if s.blank? indentation = (0..amount).collect { |n| " " }.join s.split("\n").collect { |sp| "#{indentation}#{sp}"}.join("\n") end - # Unindent, lifted from capistrano bin/capify + # Unindent. + # + # Lifted from capistrano bin/capify + # + # ==== Options + # +string+:: String to unindent + # def unindent(string) return "" if string.blank? if string =~ /\A(\s*)/ amount = $1.length return string.strip.gsub(/^#{$1}/, "") end string end - # Load all tasks + # Load all tasks into an array. def load_all_tasks tasks = [] top.namespaces.each do |namespace| load_tasks(namespace, tasks) end tasks end - # Task tree + # Build a task tree, consisting of task nodes. def task_tree top_node = Capitate::TaskNode.new("top") load_all_tasks.each do |task| Capitate::TaskNode.populate_with_task(top_node, task) end top_node end protected - + def load_tasks(namespace, tasks = []) recipe = namespace.last recipe.namespaces.each do |nested_namespace| load_tasks(nested_namespace, tasks) \ No newline at end of file