Class: Derailleur::Dispatcher
- Inherits:
-
Struct
- Object
- Struct
- Derailleur::Dispatcher
- Defined in:
- lib/derailleur/core/dispatcher.rb
Instance Method Summary collapse
-
#get_handler(method) ⇒ Object
returns the handler for an HTTP method, or, the default one.
-
#handlers ⇒ Object
Returns an array of pairs of array with [HTTP-verbs, handler] an extra item is the :default handler NB: could also be a hash, but I’m fine with it.
-
#handlers_set ⇒ Object
returns an array like handlers but restricted to the not nil values.
-
#has_handler?(method) ⇒ Boolean
returns true if a handler is set for the HTTP method in param it is an alternative to get_handler which would return a true value if there is a default handler.
-
#no_handler? ⇒ Boolean
Returns true if there is no handler set for this dispatcher.
-
#set_handler(method, val) ⇒ Object
sets a handler for the HTTP method in param to val.
Instance Method Details
#get_handler(method) ⇒ Object
returns the handler for an HTTP method, or, the default one
6 7 8 |
# File 'lib/derailleur/core/dispatcher.rb', line 6 def get_handler(method) send(method) || send(:default) end |
#handlers ⇒ Object
Returns an array of pairs of array with [HTTP-verbs, handler] an extra item is the :default handler NB: could also be a hash, but I’m fine with it
25 26 27 28 29 |
# File 'lib/derailleur/core/dispatcher.rb', line 25 def handlers HTTP_METHODS.map do |sym| [sym, send(sym)] end end |
#handlers_set ⇒ Object
returns an array like handlers but restricted to the not nil values
32 33 34 |
# File 'lib/derailleur/core/dispatcher.rb', line 32 def handlers_set handlers.reject{|sym, handler| handler.nil?} end |
#has_handler?(method) ⇒ Boolean
returns true if a handler is set for the HTTP method in param it is an alternative to get_handler which would return a true value if there is a default handler
13 14 15 |
# File 'lib/derailleur/core/dispatcher.rb', line 13 def has_handler?(method) send(method) && true end |
#no_handler? ⇒ Boolean
Returns true if there is no handler set for this dispatcher
37 38 39 |
# File 'lib/derailleur/core/dispatcher.rb', line 37 def no_handler? handlers_set.empty? end |
#set_handler(method, val) ⇒ Object
sets a handler for the HTTP method in param to val
18 19 20 |
# File 'lib/derailleur/core/dispatcher.rb', line 18 def set_handler(method, val) send("#{method}=", val) end |