Module: SH

Defined in:
lib/choosy/rake.rb

Overview

This is a library task that others can use to expose functionality in their rake files It defines the ‘$version’ global variable to let users pull this information out into their own scripts.

Class Method Summary collapse

Class Method Details

.attempt(command, options = {}, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/choosy/rake.rb', line 7

def self.attempt(command, options={}, &block)
  contents = nil
  IO.popen("#{command} 2>&1", 'r') do |io|
    contents = io.read
  end
  if $? != 0
    yield [$?, contents] if block_given?

    if options[:error]
      raise options[:error]
    else
      puts contents
      raise "Unable to execute command: #{command}" unless options[:fail] == false
    end
  end 

  if options[:success] && contents !~ options[:success]
    raise "Command failed: #{command}"
  elsif options[:failure] && contents =~ options[:failure]
    raise "Command didn't succeed: #{command}"
  end

  puts contents unless options[:quiet]
end

.files(ending_with, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/choosy/rake.rb', line 32

def self.files(ending_with, &block)
  files = Dir.glob("*#{ending_with}")

  raise "No #{ending_with} files found." if files.empty?
  
  files.each do |file|
    yield file
  end
end