Module: Capitate::Plugins::Base
- Included in:
- TaskNode
- Defined in:
- lib/capitate/plugins/base.rb
Overview
Capitate base capistrano plugin
Instance Method Summary collapse
-
#indent_doc(s, amount = 4) ⇒ Object
Indent string block.
-
#load_all_tasks ⇒ Object
Load all tasks into an array.
-
#relative_to_root(path = nil, check_exist = false) ⇒ Object
Path relative to project root.
-
#root ⇒ Object
Project root.
-
#task_tree ⇒ Object
Build a task tree, consisting of task nodes.
-
#unindent(string) ⇒ Object
Unindent.
-
#usage(variable = nil) ⇒ Object
Usage for current task.
Instance Method Details
#indent_doc(s, amount = 4) ⇒ Object
Indent string block.
Options
s-
String block
amount-
Amount to indent
83 84 85 86 87 |
# File 'lib/capitate/plugins/base.rb', line 83 def indent_doc(s, amount = 4) return nil if s.blank? indentation = (0..amount).collect { |n| " " }.join s.split("\n").collect { |sp| "#{indentation}#{sp}"}.join("\n") end |
#load_all_tasks ⇒ Object
Load all tasks into an array.
106 107 108 109 110 111 112 |
# File 'lib/capitate/plugins/base.rb', line 106 def load_all_tasks tasks = [] top.namespaces.each do |namespace| load_tasks(namespace, tasks) end tasks end |
#relative_to_root(path = nil, check_exist = false) ⇒ Object
Path relative to project root.
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
relative_to_root("config/foo.yml") => "path/to/project/config/foo.yml"
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/capitate/plugins/base.rb', line 26 def relative_to_root(path = nil, check_exist = false) if path root_path = File.join(root, path) else root_path = root end # Check for file existance if check_exist and !File.exist?(root_path) raise " \n File not found: \#{File.expand_path(root_path)}\n \n This is loaded for the capitate plugin. View the README in:\n \#{File.expand_path(File.dirname(__FILE__) + \"/../doc/README\")}\n EOS\n end\n \n root_path\nend\n" |
#root ⇒ Object
Project root. Fetch from :project_root, or fall back to RAILS_ROOT.
8 9 10 11 |
# File 'lib/capitate/plugins/base.rb', line 8 def root return fetch(:project_root) if exists?(:project_root) RAILS_ROOT end |
#task_tree ⇒ Object
Build a task tree, consisting of task nodes.
115 116 117 118 119 120 121 122 |
# File 'lib/capitate/plugins/base.rb', line 115 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 |
#unindent(string) ⇒ Object
Unindent.
Lifted from capistrano bin/capify
Options
string-
String to unindent
96 97 98 99 100 101 102 103 |
# File 'lib/capitate/plugins/base.rb', line 96 def unindent(string) return "" if string.blank? if string =~ /\A(\s*)/ amount = $1.length return string.strip.gsub(/^#{$1}/, "") end string end |
#usage(variable = nil) ⇒ Object
Usage for current task.
Options
variable-
Missing variable setting (to display as not set)
Examples
usage(:gem_list) => "Description from task definition."
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/capitate/plugins/base.rb', line 55 def usage(variable = nil) = "" if variable += " \n Error: :\#{variable} not set. \n EOS\n end\n \n if current_task\n message += <<-EOS\n \n Usage: \n \n\#{indent_doc(current_task.desc)}\n \n EOS\n end\n message\nend\n" |