Class: MonkeysPaw::Server
- Inherits:
-
Object
- Object
- MonkeysPaw::Server
- Defined in:
- lib/monkeyspaw/server.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Instance Method Summary collapse
- #generate_error_page(message) ⇒ Object
- #generate_page(path, prompt_file) ⇒ Object
-
#initialize(app, **options) ⇒ Server
constructor
A new instance of Server.
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(app, **options) ⇒ Server
Returns a new instance of Server.
8 9 10 11 12 |
# File 'lib/monkeyspaw/server.rb', line 8 def initialize(app, **) @app = app @options = @rack_app = build_rack_app end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
6 7 8 |
# File 'lib/monkeyspaw/server.rb', line 6 def app @app end |
Instance Method Details
#generate_error_page(message) ⇒ Object
57 58 59 |
# File 'lib/monkeyspaw/server.rb', line 57 def generate_error_page() "<html><body><h1>Error</h1><p>#{}</p></body></html>" end |
#generate_page(path, prompt_file) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/monkeyspaw/server.rb', line 30 def generate_page(path, prompt_file) if app.config.caching_enabled # Try to get from cache first cached_content = app.cache_manager.get_cached_page(path, prompt_file) return cached_content if cached_content end # Cache miss or caching disabled, generate the page # Reload layout and style prompts to pick up changes app.prompt_manager.load_default_components layout_prompt = app.prompt_manager.layout_prompt style_prompt = app.prompt_manager.style_prompt html_content = HtmlFromDescriptionGenerator.new( description: File.read(prompt_file), layout_prompt: layout_prompt, style_prompt: style_prompt ).generate # Store in cache if enabled if app.config.caching_enabled app.cache_manager.cache_page(path, prompt_file, html_content) end html_content end |
#shutdown ⇒ Object
25 26 27 28 |
# File 'lib/monkeyspaw/server.rb', line 25 def shutdown puts "Enough! You throw the paw away. Hopefully there were no unintended consequences. Mua ha ha ha ha!" exit end |
#start ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/monkeyspaw/server.rb', line 14 def start host = @options[:host] || app.config.host || 'localhost' port = @options[:port] || app.config.port || 1337 puts "You pick up the monkey's paw. Be careful what you wish for on http://#{host}:#{port}" setup_signal_handlers Rack::Handler::Puma.run(@rack_app, Host: host, Port: port, Silent: true, Threads: "0:16", workers: 0) end |