ways-and-means 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,8 +8,9 @@ module Sinatra
8
8
 
9
9
  # reserved configuration keys
10
10
  # i allow people to be less funky than i am
11
- # with key names, hence 'routes'
11
+ # with key names, hence 'routes' and 'config'
12
12
  WAYS_KEYS = %w|ways routes|.freeze
13
+ MEANS_KEYS = %w|means config|.freeze
13
14
 
14
15
  # HTTP verbs list
15
16
  VERBS = %w|get post patch put delete head options|.freeze
@@ -32,7 +33,14 @@ module Sinatra
32
33
  yield endpoint, dispatch if block_given?
33
34
 
34
35
  send dispatch[:verb], "/#{endpoint}" do
35
- send dispatch[:to]
36
+ # before hooks before
37
+ ['before_anyway', "before_#{dispatch[:to]}"].each { |hook| respond_to?(hook) && send(hook) }
38
+ send(dispatch[:to]).tap do
39
+ # after hooks in a tap, because i like tap
40
+ # Mmmh ? And yes, also because i need to maintain the return of the
41
+ # route call back as the return value of the route
42
+ ['after_anyway', "after_#{dispatch[:to]}"].each { |hook| respond_to?(hook) && send(hook) }
43
+ end
36
44
  end
37
45
  end
38
46
 
@@ -79,6 +87,13 @@ module Sinatra
79
87
  end
80
88
  end
81
89
 
90
+ def means
91
+ # set key / values in App.settings
92
+ means_config.each do |mean, it|
93
+ set mean, it
94
+ end
95
+ end
96
+
82
97
  def ways_config
83
98
  # hash.slice, i miss you...
84
99
  # at least this is safe and very explicit
@@ -91,18 +106,10 @@ module Sinatra
91
106
  # WAYS_KEYS.map { |k| [k, k.to_sym] }.flatten.map { |k| config[k] }.compact.first
92
107
  end
93
108
 
94
- def means
95
- # set key / values in App.settings
96
- means_config do |mean, it|
97
- set mean, it
98
- end
99
- end
100
-
101
109
  def means_config
102
- # key / values except reserved space for routes
103
- config.reject { |k, v| WAYS_KEYS.include? k.to_s }.each do |k, v|
104
- yield k.to_sym, v
105
- end
110
+ # hash.slice, i miss you...
111
+ # at least this is safe and very explicit
112
+ config['means'] || config[:means] || config['config'] || config[:config] || {}
106
113
  end
107
114
 
108
115
  # Well... What can i say now ...? Oh, i know : too many parentheses !
@@ -112,6 +119,4 @@ module Sinatra
112
119
 
113
120
  end
114
121
 
115
- register WaysAndMeans
116
-
117
122
  end
@@ -1,3 +1,3 @@
1
1
  module WaysAndMeans
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ways-and-means
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-18 00:00:00.000000000 Z
12
+ date: 2013-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra