Module: Fixturized::FileHandler

Extended by:
FileHandler
Included in:
FileHandler
Defined in:
lib/file_handler.rb

Instance Method Summary collapse

Instance Method Details

#create_fixture_dirObject



8
9
10
11
12
# File 'lib/file_handler.rb', line 8

def create_fixture_dir
  if Dir[self.fixture_dir].empty?
    FileUtils.mkdir_p self.fixture_dir
  end
end

#fixture_dirObject

All filesystem operations are handled here



4
5
6
# File 'lib/file_handler.rb', line 4

def fixture_dir
  "#{RAILS_ROOT}/fixturized"
end

#fixture_exists?(filename) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/file_handler.rb', line 23

def fixture_exists?(filename)
  return FileTest.exists?(self.fixture_path(filename))
end

#fixture_path(filename) ⇒ Object



27
28
29
# File 'lib/file_handler.rb', line 27

def fixture_path(filename)
  return File.join(self.fixture_dir, filename)
end

#load_fixture(filename) ⇒ Object



19
20
21
# File 'lib/file_handler.rb', line 19

def load_fixture(filename)
  return YAML.load_file(self.fixture_path(filename))
end

#write_fixture(filename, objects) ⇒ Object



14
15
16
17
# File 'lib/file_handler.rb', line 14

def write_fixture(filename, objects)
  Fixturized.create_fixture_dir
  return File.open(self.fixture_path(filename), 'w') {|f| YAML.dump objects, f}      
end