Module: Chirp

Defined in:
lib/chirp/context.rb,
lib/chirp.rb,
lib/chirp/span.rb,
lib/chirp/application.rb,
lib/chirp/path_filter.rb,
lib/chirp/fs_expression.rb

Overview

require ‘erb’

Defined Under Namespace

Modules: FSSugar Classes: All, And, Application, Bigger, Contains, Context, EachProcessor, FSExpression, IsDir, IsFile, LineProcessor, Named, None, Not, NowProcessor, Or, PathFilter, PathProcessor, SameSize, Smaller, Span, StaringWithProcessor

Constant Summary collapse

VERSION =
'0.3'

Class Method Summary collapse

Class Method Details

.debug(*msg) ⇒ Object



49
50
51
# File 'lib/chirp/application.rb', line 49

def self.debug(*msg)
  STDERR.puts msg.join(' ')
end

.run_with_input_file(in_file, &block) ⇒ Object



26
27
28
# File 'lib/chirp/application.rb', line 26

def self.run_with_input_file(in_file, &block)
  File.open(in_file) {|f| run_with_input_stream(f, &block)}
end

.run_with_input_stream(in_stream, &block) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/chirp/application.rb', line 8

def self.run_with_input_stream(in_stream, &block)
  old_stdin, $stdin = $stdin, in_stream
  begin
    block.call
  ensure
    $stdin = old_stdin
  end
end

.run_with_output_file(out_file, create_backups = false, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/chirp/application.rb', line 30

def self.run_with_output_file(out_file, create_backups=false, &block)
  temp_file = Tempfile.new('chirp').path
  File.open(temp_file, 'w') do |out_stream|
    run_with_output_stream(out_stream, &block)
  end
  backup_file = nil
  if create_backups and File.exist?(out_file)
    backup_file = Tempfile.new('chirp').path
    FileUtils.cp(out_file, backup_file) if File.exist?(out_file)
  end
  FileUtils.cp(temp_file, out_file)
  FileUtils.rm(temp_file)
  if backup_file
    FileUtils.cp(backup_file, "#{out_file}.bak")
    FileUtils.rm(backup_file) 
  end
end

.run_with_output_stream(out_stream, &block) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/chirp/application.rb', line 17

def self.run_with_output_stream(out_stream, &block)
  old_stdout, $stdout = $stdout, out_stream
  begin
    block.call
  ensure
    $stdout = old_stdout
  end
end