Class: Brut::FrontEnd::HttpMethod
- Inherits:
-
Object
- Object
- Brut::FrontEnd::HttpMethod
- Includes:
- Phlex::SGML::SafeObject
- Defined in:
- lib/brut/front_end/http_method.rb
Overview
Wrapper around an HTTP Method, ensuring it contains only a valid value.
Instance Method Summary collapse
-
#==(other) ⇒ true|false
True if the other object is the same class as this and has the same string representation.
-
#get? ⇒ true|false
True if this is a GET.
-
#initialize(string) ⇒ HttpMethod
constructor
Create an HTTP method from a string.
-
#post? ⇒ true|false
True if this is a POST.
-
#to_s ⇒ String
(also: #to_str)
The method name, normalized to all lower case, as a string.
-
#to_sym ⇒ Symbol
The method name, normalized to all lower case, as a symbol.
Constructor Details
#initialize(string) ⇒ HttpMethod
Create an HTTP method from a string.
12 13 14 15 16 17 18 |
# File 'lib/brut/front_end/http_method.rb', line 12 def initialize(string) normalized = string.to_s.downcase.to_sym if !self.class.method_names.include?(normalized) raise ArgumentError,"'#{string}' is not a known HTTP method" end @method = normalized end |
Instance Method Details
#==(other) ⇒ true|false
Returns True if the other object is the same class as this and has the same string representation.
27 28 29 |
# File 'lib/brut/front_end/http_method.rb', line 27 def ==(other) self.class.name == other.class.name && self.to_s == other.to_s end |
#get? ⇒ true|false
Returns true if this is a GET.
32 33 |
# File 'lib/brut/front_end/http_method.rb', line 32 def get? = self.to_sym == :get # @return [true|false] true if this is a POST |
#post? ⇒ true|false
Returns true if this is a POST.
34 |
# File 'lib/brut/front_end/http_method.rb', line 34 def post? = self.to_sym == :post |
#to_s ⇒ String Also known as: to_str
Returns the method name, normalized to all lower case, as a string.
21 22 |
# File 'lib/brut/front_end/http_method.rb', line 21 def to_s = @method.to_s # @return [Symbol] the method name, normalized to all lower case, as a symbol |
#to_sym ⇒ Symbol
Returns the method name, normalized to all lower case, as a symbol.
23 |
# File 'lib/brut/front_end/http_method.rb', line 23 def to_sym = @method.to_sym |