class Djoini::Files

Handles loading of ini and json fixtures

Attributes

path[RW]

Public Class Methods

new(fixtures_path = nil) click to toggle source
# File lib/djoini/files.rb, line 9
def initialize(fixtures_path = nil)
  self.path = fixtures_path || Djoini.configuration.fixtures_folder
end

Public Instance Methods

load_files(type = 'mixed') click to toggle source
# File lib/djoini/files.rb, line 13
def load_files(type = 'mixed')
  IniLoader.new(path).load_files(find_files('ini')) unless type == 'json'
  JsonLoader.new(path).load_files find_files('json') unless type == 'ini'
end

Private Instance Methods

find_files(type) click to toggle source
# File lib/djoini/files.rb, line 20
def find_files(type)
  _files = []

  Dir.foreach(path) do |file|
    next unless File.extname(file) == ".#{type}"
    _model = file.gsub(".#{type}", '')
    _files << { model: _model, file: file }
  end

  _files
end