class Vantiv::Certification::PaypageServer

Attributes

server[RW]
server_thread[RW]
threaded[RW]

Public Class Methods

new(threaded: true) click to toggle source
# File lib/vantiv/certification/paypage_server.rb, line 8
def initialize(threaded: true)
  @threaded = threaded
  @template = "#{Vantiv.root}/lib/vantiv/certification/views/index.html.erb"
  @static_file_dir = "#{Vantiv.root}/tmp/e-protect"
end

Public Instance Methods

root_path() click to toggle source
# File lib/vantiv/certification/paypage_server.rb, line 28
def root_path
  "http://localhost:#{port}"
end
start() click to toggle source
# File lib/vantiv/certification/paypage_server.rb, line 14
def start
  if threaded
    @server_thread = Thread.new do
      compile_template
      server = WEBrick::HTTPServer.new :Port => port, :DocumentRoot => document_root
      Thread.current.thread_variable_set(:server, server)
      trap('INT') { server.shutdown }
      server.start
    end
  else
    start_server
  end
end
stop() click to toggle source
# File lib/vantiv/certification/paypage_server.rb, line 32
def stop
  if threaded
    server_thread.thread_variable_get(:server).shutdown
    Thread.kill(server_thread)
  else
    stop_server
  end
end

Private Instance Methods

compile_template() click to toggle source
# File lib/vantiv/certification/paypage_server.rb, line 71
def compile_template
  template = File.open(@template)
  File.open("#{static_file_dir}/index.html", "w") do |f|
    renderer = ERB.new(template.read)
    f << renderer.result()
  end
end
document_root() click to toggle source
# File lib/vantiv/certification/paypage_server.rb, line 45
def document_root
  File.expand_path "#{static_file_dir}"
end
port() click to toggle source
# File lib/vantiv/certification/paypage_server.rb, line 49
def port
  8000
end
start_server() click to toggle source
# File lib/vantiv/certification/paypage_server.rb, line 53
def start_server
  compile_template
  server = WEBrick::HTTPServer.new :Port => port, :DocumentRoot => document_root
  trap('INT') { server.shutdown }
  server.start
end
static_file_dir() click to toggle source
# File lib/vantiv/certification/paypage_server.rb, line 64
def static_file_dir
  unless File.directory?(@static_file_dir)
    FileUtils.mkdir_p(@static_file_dir)
  end
  @static_file_dir
end
stop_server() click to toggle source
# File lib/vantiv/certification/paypage_server.rb, line 60
def stop_server
  server.shutdown
end