RackMotion 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/project/RackMotion.rb +29 -7
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb2494f20c65313b1700f2617b6c5b11da36a2df
4
- data.tar.gz: a747d75245919048c09797bf184b37f123c995e0
3
+ metadata.gz: ee9068613ce2063f92e820d0490c7bb59cedd2f7
4
+ data.tar.gz: 2145db0a91f4b9d9dd6f7329b48e870e9fb07202
5
5
  SHA512:
6
- metadata.gz: c064c8046f25d695fb8c5478e97836ea94d438670342782c1f8fb8d2f222f3fc654247dc7f54529c25b7424fb63f29c10153aa58aeabf2676080832a303c0fcc
7
- data.tar.gz: 5a51befbadc837d6b5fbc6427a573d69b6b37dd1be2c856672d287e9b6efea31236ea295c58a9dc1023859cb77535c486b997922990426ace072de5fe1e1654c
6
+ metadata.gz: a4d11b2b4d4aa13070cc32e7e817f9c8d807593662a210613d27f2c68544dc81ada3096eec9048553119904f4c673b1ffeddc82650c81b665cbc849a9ad47503
7
+ data.tar.gz: 08b276a6f08d958b258d015f0c39b69c1da54de514c9dbd6334b59a174761521083a445da1f03d3fad7d8d23b5b210118638289317f2965893b1db57f75dd926
@@ -1,26 +1,40 @@
1
1
  module RackMotion
2
2
  def self.use(middleware)
3
- NSURLProtocol.registerClass URLProtocol if URLProtocol.middlewares.empty?
3
+ self.registerURLProtocol
4
4
  URLProtocol.middlewares << middleware
5
5
  end
6
6
 
7
- def self.cease(middleware)
8
- URLProtocol.middlewares.delete middleware
9
- NSURLProtocol.unregisterClass URLProtocol if URLProtocol.middlewares.empty?
7
+ def self.run(app)
8
+ self.registerURLProtocol
9
+ URLProtocol.app = app
10
10
  end
11
11
 
12
- def self.cease_all
12
+ def self.cease
13
13
  URLProtocol.middlewares = []
14
+ URLProtocol.app = nil
14
15
  NSURLProtocol.unregisterClass URLProtocol
15
16
  end
16
17
 
17
18
  class URLProtocol < NSURLProtocol
18
19
  @@middlewares = []
20
+ @@app = nil
19
21
 
20
22
  def self.middlewares
21
23
  @@middlewares
22
24
  end
23
25
 
26
+ def self.middlewares=(obj)
27
+ @@middlewares = obj
28
+ end
29
+
30
+ def self.app
31
+ @@app
32
+ end
33
+
34
+ def self.app=(obj)
35
+ @@app = obj
36
+ end
37
+
24
38
  def self.canInitWithRequest(request)
25
39
  return false unless request.URL
26
40
  return false unless request.URL.scheme.start_with?("http")
@@ -33,13 +47,14 @@ module RackMotion
33
47
 
34
48
  def startLoading
35
49
  @thread = NSThread.alloc.initWithTarget(lambda do
36
- chain = @@middlewares.inject(self) do |instance, klass|
50
+
51
+ chain = @@middlewares.inject(@@app ? @@app : self) do |instance, klass|
37
52
  klass.new(instance)
38
53
  end
39
54
 
40
55
  status, headers, data = chain.call self.request.mutableCopy
41
56
 
42
- response = NSHTTPURLResponse.alloc.initWithURL @connection.originalRequest.URL, statusCode: status, HTTPVersion: 'HTTP/1.1', headerFields: headers
57
+ response = NSHTTPURLResponse.alloc.initWithURL self.request.URL, statusCode: status, HTTPVersion: 'HTTP/1.1', headerFields: headers
43
58
 
44
59
  self.client.URLProtocol(self, didReceiveResponse: response, cacheStoragePolicy: NSURLCacheStorageNotAllowed)
45
60
  self.client.URLProtocol(self, didLoadData: data)
@@ -87,4 +102,11 @@ module RackMotion
87
102
  @semaphore.signal
88
103
  end
89
104
  end
105
+
106
+ private
107
+ def self.registerURLProtocol
108
+ if URLProtocol.middlewares.empty? && URLProtocol.app.nil?
109
+ NSURLProtocol.registerClass URLProtocol
110
+ end
111
+ end
90
112
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: RackMotion
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drew Carey Buglione
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-16 00:00:00.000000000 Z
11
+ date: 2013-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake