flexirest 1.3.20 → 1.3.21

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: a08b537f83b7e91f676166915c6db2858aaf3858
4
- data.tar.gz: a1962938bb89f82b79640aa29e619ec3ba48d857
3
+ metadata.gz: 7b44e78f8e0339a35faa3fb279633ed5ef81f7ae
4
+ data.tar.gz: d83135c90a5d429189f808f13ead3e729ec4bd65
5
5
  SHA512:
6
- metadata.gz: d1af9fae82540fcff4c45dcedd9c5074743188531b1481a3d02ace07ab1cdcc537d8b505027a818f18dcff3f1a0a90ec7ee57fc1f0d0502d4a52de206dc71ba0
7
- data.tar.gz: b3eaa600d7ecd24034168a57ec10376ed1b5a4f29570f6762f3ff7eea2ecbf82f48ba036d5a401edd4d986bcda2c6c34e681a4d7bca7fbf25052e438d93bbf25
6
+ metadata.gz: c3b04f2aaa9fe1f67601ab242374d6c2f142a859bac9185bfa46857947467edd1379a63be9896dfccf7353479f4015eb17a3b92f080e9eedd44b74ed7378a6bb
7
+ data.tar.gz: f2dc4c231338f6bfa6c8b5323c09f4226c5fd4cf79564cce936186c8f3b07de6f89ab2041b27b03561ffb4074ac87dddf3e95114930e75b314ec1a0190ac81db
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.21
4
+
5
+ Feature:
6
+
7
+ - Now any requests returning a 204 with an empty (nil or blank) body return true instead of raising a ParseException
8
+
3
9
  ## 1.3.20
4
10
 
5
11
  Bugfix:
data/README.md CHANGED
@@ -396,11 +396,11 @@ If Rails is defined, it will default to using Rails.cache as the cache store, if
396
396
  Flexirest::Base.cache_store = Redis::Store.new("redis://localhost:6379/0/cache")
397
397
  ```
398
398
 
399
- ### Using filters
399
+ ### Using callbacks
400
400
 
401
- You can use filters to alter get/post parameters, the URL or set the post body (doing so overrides normal parameter insertion in to the body) before a request or to adjust the response after a request. This can either be a block or a named method (like ActionController's `before_filter`/`before_action` methods).
401
+ You can use callbacks to alter get/post parameters, the URL or set the post body (doing so overrides normal parameter insertion in to the body) before a request or to adjust the response after a request. This can either be a block or a named method (like ActionController's `before_callback`/`before_action` methods).
402
402
 
403
- The filter is passed the name of the method (e.g. `:save`) and an object (a request object for `before_request` and a response object for `after_request`). The request object has four public attributes `post_params` (a Hash of the POST parameters), `get_params` (a Hash of the GET parameters), headers and `url` (a String containing the full URL without GET parameters appended)
403
+ The callback is passed the name of the method (e.g. `:save`) and an object (a request object for `before_request` and a response object for `after_request`). The request object has four public attributes `post_params` (a Hash of the POST parameters), `get_params` (a Hash of the GET parameters), headers and `url` (a String containing the full URL without GET parameters appended)
404
404
 
405
405
  ```ruby
406
406
  require 'secure_random'
@@ -445,7 +445,7 @@ class Person < Flexirest::Base
445
445
  end
446
446
  ```
447
447
 
448
- If you need to, you can create a custom parent class with a `before_request` filter and all children will inherit this filter.
448
+ If you need to, you can create a custom parent class with a `before_request` callback and all children will inherit this callback.
449
449
 
450
450
  ```ruby
451
451
  class MyProject::Base < Flexirest::Base
@@ -459,7 +459,7 @@ class Person < MyProject::Base
459
459
  end
460
460
  ```
461
461
 
462
- After filters work in exactly the same way:
462
+ After callbacks work in exactly the same way:
463
463
 
464
464
  ```ruby
465
465
  class Person < Flexirest::Base
@@ -475,6 +475,8 @@ class Person < Flexirest::Base
475
475
  end
476
476
  ```
477
477
 
478
+ **Note:** since v1.3.21 this isn't necessary, empty responses for 204 are accepted normally (the method returns `true`), but this is hear to show an example of an `after_request` callback.
479
+
478
480
  ### Lazy Loading
479
481
 
480
482
  Flexirest supports lazy loading (delaying the actual API call until the response is actually used, so that views can be cached without still causing API calls).
@@ -565,7 +567,7 @@ or
565
567
  Flexirest::Base.request_body_type = :json
566
568
  ```
567
569
 
568
- This will also set the header `Content-Type` to `application/x-www-form-urlencoded` by default or `application/json; charset=utf-8` when `:json`. You can override this using the filter `before_request`.
570
+ This will also set the header `Content-Type` to `application/x-www-form-urlencoded` by default or `application/json; charset=utf-8` when `:json`. You can override this using the callback `before_request`.
569
571
 
570
572
  If you have an API that is inconsistent in its body type requirements, you can also specify it on the individual method mapping:
571
573
 
@@ -673,7 +675,7 @@ end
673
675
 
674
676
  ### Raw Requests
675
677
 
676
- Sometimes you have have a URL that you just want to force through, but have the response handled in the same way as normal objects or you want to have the filters run (say for authentication). The easiest way to do that is to call `_request` on the class:
678
+ Sometimes you have have a URL that you just want to force through, but have the response handled in the same way as normal objects or you want to have the callbacks run (say for authentication). The easiest way to do that is to call `_request` on the class:
677
679
 
678
680
  ```ruby
679
681
  class Person < Flexirest::Base
@@ -2,7 +2,7 @@ module Flexirest
2
2
  class Base
3
3
  include Mapping
4
4
  include Configuration
5
- include RequestFiltering
5
+ include Callbacks
6
6
  include Validation
7
7
  include Caching
8
8
  include Recording
@@ -0,0 +1,63 @@
1
+ module Flexirest
2
+ module Callbacks
3
+ module ClassMethods
4
+ def before_request(method_name = nil, &block)
5
+ @before_callbacks ||= []
6
+ if block
7
+ @before_callbacks << block
8
+ elsif method_name
9
+ @before_callbacks << method_name
10
+ end
11
+ end
12
+
13
+ def after_request(method_name = nil, &block)
14
+ @after_callbacks ||= []
15
+ if block
16
+ @after_callbacks << block
17
+ elsif method_name
18
+ @after_callbacks << method_name
19
+ end
20
+ end
21
+
22
+ def _callback_request(type, name, param)
23
+ _handle_super_class_callbacks(type, name, param)
24
+ @before_callbacks ||= []
25
+ @after_callbacks ||= []
26
+ callbacks = (type == :before ? @before_callbacks : @after_callbacks)
27
+ callbacks.each do |callback|
28
+ if callback.is_a? Symbol
29
+ if self.respond_to?(callback)
30
+ self.send(callback, name, param)
31
+ else
32
+ instance = self.new
33
+ instance.send(callback, name, param)
34
+ end
35
+ else
36
+ callback.call(name, param)
37
+ end
38
+ end
39
+ end
40
+
41
+ def _handle_super_class_callbacks(type, name, request)
42
+ @parents ||= []
43
+ @parents.each do |parent|
44
+ parent._callback_request(type, name, request)
45
+ end
46
+ end
47
+
48
+ def _parents
49
+ @parents ||= []
50
+ end
51
+
52
+ def inherited(subclass)
53
+ subclass._parents << self
54
+ super
55
+ end
56
+ end
57
+
58
+ def self.included(base)
59
+ base.extend(ClassMethods)
60
+ end
61
+
62
+ end
63
+ end
@@ -161,9 +161,9 @@ module Flexirest
161
161
  return handle_response(OpenStruct.new(status:200, body:fake, response_headers:{"X-ARC-Faked-Response" => "true", "Content-Type" => content_type}))
162
162
  end
163
163
  if object_is_class?
164
- @object.send(:_filter_request, :before, @method[:name], self)
164
+ @object.send(:_callback_request, :before, @method[:name], self)
165
165
  else
166
- @object.class.send(:_filter_request, :before, @method[:name], self)
166
+ @object.class.send(:_callback_request, :before, @method[:name], self)
167
167
  end
168
168
  append_get_parameters
169
169
  prepare_request_body
@@ -205,9 +205,9 @@ module Flexirest
205
205
  @object.record_response(self.url, response_env)
206
206
  end
207
207
  if object_is_class?
208
- @object.send(:_filter_request, :after, @method[:name], response_env)
208
+ @object.send(:_callback_request, :after, @method[:name], response_env)
209
209
  else
210
- @object.class.send(:_filter_request, :after, @method[:name], response_env)
210
+ @object.class.send(:_callback_request, :after, @method[:name], response_env)
211
211
  end
212
212
 
213
213
  result = handle_response(response_env, cached)
@@ -402,6 +402,8 @@ module Flexirest
402
402
  if (200..399).include?(status)
403
403
  if @method[:options][:plain]
404
404
  return @response = Flexirest::PlainResponse.from_response(response)
405
+ elsif status == 204 && @response.body.blank?
406
+ return true
405
407
  elsif is_json_response? || is_xml_response?
406
408
  if @response.respond_to?(:proxied) && @response.proxied
407
409
  Flexirest::Logger.debug " \033[1;4;32m#{Flexirest.name}\033[0m #{@instrumentation_name} - Response was proxied, unable to determine size"
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.3.20"
2
+ VERSION = "1.3.21"
3
3
  end
data/lib/flexirest.rb CHANGED
@@ -16,7 +16,7 @@ require "flexirest/lazy_association_loader"
16
16
  require "flexirest/request"
17
17
  require "flexirest/request_delegator"
18
18
  require "flexirest/validation"
19
- require "flexirest/request_filtering"
19
+ require "flexirest/callbacks"
20
20
  require "flexirest/proxy_base"
21
21
  require "flexirest/recording"
22
22
  require "flexirest/base"
@@ -272,9 +272,9 @@ describe Flexirest::Base do
272
272
  EmptyExample._request("http://api.example.com/")
273
273
  end
274
274
 
275
- it "runs filters as usual" do
275
+ it "runs callbacks as usual" do
276
276
  expect_any_instance_of(Flexirest::Request).to receive(:do_request).with(any_args).and_return(::FaradayResponseMock.new(OpenStruct.new(status:200, response_headers:{}, body:"{\"first_name\":\"Billy\"}")))
277
- expect(EmptyExample).to receive(:_filter_request).with(any_args).exactly(2).times
277
+ expect(EmptyExample).to receive(:_callback_request).with(any_args).exactly(2).times
278
278
  EmptyExample._request("http://api.example.com/")
279
279
  end
280
280
 
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
- class RequestFilteringExample
4
- include Flexirest::RequestFiltering
3
+ class CallbacksExample
4
+ include Flexirest::Callbacks
5
5
 
6
6
  before_request do |name, request|
7
- request.get_params[:filter1] = "Hello"
7
+ request.get_params[:callback1] = "Hello"
8
8
  end
9
9
 
10
10
  before_request do |name, request|
11
- request.post_params[:post_filter1] = "World"
11
+ request.post_params[:post_callback1] = "World"
12
12
  end
13
13
 
14
14
  before_request do |name, request|
@@ -35,50 +35,50 @@ class RequestFilteringExample
35
35
  end
36
36
  end
37
37
 
38
- class SubClassedRequestFilteringExample < RequestFilteringExample
38
+ class SubClassedCallbacksExample < CallbacksExample
39
39
  before_request do |name, request|
40
40
  request.get_params[:api_key] = 1234
41
41
  end
42
42
  end
43
43
 
44
- describe Flexirest::RequestFiltering do
44
+ describe Flexirest::Callbacks do
45
45
  let(:request) { OpenStruct.new(get_params:{}, post_params:{}, url:"http://www.example.com", headers:Flexirest::HeadersList.new) }
46
46
  let(:response) { OpenStruct.new(body:"") }
47
47
 
48
48
  it "should call through to adjust the parameters" do
49
- RequestFilteringExample._filter_request(:before, :test, request)
50
- expect(request.get_params).to have_key(:filter1)
49
+ CallbacksExample._callback_request(:before, :test, request)
50
+ expect(request.get_params).to have_key(:callback1)
51
51
  end
52
52
 
53
- it "should call through for more than one filter" do
54
- RequestFilteringExample._filter_request(:before, :test, request)
55
- expect(request.get_params).to have_key(:filter1)
56
- expect(request.post_params).to have_key(:post_filter1)
53
+ it "should call through for more than one callback" do
54
+ CallbacksExample._callback_request(:before, :test, request)
55
+ expect(request.get_params).to have_key(:callback1)
56
+ expect(request.post_params).to have_key(:post_callback1)
57
57
  end
58
58
 
59
- it "should allow adjusting the URL via a named filter" do
60
- RequestFilteringExample._filter_request(:before, :test, request)
59
+ it "should allow adjusting the URL via a named callback" do
60
+ CallbacksExample._callback_request(:before, :test, request)
61
61
  expect(request.url).to match(/https:\/\//)
62
62
  end
63
63
 
64
- it "should allow adjusting the URL via a named filter as an instance method" do
65
- RequestFilteringExample._filter_request(:before, :test, request)
64
+ it "should allow adjusting the URL via a named callback as an instance method" do
65
+ CallbacksExample._callback_request(:before, :test, request)
66
66
  expect(request.url).to match(/\/\/new\./)
67
67
  end
68
68
 
69
- it "should allow filters to be set on the parent or on the child" do
70
- SubClassedRequestFilteringExample._filter_request(:before, :test, request)
69
+ it "should allow callbacks to be set on the parent or on the child" do
70
+ SubClassedCallbacksExample._callback_request(:before, :test, request)
71
71
  expect(request.url).to match(/\/\/new\./)
72
72
  expect(request.get_params[:api_key]).to eq(1234)
73
73
  end
74
74
 
75
- it "should allow filters to add custom headers" do
76
- RequestFilteringExample._filter_request(:before, :test, request)
75
+ it "should allow callbacks to add custom headers" do
76
+ CallbacksExample._callback_request(:before, :test, request)
77
77
  expect(request.headers["X-My-Header"]).to eq("myvalue")
78
78
  end
79
79
 
80
80
  it "should be able to alter the response body" do
81
- RequestFilteringExample._filter_request(:after, :test, response)
81
+ CallbacksExample._callback_request(:after, :test, response)
82
82
  expect(response.body).to eq("{test: 1}")
83
83
  end
84
84
  end
@@ -194,7 +194,7 @@ describe Flexirest::Base do
194
194
  expect(ret.name).to eq("Johnny")
195
195
  end
196
196
 
197
- it "can force the URL from a filter without it being passed through URL replacement" do
197
+ it "can force the URL from a callback without it being passed through URL replacement" do
198
198
  expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/hal_test/1", instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", status:200, response_headers:{})))
199
199
  expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/this/is/a/test", instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"result\":true}", status:200, response_headers:{})))
200
200
  expect(ProxyClientExample.hal_test(id:1).test.result).to eq(true)
@@ -203,10 +203,8 @@ describe Flexirest::Base do
203
203
  it "properly passes basic HTTP auth credentials" do
204
204
  host, credentials, url_path = 'www.example.com', 'user:pass', '/getAll?id=1'
205
205
  ProxyClientExample.base_url "http://#{credentials}@#{host}"
206
- stub_request(:get, "#{host}#{url_path}")
206
+ stub_request(:get, "http://#{credentials}@#{host}#{url_path}")
207
207
  ProxyClientExample.all(id:1)
208
- expect(a_request(:get, "#{host}#{url_path}").with(headers: {
209
- 'Authorization'=>"Basic #{Base64.strict_encode64(credentials)}"
210
- })).to have_been_made
208
+ expect(a_request(:get, "#{credentials}@#{host}#{url_path}")).to have_been_made
211
209
  end
212
210
  end
@@ -80,7 +80,7 @@ describe Flexirest::Request do
80
80
  post :create, "/create"
81
81
  end
82
82
 
83
- class FilteredBodyExampleClient < ExampleClient
83
+ class CallbackBodyExampleClient < ExampleClient
84
84
  base_url "http://www.example.com"
85
85
  before_request do |name, request|
86
86
  request.body = MultiJson.dump(request.post_params)
@@ -312,6 +312,11 @@ describe Flexirest::Request do
312
312
  expect(ExampleClient.plain(id:1234)).to be_a(Flexirest::PlainResponse)
313
313
  end
314
314
 
315
+ it "should return true from 204 with empty bodies" do
316
+ expect_any_instance_of(Flexirest::Connection).to receive(:get).with(any_args).and_return(::FaradayResponseMock.new(OpenStruct.new(status:204, response_headers:{}, body: nil)))
317
+ expect(ExampleClient.all).to be_truthy
318
+ end
319
+
315
320
  it "should return a lazy loader object if lazy loading is enabled" do
316
321
  object = LazyLoadedExampleClient.fake id:1234, debug:true
317
322
  expect(object).to be_an_instance_of(Flexirest::LazyLoader)
@@ -640,7 +645,7 @@ describe Flexirest::Request do
640
645
  def username ; end
641
646
  def password ; end
642
647
  def name ; end
643
- def _filter_request(*args) ; end
648
+ def _callback_request(*args) ; end
644
649
  def verbose ; false ; end
645
650
  end
646
651
  fake_object = RequestFakeObject.new
@@ -649,20 +654,20 @@ describe Flexirest::Request do
649
654
  expect{request.call}.to raise_error(Flexirest::InvalidRequestException)
650
655
  end
651
656
 
652
- it "should send all class mapped methods through _filter_request" do
657
+ it "should send all class mapped methods through _callback_request" do
653
658
  expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"expenses\":[{\"amount\":1}, {\"amount\":2}]}", status:200, response_headers:{})))
654
- expect(ExampleClient).to receive(:_filter_request).with(any_args).exactly(2).times
659
+ expect(ExampleClient).to receive(:_callback_request).with(any_args).exactly(2).times
655
660
  ExampleClient.all
656
661
  end
657
662
 
658
- it "should send all instance mapped methods through _filter_request" do
663
+ it "should send all instance mapped methods through _callback_request" do
659
664
  expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"expenses\":[{\"amount\":1}, {\"amount\":2}]}", status:200, response_headers:{})))
660
- expect(ExampleClient).to receive(:_filter_request).with(any_args).exactly(2).times
665
+ expect(ExampleClient).to receive(:_callback_request).with(any_args).exactly(2).times
661
666
  e = ExampleClient.new
662
667
  e.all
663
668
  end
664
669
 
665
- it "should change the generated object if an after_filter changes it" do
670
+ it "should change the generated object if an after_request changes it" do
666
671
  expect_any_instance_of(Flexirest::Connection).to receive(:get).with("/change", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"Johnny\", \"expenses\":[{\"amount\":1}, {\"amount\":2}]}", status:200, response_headers:{})))
667
672
  obj = ExampleClient.change
668
673
  expect(obj.test).to eq(1)
@@ -737,7 +742,7 @@ describe Flexirest::Request do
737
742
  end
738
743
 
739
744
  def name ; end
740
- def _filter_request(*args) ; end
745
+ def _callback_request(*args) ; end
741
746
  end
742
747
  fake_object = RequestFakeObject.new
743
748
  request = Flexirest::Request.new(method, fake_object, {})
@@ -784,9 +789,9 @@ describe Flexirest::Request do
784
789
  end
785
790
  end
786
791
 
787
- it "replaces the body completely in a filter" do
792
+ it "replaces the body completely in a callback" do
788
793
  expect_any_instance_of(Flexirest::Connection).to receive(:post).with("/save", "{\"id\":1234,\"name\":\"john\"}", an_instance_of(Hash)).and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{}", response_headers:{})))
789
- FilteredBodyExampleClient.save id:1234, name:'john'
794
+ CallbackBodyExampleClient.save id:1234, name:'john'
790
795
  end
791
796
 
792
797
  context 'Simulating Faraday connection in_parallel' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexirest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.20
4
+ version: 1.3.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-21 00:00:00.000000000 Z
11
+ date: 2016-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -236,6 +236,7 @@ files:
236
236
  - lib/flexirest/attribute_parsing.rb
237
237
  - lib/flexirest/base.rb
238
238
  - lib/flexirest/caching.rb
239
+ - lib/flexirest/callbacks.rb
239
240
  - lib/flexirest/configuration.rb
240
241
  - lib/flexirest/connection.rb
241
242
  - lib/flexirest/connection_manager.rb
@@ -251,7 +252,6 @@ files:
251
252
  - lib/flexirest/recording.rb
252
253
  - lib/flexirest/request.rb
253
254
  - lib/flexirest/request_delegator.rb
254
- - lib/flexirest/request_filtering.rb
255
255
  - lib/flexirest/result_iterator.rb
256
256
  - lib/flexirest/validation.rb
257
257
  - lib/flexirest/version.rb
@@ -259,6 +259,7 @@ files:
259
259
  - spec/lib/attribute_parsing_spec.rb
260
260
  - spec/lib/base_spec.rb
261
261
  - spec/lib/caching_spec.rb
262
+ - spec/lib/callbacks_spec.rb
262
263
  - spec/lib/configuration_spec.rb
263
264
  - spec/lib/connection_manager_spec.rb
264
265
  - spec/lib/connection_spec.rb
@@ -272,7 +273,6 @@ files:
272
273
  - spec/lib/plain_response_spec.rb
273
274
  - spec/lib/proxy_spec.rb
274
275
  - spec/lib/recording_spec.rb
275
- - spec/lib/request_filtering_spec.rb
276
276
  - spec/lib/request_spec.rb
277
277
  - spec/lib/result_iterator_spec.rb
278
278
  - spec/lib/validation_spec.rb
@@ -310,6 +310,7 @@ test_files:
310
310
  - spec/lib/attribute_parsing_spec.rb
311
311
  - spec/lib/base_spec.rb
312
312
  - spec/lib/caching_spec.rb
313
+ - spec/lib/callbacks_spec.rb
313
314
  - spec/lib/configuration_spec.rb
314
315
  - spec/lib/connection_manager_spec.rb
315
316
  - spec/lib/connection_spec.rb
@@ -323,7 +324,6 @@ test_files:
323
324
  - spec/lib/plain_response_spec.rb
324
325
  - spec/lib/proxy_spec.rb
325
326
  - spec/lib/recording_spec.rb
326
- - spec/lib/request_filtering_spec.rb
327
327
  - spec/lib/request_spec.rb
328
328
  - spec/lib/result_iterator_spec.rb
329
329
  - spec/lib/validation_spec.rb
@@ -1,63 +0,0 @@
1
- module Flexirest
2
- module RequestFiltering
3
- module ClassMethods
4
- def before_request(method_name = nil, &block)
5
- @before_filters ||= []
6
- if block
7
- @before_filters << block
8
- elsif method_name
9
- @before_filters << method_name
10
- end
11
- end
12
-
13
- def after_request(method_name = nil, &block)
14
- @after_filters ||= []
15
- if block
16
- @after_filters << block
17
- elsif method_name
18
- @after_filters << method_name
19
- end
20
- end
21
-
22
- def _filter_request(type, name, param)
23
- _handle_super_class_filters(type, name, param)
24
- @before_filters ||= []
25
- @after_filters ||= []
26
- filters = (type == :before ? @before_filters : @after_filters)
27
- filters.each do |filter|
28
- if filter.is_a? Symbol
29
- if self.respond_to?(filter)
30
- self.send(filter, name, param)
31
- else
32
- instance = self.new
33
- instance.send(filter, name, param)
34
- end
35
- else
36
- filter.call(name, param)
37
- end
38
- end
39
- end
40
-
41
- def _handle_super_class_filters(type, name, request)
42
- @parents ||= []
43
- @parents.each do |parent|
44
- parent._filter_request(type, name, request)
45
- end
46
- end
47
-
48
- def _parents
49
- @parents ||= []
50
- end
51
-
52
- def inherited(subclass)
53
- subclass._parents << self
54
- super
55
- end
56
- end
57
-
58
- def self.included(base)
59
- base.extend(ClassMethods)
60
- end
61
-
62
- end
63
- end