Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .autotest
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Guardfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.textile
Octocat-spinner-32 Rakefile
Octocat-spinner-32 dotanuki-ruby.gemspec
Octocat-spinner-32 dotanuki.gemspec
README.textile

Dotanuki

Simple but effective executioner of commands, which will deal correctly with failed commands.

There are two versions of the Dotanuki gem dotanuki which uses posix-spawn and a pure ruby version dotanuki-ruby which uses open4 instead.

Note that if the pure ruby version can load posix-spawn it will use it.

Examples

In the following example, if the mkdir fails, none of the other commands will be executed.

  require "dotanuki"

  class Example
    include Dotanuki

    def test
      commands = [
        "mkdir /tmp/foo",
        "cp /etc/hosts /tmp/foo",
        "cp /etc/passwd /tmp/foo"
      ]

      result = execute(commands)
      if result.failed?
        puts "execution failed: #{result.fail_message}"
      end
    end
  end

It can also be used with a guard block, which will raise an ExecError if a command fails.

  require "dotanuki"

  class Example
    include Dotanuki

    def test
      guard do
        execute "mkdir /tmp/foo"
        execute "cp /etc/hosts /tmp/foo"
        execute "cp /etc/passwd /tmp/foo"
      end
    end
  end

If you want to use dotanuki in a class method, you have to use the module method

  require "dotanuki"

  class Example
    def self.test?
      Dotanuki.execute("mkdir /tmp/foo").ok?
    end
  end
Something went wrong with that request. Please try again.