Module: QED::FileFixtures

Defined in:
lib/qed/helpers/file_fixtures.rb

Overview

This extension provides a simple means for creatind file-system fixtures. Include this in your applique, to have a

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


8
9
10
# File 'lib/qed/helpers/file_fixtures.rb', line 8

def self.included(base)
  require 'erb'
end

Instance Method Details

#copy_fixture(name, tmpdir = nil) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/qed/helpers/file_fixtures.rb', line 13

def copy_fixture(name, tmpdir=nil)
  tmpdir ||= 'tmp' # self.tmpdir
  FileUtils.mkdir(tmpdir) unless File.directory?(tmpdir)
  srcdir = File.join(demo_directory, 'fixtures', name)
  paths  = Dir.glob(File.join(srcdir, '**', '*'), File::FNM_DOTMATCH)
  paths.each do |path|
    basename = File.basename(path)
    next if basename == '.'
    next if basename == '..'
    dest = File.join(tmpdir, path.sub(srcdir+'/', ''))
    if File.directory?(path)
      FileUtils.mkdir(dest)
    else
      text = ERB.new(File.read(path)).result
      File.open(dest, 'w'){ |f| f << text }
    end
  end
end