Module: Sinatra::WaysAndMeans
- Defined in:
- lib/ways-and-means/sinatra/ways-and-means.rb
Constant Summary collapse
- WAYS_KEYS =
reserved configuration keys i allow people to be less funky than i am with key names, hence ‘routes’ and ‘config’
%w|ways routes|.freeze
- MEANS_KEYS =
%w|means config|.freeze
- VERBS =
HTTP verbs list
%w|get post patch put delete head options|.freeze
Instance Method Summary collapse
Instance Method Details
#ways_and_means!(ways_and_means = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ways-and-means/sinatra/ways-and-means.rb', line 18 def ways_and_means!(ways_and_means=nil) # Pfff'... Should probably be more tyrannical here... # if you registered, you should know what you're doing, right ? return unless @config = ways_and_means || config # the verb # the endpoint to string prefixed by '/' # the callback # # get '/plop' do # callback # end ways do |endpoint, dispatch| # if ever you wanna do something # with dispatch info' set right yield endpoint, dispatch if block_given? send dispatch[:verb], "/#{endpoint}" do # before hooks before ['before_anyway', "before_#{dispatch[:to]}"].each { |hook| respond_to?(hook, true) && send(hook) } send(dispatch[:to]).tap do # after hooks in a tap, because i like tap # Mmmh ? And yes, also because i need to maintain the return of the # route call back as the return value of the route ['after_anyway', "after_#{dispatch[:to]}"].each { |hook| respond_to?(hook, true) && send(hook) } end end end # settings means end |