Included Modules

Class/Module Index [+]

Quicksearch

DO::Commands

Public Instance Methods

current_server() click to toggle source

Returns the current server

# File lib/do/commands.rb, line 22
def current_server
  @_current_server
end
load(path) click to toggle source
Alias for: load_recipe
load_recipe(path) click to toggle source
# File lib/do/commands.rb, line 55
def load_recipe(path)
  instance_eval(File.read(path), __FILE__, __LINE__)
end
Also aliased as: load
load_recipes() click to toggle source
# File lib/do/commands.rb, line 51
def load_recipes
  recipes.each { |f| load_recipe(f) }
end
log(text="", new_line=true) click to toggle source

Log text under current_server if available

# File lib/do/commands.rb, line 112
def log(text="", new_line=true)
  current_server ? current_server.log(text, new_line) : super(text, new_line)
end
method_missing(method, *args, &block) click to toggle source
# File lib/do/commands.rb, line 123
def method_missing(method, *args,  &block)
  current_server && current_server.respond_to?(method) ? current_server.send(method, *args) : super(method, *args,  &block)
end
plugin(name, repo) click to toggle source

Install in your DO_PATH a remote task

Examples

# You can install/update task with
# rake plugin:configuration
plugin "configuration", "https://gist.github.com/raw/xys.rake"
# File lib/do/commands.rb, line 96
def plugin(name, repo)
  desc "install #{name} plugin"
  namespace :plugin do
    task(name => 'setup') do
      log "\e[36m## Installing plugin %s\e[0m" % name
      Dir.mkdir(DO_PATH) unless File.exist?(DO_PATH)
      path = File.join(DO_PATH, '%s.rake' % name)
      sh :curl, '--location', '--progress-bar', repo, '>', path
      load_recipe(path)
    end
  end
end
recipes() click to toggle source

DO loads rakefiles in these locations:

~/do/dorc
~/do/*.rake
./Do
./Dofile

DO_PATH, default is ~/do.

# File lib/do/commands.rb, line 43
def recipes
  @_recipes ||= (
    ]dorc **/*.rake].map { |f| Dir[File.join(DO_PATH, f)] }.flatten +
    ]./Do ./Dofile].map { |f| File.expand_path(f) } <<
    File.expand_path('../common.rb', __FILE__)
  ).reject { |f| !File.exist?(f) }
end
remote() click to toggle source
# File lib/do/commands.rb, line 15
def remote
  servers.map(&:name)
end
run(*args) click to toggle source

Run commands on current_server if available

# File lib/do/commands.rb, line 119
def run(*args)
  current_server ? current_server.run(*args) : super(*args)
end
server(name, host, user, options={}) click to toggle source

This method define our servers

Examples:

keys = %w[key1.pem key2.pem key3.pem key4.pem]
server :srv1, 's1.domain.local', 'user', :keys => keys
server :srv2, 's2.domain.local', 'user', :keys => keys
server :srv3, 's3.domain.local', 'user', :keys => keys
server :srv4, 's4.domain.local', 'user', :keys => keys
# File lib/do/commands.rb, line 70
def server(name, host, user, options={})
  servers.push(DO::Server.new(name, host, user, options))
  task name do |opts, b|
    allowed  = opts.map { |k,v| k if remote.include?(k) && v }.compact
    denied   = opts.map { |k,v| k if remote.include?(k) && v == false }.compact
    if (allowed.empty? && denied.empty?) ||
       (!allowed.empty? && allowed.include?(name)) ||
       (!denied.empty? && !denied.include?(name))
      @_current_server = servers.find { |s| s.name == name }
      begin
        b.arity == 1 ? b.call(opts) : b.call
      ensure
        @_current_server = nil
      end
    end
  end
end
servers() click to toggle source

Array of DO::Server defined in our tasks

# File lib/do/commands.rb, line 11
def servers
  @_servers ||= []
end
set(option, value) click to toggle source

Set an option to the given value

# File lib/do/commands.rb, line 29
def set(option, value)
  define_method(option) { value }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.