Class: HtmlMockup::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/html_mockup/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  @stack = initialize_rack_builder
        
  @project = project
  
  @server_options = {}
  
  set_options(options)
end

Instance Attribute Details

#handlerObject

Returns the value of attribute handler.



17
18
19
# File 'lib/html_mockup/server.rb', line 17

def handler
  @handler
end

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/html_mockup/server.rb', line 13

def options
  @options
end

#portObject

Returns the value of attribute port.



17
18
19
# File 'lib/html_mockup/server.rb', line 17

def port
  @port
end

#projectObject (readonly)

Returns the value of attribute project.



15
16
17
# File 'lib/html_mockup/server.rb', line 15

def project
  @project
end

#server_optionsObject (readonly)

Returns the value of attribute server_options.



13
14
15
# File 'lib/html_mockup/server.rb', line 13

def server_options
  @server_options
end

Instance Method Details

#map(*args, &block) ⇒ Object

Use the map handler to map endpoints to certain urls

See Also:

  • Rack::Builder#map


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.server_options 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 set_options(options)
  @options = {
    :handler => nil, # Autodetect
    :port => 9000
  }.update(options)
        
  self.port = @options[:port]
  self.handler = @options[:handler]      
end

#use(*args, &block) ⇒ Object

Use the specified Rack middleware

See Also:

  • Rack::Builder#use


44
45
46
# File 'lib/html_mockup/server.rb', line 44

def use(*args, &block)
  @stack.use *args, &block
end