Class: Luna::Command::Serve

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

Instance Method Summary collapse

Instance Method Details

#callObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/luna/command/serve.rb', line 62

def call
	Console.logger.info(self) do |buffer|
		buffer.puts "Luna v#{Luna::VERSION} serving..."
		buffer.puts "- Root: #{File.expand_path(root_directory)}"
		buffer.puts "- Bind: #{endpoint}"
		buffer.puts "- Markdown: #{@options[:markdown]} | Index: #{@options[:index]} | Directory Listing: #{@options[:directory_listing]}"
	end
	
	Async do |task|
		server = Luna::Server.new(middleware, endpoint, protocol: endpoint.protocol)
		
		server.run
		
		task.children.each(&:wait)
	end
end

#endpointObject



48
49
50
# File 'lib/luna/command/serve.rb', line 48

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

#endpoint_optionsObject



44
45
46
# File 'lib/luna/command/serve.rb', line 44

def endpoint_options
	@options.slice(:hostname, :port, :timeout)
end

#middlewareObject



52
53
54
55
56
57
58
59
60
# File 'lib/luna/command/serve.rb', line 52

def middleware
	Luna::Server.middleware(
		root: File.expand_path(root_directory),
		verbose: @options[:verbose],
		markdown: @options[:markdown],
		index: @options[:index],
		directory_listing: @options[:directory_listing]
	)
end

#root_directoryObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/luna/command/serve.rb', line 33

def root_directory
	# Use positional argument if provided, otherwise --root option, otherwise current directory
	if @path
		@path
	elsif @options[:root]
		@options[:root]
	else
		Dir.pwd
	end
end