module Jetel::Helper

Public Class Methods

erb(template, vars) click to toggle source
# File lib/jetel/helpers/general_helper.rb, line 51
def erb(template, vars)
  ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
end
erb_template(file, vars) click to toggle source
# File lib/jetel/helpers/general_helper.rb, line 55
def erb_template(file, vars)
  template = File.open(file, 'r').read
  ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
end
get_loader(uri) click to toggle source
# File lib/jetel/helpers/general_helper.rb, line 41
def get_loader(uri)
  loaders = Loaders.loaders
  loader_schema = uri.split(':/').first.downcase
  res = loaders.find do |loader|
    loader[:class_name].downcase === loader_schema
  end

  res[:klass].new(uri)
end
sanitize(str) click to toggle source
# File lib/jetel/helpers/general_helper.rb, line 60
def sanitize(str)
  I18n.transliterate(str).gsub(/[^0-9a-z_\-]/i, '_')
end
target_dir(modul, dir, source) click to toggle source
# File lib/jetel/helpers/general_helper.rb, line 35
def target_dir(modul, dir, source)
  klass = modul.class.name.split('::').last
  source_name = Helper.sanitize(source[:name])
  File.join(dir || Config[:DATA_DIRECTORY], klass, source_name)
end
which(cmd) click to toggle source

Cross-platform way of finding an executable in the $PATH.

which('ruby') #=> /usr/bin/ruby
# File lib/jetel/helpers/os_helper.rb, line 29
def which(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each { |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    }
  end
  return nil
end