Class: Luna::Command::Serve
- Inherits:
-
Samovar::Command
- Object
- Samovar::Command
- Luna::Command::Serve
- Defined in:
- lib/luna/command/serve.rb
Instance Method Summary collapse
- #call ⇒ Object
- #endpoint ⇒ Object
- #endpoint_options ⇒ Object
- #middleware ⇒ Object
- #root_directory ⇒ Object
Instance Method Details
#call ⇒ Object
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.(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 |
#endpoint ⇒ Object
48 49 50 |
# File 'lib/luna/command/serve.rb', line 48 def endpoint Async::HTTP::Endpoint.parse(@options[:bind], **) end |
#endpoint_options ⇒ Object
44 45 46 |
# File 'lib/luna/command/serve.rb', line 44 def @options.slice(:hostname, :port, :timeout) end |
#middleware ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/luna/command/serve.rb', line 52 def middleware Luna::Server.middleware( root: File.(root_directory), verbose: @options[:verbose], markdown: @options[:markdown], index: @options[:index], directory_listing: @options[:directory_listing] ) end |
#root_directory ⇒ Object
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 |