Class: HiveRuby::ServerConfig
- Inherits:
-
Object
- Object
- HiveRuby::ServerConfig
- Defined in:
- lib/hive_ruby/server_config.rb
Overview
Web Server Configuration
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #delete(path, &handler) ⇒ Object
- #get(path, &handler) ⇒ Object
- #head(path, &handler) ⇒ Object
-
#initialize ⇒ ServerConfig
constructor
A new instance of ServerConfig.
- #patch(path, &handler) ⇒ Object
- #post(path, &handler) ⇒ Object
- #put(path, &handler) ⇒ Object
Constructor Details
#initialize ⇒ ServerConfig
Returns a new instance of ServerConfig.
8 9 10 |
# File 'lib/hive_ruby/server_config.rb', line 8 def initialize @routes = {} end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
55 56 57 |
# File 'lib/hive_ruby/server_config.rb', line 55 def request @request end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
6 7 8 |
# File 'lib/hive_ruby/server_config.rb', line 6 def routes @routes end |
Instance Method Details
#call(env) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/hive_ruby/server_config.rb', line 36 def call(env) @request = Rack::Request.new(env) verb = @request.request_method requested_path = @request.path_info handler = @routes.fetch(verb, {}).fetch(requested_path, nil) if handler result = instance_eval(&handler) if result.class == String [200, {}, [result]] else result end else [404, {}, ["Oops! No route for #{verb} #{requested_path}"]] end end |
#delete(path, &handler) ⇒ Object
28 29 30 |
# File 'lib/hive_ruby/server_config.rb', line 28 def delete(path, &handler) route('DELETE', path, &handler) end |
#get(path, &handler) ⇒ Object
12 13 14 |
# File 'lib/hive_ruby/server_config.rb', line 12 def get(path, &handler) route('GET', path, &handler) end |
#head(path, &handler) ⇒ Object
32 33 34 |
# File 'lib/hive_ruby/server_config.rb', line 32 def head(path, &handler) route('HEAD', path, &handler) end |
#patch(path, &handler) ⇒ Object
24 25 26 |
# File 'lib/hive_ruby/server_config.rb', line 24 def patch(path, &handler) route('PATCH', path, &handler) end |
#post(path, &handler) ⇒ Object
16 17 18 |
# File 'lib/hive_ruby/server_config.rb', line 16 def post(path, &handler) route('POST', path, &handler) end |
#put(path, &handler) ⇒ Object
20 21 22 |
# File 'lib/hive_ruby/server_config.rb', line 20 def put(path, &handler) route('PUT', path, &handler) end |