Class: Falcon::Command::Serve

Inherits:
Samovar::Command
  • Object
show all
Defined in:
lib/falcon/command/serve.rb

Instance Method Summary collapse

Instance Method Details

#callObject



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/falcon/command/serve.rb', line 122

def call
	Async.logger.info(self.endpoint) do |buffer|
		buffer.puts "Falcon v#{VERSION} taking flight! Using #{self.container_class} #{self.container_options}."
		buffer.puts "- To terminate: Ctrl-C or kill #{Process.pid}"
		buffer.puts "- To reload configuration: kill -HUP #{Process.pid}"
	end
	
	if @options[:preload]
		Bundler.require(:preload)
	end
	
	self.controller.run
end

#clientObject



114
115
116
# File 'lib/falcon/command/serve.rb', line 114

def client
	Async::HTTP::Client.new(client_endpoint)
end

#client_endpointObject



110
111
112
# File 'lib/falcon/command/serve.rb', line 110

def client_endpoint
	Async::HTTP::Endpoint.parse(@options[:bind], **endpoint_options)
end

#container_classObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/falcon/command/serve.rb', line 64

def container_class
	case @options[:container]
	when :threaded
		return Async::Container::Threaded
	when :forked
		return Async::Container::Forked
	when :hybrid
		return Async::Container::Hybrid
	end
end

#container_optionsObject



98
99
100
# File 'lib/falcon/command/serve.rb', line 98

def container_options
	slice_options(:count, :forks, :threads)
end

#controllerObject



118
119
120
# File 'lib/falcon/command/serve.rb', line 118

def controller
	Controller::Serve.new(self)
end

#endpointObject



106
107
108
# File 'lib/falcon/command/serve.rb', line 106

def endpoint
	Endpoint.parse(@options[:bind], **endpoint_options)
end

#endpoint_optionsObject



102
103
104
# File 'lib/falcon/command/serve.rb', line 102

def endpoint_options
	slice_options(:hostname, :port, :reuse_port, :timeout)
end

#load_app(verbose = self.verbose?) ⇒ Object



79
80
81
82
83
# File 'lib/falcon/command/serve.rb', line 79

def load_app(verbose = self.verbose?)
	rack_app, options = Rack::Builder.parse_file(@options[:config])
	
	return Server.middleware(rack_app, verbose: verbose), options
end

#slice_options(*keys) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/falcon/command/serve.rb', line 85

def slice_options(*keys)
	# TODO: Ruby 2.5 introduced Hash#slice
	options = {}
	
	keys.each do |key|
		if @options.key?(key)
			options[key] = @options[key]
		end
	end
	
	return options
end

#verbose?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/falcon/command/serve.rb', line 75

def verbose?
	@parent&.verbose?
end