circuitry-middleware 1.0.0 → 1.1.0
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.
- checksums.yaml +4 -4
- data/README.md +41 -1
- data/circuitry-middleware.gemspec +1 -0
- data/lib/circuitry/middleware.rb +1 -16
- data/lib/circuitry/middleware/rack.rb +22 -0
- data/lib/circuitry/middleware/railtie.rb +2 -2
- data/lib/circuitry/middleware/version.rb +2 -2
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14617084a8222481f7bab181591ffeb2db8f3bd6
|
4
|
+
data.tar.gz: c625290563320713b4ec8e95d0555b29c7a51768
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8953dfeb827d517720043cc53a76a1d35129946af56ff276dd864a419053d5f6914c164ab88e1a5b66b7a479616fcf5b4f8b2889b3f265f42519c5cdc043ce31
|
7
|
+
data.tar.gz: 4dc33256286700d0c0e5a8a0dce5de5b093cafd52b89057c78ca6731671eab31eeb9c9ae4618947da381e0623e3f67b5942758c6e422da63fbab2a45baf25126
|
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
Rails/Rack middleware for batching circuitry notifications.
|
4
4
|
|
5
|
+
[](https://codeclimate.com/repos/559d735f6956804ff2000a9b/feed)
|
6
|
+
[](https://codeclimate.com/repos/559d735f6956804ff2000a9b/coverage)
|
7
|
+
|
5
8
|
## Installation
|
6
9
|
|
7
10
|
Add this line to your application's Gemfile:
|
@@ -20,7 +23,7 @@ Or install it yourself as:
|
|
20
23
|
|
21
24
|
## Usage
|
22
25
|
|
23
|
-
### Ruby on Rails
|
26
|
+
### Ruby on Rails 4.x
|
24
27
|
|
25
28
|
If using this gem in the context of a Ruby on Rails application, there's nothing
|
26
29
|
more that you need to do beyond including the gem in your `Gemfile`.
|
@@ -33,6 +36,29 @@ initializer:
|
|
33
36
|
require 'circuitry-middleware'
|
34
37
|
```
|
35
38
|
|
39
|
+
### Ruby on Rails 3.x
|
40
|
+
|
41
|
+
If your application *does not* use either of the `Rack::ETag` or
|
42
|
+
`Rack::ConditionalGet` middleware components (check via `rake middleware`), then
|
43
|
+
you can follow the Rails 4.x directions above.
|
44
|
+
|
45
|
+
If your application *does* use either of these middleware components, then this
|
46
|
+
gem must be implemented in a different manner due to an older Rack dependency
|
47
|
+
that improperly implements these pieces of middleware.
|
48
|
+
|
49
|
+
First, in your `Gemfile`:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
gem 'circuitry-middleware', require: false
|
53
|
+
```
|
54
|
+
|
55
|
+
Then in your `config/application.rb`:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
require 'circuitry/middleware/rack'
|
59
|
+
config.middleware.insert_before Rack::ConditionalGet, Circuitry::Middleware::Rack
|
60
|
+
```
|
61
|
+
|
36
62
|
### Rack
|
37
63
|
|
38
64
|
If using this gem in the context of a Rack application, you'll need to explicitly
|
@@ -43,6 +69,20 @@ require 'circuitry-middleware'
|
|
43
69
|
use Circuitry::Middleware
|
44
70
|
```
|
45
71
|
|
72
|
+
### Custom Options
|
73
|
+
|
74
|
+
By default, this gem utilizes batching when publishing and threading when
|
75
|
+
subscribing. These options can be overridden by swapping the middleware.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
config.middleware.swap Circuitry::Middleware::Rack, Circuitry::Middleware::Rack,
|
79
|
+
publish_async_strategy: :fork,
|
80
|
+
subscribe_async_strategy: :fork
|
81
|
+
```
|
82
|
+
|
83
|
+
Please refer to the [circuitry gem](https://github.com/kapost/circuitry) for
|
84
|
+
more insight on asynchronous options.
|
85
|
+
|
46
86
|
## Development
|
47
87
|
|
48
88
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
data/lib/circuitry/middleware.rb
CHANGED
@@ -1,18 +1,3 @@
|
|
1
1
|
require 'circuitry/middleware/version'
|
2
|
+
require 'circuitry/middleware/rack'
|
2
3
|
require 'circuitry/middleware/railtie' if defined?(Rails)
|
3
|
-
require 'circuitry'
|
4
|
-
|
5
|
-
module Circuitry
|
6
|
-
class Middleware
|
7
|
-
def initialize(app, options = {})
|
8
|
-
@app = app
|
9
|
-
Circuitry.config.publish_async_strategy = options.fetch(:publish_async_strategy, :batch)
|
10
|
-
Circuitry.config.subscribe_async_strategy = options.fetch(:subscribe_async_strategy, :thread)
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(env)
|
14
|
-
@app.call(env)
|
15
|
-
Circuitry.flush
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'circuitry'
|
2
|
+
require 'rack/body_proxy'
|
3
|
+
|
4
|
+
module Circuitry
|
5
|
+
module Middleware
|
6
|
+
class Rack
|
7
|
+
def initialize(app, options = {})
|
8
|
+
@app = app
|
9
|
+
Circuitry.config.publish_async_strategy = options.fetch(:publish_async_strategy, :batch)
|
10
|
+
Circuitry.config.subscribe_async_strategy = options.fetch(:subscribe_async_strategy, :thread)
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
status, headers, actual_body = @app.call(env)
|
15
|
+
body = ::Rack::BodyProxy.new(actual_body) do
|
16
|
+
Circuitry.flush
|
17
|
+
end
|
18
|
+
[status, headers, body]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circuitry-middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Huggins
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: circuitry
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.4.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.4.5
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: pry-nav
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,6 +126,7 @@ files:
|
|
112
126
|
- circle.yml
|
113
127
|
- circuitry-middleware.gemspec
|
114
128
|
- lib/circuitry/middleware.rb
|
129
|
+
- lib/circuitry/middleware/rack.rb
|
115
130
|
- lib/circuitry/middleware/railtie.rb
|
116
131
|
- lib/circuitry/middleware/version.rb
|
117
132
|
homepage: https://github.com/kapost/circuitry-middleware
|
@@ -134,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
149
|
version: '0'
|
135
150
|
requirements: []
|
136
151
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.4.
|
152
|
+
rubygems_version: 2.4.3
|
138
153
|
signing_key:
|
139
154
|
specification_version: 4
|
140
155
|
summary: Rails/Rack middleware for batching circuitry notifications.
|