module DataSeeder

Constants

VERSION

Attributes

config[W]

Public Class Methods

config() click to toggle source
# File lib/data_seeder.rb, line 12
def self.config
  @config ||= Config.new
end
configure() { |config| ... } click to toggle source
# File lib/data_seeder.rb, line 21
def self.configure
  yield(config)
end
quiet_run(new_config={}) click to toggle source
# File lib/data_seeder.rb, line 72
def self.quiet_run(new_config={})
  run({logger: Rails.logger}.merge(new_config))
end
reset() click to toggle source
# File lib/data_seeder.rb, line 16
def self.reset
  @config = Config.new
  SeedFile.reset
end
run(new_config={}) click to toggle source
# File lib/data_seeder.rb, line 25
def self.run(new_config={})
  @@mutex.synchronize do
    msec = Benchmark.ms do
      new_config.each do |key, value|
        self.config.send("#{key}=", value)
      end
      # Keep track of the seed files that have dependencies that aren't fulfilled
      pending = []
      config.seed_dirs.each do |seed_dir|
        Dir.chdir(seed_dir) do
          Dir['**/*'].each do |path|
            next if path.end_with?('.cfg')
            if File.file?(path)
              unless SeedFile.load(path)
                pending << [seed_dir, path]
              end
            end
          end
        end
      end
      # Loop thru the ones that couldn't be processed previously because they depended on another seed being loaded first
      until pending.empty?
        new_pending = []
        pending.each do |seed_dir, path|
          Dir.chdir(seed_dir) do
            unless SeedFile.load(path)
              new_pending << [seed_dir, path]
            end
          end
        end
        if pending.size == new_pending.size
          msg = "Error: Circular dependency in DataSeeder, seeds=#{pending.inspect}"
          config.logger.error msg
          raise msg
        end
        pending = new_pending
      end
    end
    config.logger.info "DataSeeder.run took #{msec.to_i} msec"
  end
end
test_run(new_config={}) click to toggle source

Deprecated

# File lib/data_seeder.rb, line 68
def self.test_run(new_config={})
  quiet_run(new_config)
end
to_id(len, str) click to toggle source
# File lib/data_seeder.rb, line 80
def self.to_id(len, str)
  id = 0
  str = str.upcase.gsub(/[^A-Z0-9]/, '')
  len.times do |i|
    char = str[i]
    if char
      ord = char.ord
      if @@numeric_range.include?(ord)
        id = id * 37 + ord - @@zero_ord
      else
        id = id * 37 + ord - @@a_ord + 10
      end
    else
      id = id * 37 + 36
    end
  end
  return id
end