Module: Syntropy::RequestExtensions
- Defined in:
- lib/syntropy/request_extensions.rb
Instance Method Summary collapse
- #ctx ⇒ Object
- #respond_by_http_method(map) ⇒ Object
- #respond_on_get(body, headers = {}) ⇒ Object
- #respond_on_post(body, headers = {}) ⇒ Object
- #validate_http_method(*accepted) ⇒ Object
- #validate_param(name, *clauses) ⇒ Object
Instance Method Details
#ctx ⇒ Object
7 8 9 |
# File 'lib/syntropy/request_extensions.rb', line 7 def ctx @ctx ||= {} end |
#respond_by_http_method(map) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/syntropy/request_extensions.rb', line 15 def respond_by_http_method(map) value = map[self.method] raise Syntropy::Error.method_not_allowed if !value value = value.() if value.is_a?(Proc) (body, headers) = value respond(body, headers) end |
#respond_on_get(body, headers = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/syntropy/request_extensions.rb', line 24 def respond_on_get(body, headers = {}) case self.method when 'head' respond(nil, headers) when 'get' respond(body, headers) else raise Syntropy::Error.method_not_allowed end end |
#respond_on_post(body, headers = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/syntropy/request_extensions.rb', line 35 def respond_on_post(body, headers = {}) case self.method when 'head' respond(nil, headers) when 'post' respond(body, headers) else raise Syntropy::Error.method_not_allowed end end |
#validate_http_method(*accepted) ⇒ Object
11 12 13 |
# File 'lib/syntropy/request_extensions.rb', line 11 def validate_http_method(*accepted) raise Syntropy::Error.method_not_allowed if !accepted.include?(method) end |
#validate_param(name, *clauses) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/syntropy/request_extensions.rb', line 46 def validate_param(name, *clauses) value = query[name] clauses.each do |c| valid = param_is_valid?(value, c) raise(Syntropy::ValidationError, 'Validation error') if !valid value = param_convert(value, c) end value end |