class Object

Public Instance Methods

app() click to toggle source
# File test/omnitoken_app_test.rb, line 5
def app
  OmniTokenApp
end
on_add(names) click to toggle source

Add provider templates.

# File bin/omnitoken, line 26
def on_add(names)
  return if names.nil?
  provider_dir = OmniTokenApp::PROVIDER_DIR
  # create the providers folder if it doesn't exist
  unless names.empty? || Dir.exists?(provider_dir)
    $stdout.puts "Creating #{provider_dir} folder"
    Dir.mkdir(provider_dir) 
  end

  template_dir = File.join(
                    File.expand_path(File.dirname(__FILE__)), 
                    *%w[.. templates])
  names.each do |n|
    file = "#{n.downcase}.yml"
    # check if the template file is available
    unless File.exists?(File.join(template_dir, file))
      $stderr.puts "Template for #{n} is not available. "\
        "Please follow the OmniToken README to create its config file."
      next
    end

    # check if the config file is already there
    if File.exists?(File.join(provider_dir, file))
       overwrite = loop do
         $stdout.print("File #{file} already exists. Overwrite it?(y/Y/n/N):")
         ans = $stdin.gets.chomp
         break true if 'y'.eql?(ans.downcase)
         break false if 'n'.eql?(ans.downcase)
       end 
       next unless overwrite
    end

    # copy the template file
    $stdout.puts "Copying template #{file}"
    FileUtils.cp(File.join(template_dir, file),
                 File.join(provider_dir, ''))
  end
end
on_server() click to toggle source

Starts the web server.

# File bin/omnitoken, line 66
def on_server()
    puts 'Starting OmniToken web server'
    OmniTokenApp.run!
end