Class: HtmlMockup::Server
- Inherits:
-
Object
- Object
- HtmlMockup::Server
- Defined in:
- lib/html_mockup/server.rb
Instance Attribute Summary collapse
-
#handler ⇒ Object
Returns the value of attribute handler.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#port ⇒ Object
Returns the value of attribute port.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#server_options ⇒ Object
readonly
Returns the value of attribute server_options.
Instance Method Summary collapse
-
#initialize(project, options = {}) ⇒ Server
constructor
A new instance of Server.
-
#map(*args, &block) ⇒ Object
Use the map handler to map endpoints to certain urls.
- #run! ⇒ Object (also: #run)
-
#set_options(options) ⇒ Object
Sets the options, this is a separate method as we want to override certain things set in the mockupfile from the commandline.
-
#use(*args, &block) ⇒ Object
Use the specified Rack middleware.
Constructor Details
#initialize(project, options = {}) ⇒ Server
Returns a new instance of Server.
19 20 21 22 23 24 25 26 27 |
# File 'lib/html_mockup/server.rb', line 19 def initialize(project, ={}) @stack = initialize_rack_builder @project = project @server_options = {} () end |
Instance Attribute Details
#handler ⇒ Object
Returns the value of attribute handler.
17 18 19 |
# File 'lib/html_mockup/server.rb', line 17 def handler @handler end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/html_mockup/server.rb', line 13 def @options end |
#port ⇒ Object
Returns the value of attribute port.
17 18 19 |
# File 'lib/html_mockup/server.rb', line 17 def port @port end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
15 16 17 |
# File 'lib/html_mockup/server.rb', line 15 def project @project end |
#server_options ⇒ Object (readonly)
Returns the value of attribute server_options.
13 14 15 |
# File 'lib/html_mockup/server.rb', line 13 def @server_options end |
Instance Method Details
#map(*args, &block) ⇒ Object
Use the map handler to map endpoints to certain urls
51 52 53 |
# File 'lib/html_mockup/server.rb', line 51 def map(*args, &block) @stack.map *args, &block end |
#run! ⇒ Object Also known as: run
55 56 57 58 59 60 61 62 63 |
# File 'lib/html_mockup/server.rb', line 55 def run! self.get_handler(self.handler).run self.application, self. do |server| trap(:INT) do ## Use thins' hard #stop! if available, otherwise just #stop server.respond_to?(:stop!) ? server.stop! : server.stop puts "Bby HtmlMockup" end end end |
#set_options(options) ⇒ Object
Sets the options, this is a separate method as we want to override certain things set in the mockupfile from the commandline
31 32 33 34 35 36 37 38 39 |
# File 'lib/html_mockup/server.rb', line 31 def () @options = { :handler => nil, # Autodetect :port => 9000 }.update() self.port = @options[:port] self.handler = @options[:handler] end |
#use(*args, &block) ⇒ Object
Use the specified Rack middleware
44 45 46 |
# File 'lib/html_mockup/server.rb', line 44 def use(*args, &block) @stack.use *args, &block end |