rocketio 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a06971bd162cb331c81d8c86129fe0ff2ef4c907
4
- data.tar.gz: 29cc243861c4edaba45394bb79c696e4369bd776
3
+ metadata.gz: c0737fe18f7374b3e25a8a4b7d60c138165b5bee
4
+ data.tar.gz: 8bb85a4305fda13a4e3bcc9cc385c365789d60f6
5
5
  SHA512:
6
- metadata.gz: 045ea446cf4586b52d7d330dcb317e4682d5ed56778dc58a965d23b2fb986b758043a0d2c08722b2805aed53324e1673d3495ab47760bb27f939cb728b32bf7b
7
- data.tar.gz: fdba8b6a904564d30e68cd1a1bc9ec3bf871e567d53fdad4960c6550980e4ba4a4946d42abfe990ab9b0910eb32cb54256b951e736e337802cb3f118370f66b7
6
+ metadata.gz: be167fe2a49f6063064358e0e6ff723b988a33f4e2f7191d8449a2a282c0a594234f8181b5bda15bcf17970b5dca5b1d3b5a862335d2e4fd94da30e8206f23c5
7
+ data.tar.gz: 526b21a00e3ee46532c6b502cf81d22fa4d3925c0d1c5ac0d29c67b3f5a6968e9c363e246b3c6cfeed02f0eae7567568e67e1927fc926db3b07f923a0a247029
@@ -14,6 +14,8 @@ module RocketIO
14
14
  # that's it, if defining `before {}` and `before(:index) {}` filters
15
15
  # `index` method will run `before` filter then `before(:index)`
16
16
  #
17
+ # @note as of version 0.4.4 it is possible to exclude methods using :except option
18
+ #
17
19
  # @example run before any method
18
20
  # before do
19
21
  # # some logic here
@@ -50,30 +52,57 @@ module RocketIO
50
52
  # # both @user and @photo variables available here
51
53
  # end
52
54
  #
55
+ # @example except a single method
56
+ # before except: :x do
57
+ # ...
58
+ # end
59
+ #
60
+ # @example except multiple methods
61
+ # before except: [:x, :y] do
62
+ # ...
63
+ # end
64
+ #
53
65
  {
54
66
  before: proc {},
55
67
  around: proc {|app| app.call},
56
68
  after: proc {}
57
69
  }.each_pair do |filter,default_block|
70
+
58
71
  define_methods = :"define_#{filter}_methods"
59
72
  var = :"@__#{filter}_filters__"
60
73
 
61
- define_singleton_method filter do |*methods,&block|
74
+ define_singleton_method filter do |*methods, except: [], &block|
75
+
62
76
  instance_variable_get(var) || instance_variable_set(var, {})
63
77
  methods = [:*] if methods.empty?
78
+ except = [except.to_sym] unless except.is_a?(Array)
79
+
64
80
  methods.each do |meth|
65
- instance_variable_get(var)[meth.to_sym] = block || default_block
81
+ instance_variable_get(var)[meth.to_sym] = {
82
+ proc: block || default_block,
83
+ except: Hash[except.zip(except)].freeze
84
+ }
66
85
  end
86
+
67
87
  __send__(define_methods)
68
88
  end
69
89
 
70
90
  define_singleton_method define_methods do |source = self|
71
- filters = (source.instance_variable_get(var) || {}).each_with_object({}) do |(meth,block),o|
72
- o[meth] = :"__#{filter}_#{meth}__"
73
- api.delete define_method(o[meth], &block)
91
+ filters = (source.instance_variable_get(var) || {}).each_with_object({}) do |(meth,opts),o|
92
+
93
+ filter_meth = "__#{filter}_#{meth}__"
94
+ api.delete define_method(filter_meth, &opts[:proc])
95
+
96
+ o[meth] = filter_meth + '?'
97
+ api.delete define_method(o[meth]) {|*a|
98
+ __send__(filter_meth, *a) unless opts[:except][requested_method]
99
+ }
100
+
74
101
  end
102
+
75
103
  filters.update(allocate.__send__(filter))
76
104
  return unless filters.any?
105
+
77
106
  filters.freeze
78
107
  api.delete define_method(filter) {filters}
79
108
  end
@@ -88,7 +117,7 @@ module RocketIO
88
117
  __send__(before[method]) if before[method]
89
118
  end
90
119
 
91
- # passing blocks somehow tends to add some overhead
120
+ # passing blocks tends to add some overhead
92
121
  # so passing the proc as a common argument
93
122
  def invoke_around_filter method = requested_method, block
94
123
  if around[:*]
@@ -1,3 +1,3 @@
1
1
  module RocketIO
2
- VERSION = '0.4.3'.freeze
2
+ VERSION = '0.4.4'.freeze
3
3
  end
@@ -191,4 +191,32 @@ spec :Filters do
191
191
  get :a
192
192
  assert(buffer) == [:*, :a]
193
193
  end
194
+
195
+ it 'excepts a single method' do
196
+ calls = []
197
+ ctrl = mock_controller {
198
+ before(except: :x) {calls << requested_method}
199
+ def x; end
200
+ def y; end
201
+ }
202
+ app(ctrl)
203
+ get :x
204
+ get :y
205
+ assert(calls) == [:y]
206
+ end
207
+
208
+ it 'excepts multiple methods' do
209
+ calls = []
210
+ ctrl = mock_controller {
211
+ before(except: [:x, :y]) {calls << requested_method}
212
+ def x; end
213
+ def y; end
214
+ def z; end
215
+ }
216
+ app(ctrl)
217
+ get :x
218
+ get :y
219
+ get :z
220
+ assert(calls) == [:z]
221
+ end
194
222
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocketio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Slee Woo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-10 00:00:00.000000000 Z
11
+ date: 2016-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -203,5 +203,5 @@ rubyforge_project:
203
203
  rubygems_version: 2.5.1
204
204
  signing_key:
205
205
  specification_version: 4
206
- summary: '["rocketio-0.4.3", "Simple routing lib"]'
206
+ summary: '["rocketio-0.4.4", "Simple routing lib"]'
207
207
  test_files: []