class Redirectly::Command
Attributes
config_path[R]
port[R]
Public Instance Methods
run()
click to toggle source
# File lib/redirectly/command.rb, line 24 def run @port = args['--port'].to_i @config_path = args['CONFIG'] || "redirects.ini" args['--init'] ? init_file : start_server end
Private Instance Methods
app()
click to toggle source
# File lib/redirectly/command.rb, line 56 def app @app ||= Redirectly::App.new config_path end
init_file()
click to toggle source
# File lib/redirectly/command.rb, line 32 def init_file if File.exist? config_path raise ArgumentError, "#{config_path} already exists" else File.write config_path, template say "Initialized #{config_path}" end end
start_server()
click to toggle source
# File lib/redirectly/command.rb, line 51 def start_server raise ArgumentError, "Cannot find config file #{config_path}" unless File.exist? config_path Rack::Server.start(app: app, Port: port, environment: 'production') end
template()
click to toggle source
# File lib/redirectly/command.rb, line 41 def template <<~TEMPLATE example.com = https://other-site.com/ *.mygoogle.com/:anything = https://google.com/?q=%{anything} example.org/* = https://other-site.com/ *.old-site.com = !https://permanent.redirect.com :sub.lvh.me/* = http://it-works.com/%{sub} TEMPLATE end