circuitry-middleware 1.0.0 → 1.1.0

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: b9d45fd5d5fbbb9c44fa397c0f2597aed4e3a915
4
- data.tar.gz: 600f49ffdf7736ce580d25744d412b80bf083dbe
3
+ metadata.gz: 14617084a8222481f7bab181591ffeb2db8f3bd6
4
+ data.tar.gz: c625290563320713b4ec8e95d0555b29c7a51768
5
5
  SHA512:
6
- metadata.gz: 53b4d05fcb215e6b5ad2b450e328fb28a2905fddb0f40058501558196dc79dc86e7bfacd097a6bf2f947e03bc24b6f6b6068c0583d8ca004dcd3d68373ef1243
7
- data.tar.gz: c09774c1fefdc9d332e2a0febb07f003d9311477c331e1fc1e87778dd7b440d73941ea082dcb81a2f2e9e2817e2fbfa769f496c379c02626301bc61e3b2c79c2
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
+ [![Code Climate](https://codeclimate.com/repos/559d735f6956804ff2000a9b/badges/ab8b6ef0a8e8a115041b/gpa.svg)](https://codeclimate.com/repos/559d735f6956804ff2000a9b/feed)
6
+ [![Test Coverage](https://codeclimate.com/repos/559d735f6956804ff2000a9b/badges/ab8b6ef0a8e8a115041b/coverage.svg)](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
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ['lib']
21
21
 
22
22
  spec.add_dependency 'circuitry', '>= 1.1.0'
23
+ spec.add_dependency 'rack', '>= 1.4.5'
23
24
 
24
25
  spec.add_development_dependency 'pry-nav'
25
26
  spec.add_development_dependency 'bundler', '~> 1.8'
@@ -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
@@ -1,8 +1,8 @@
1
1
  module Circuitry
2
- class Middleware
2
+ module Middleware
3
3
  class Railtie < ::Rails::Railtie
4
4
  initializer 'circuitry.middleware' do |app|
5
- app.middleware.use Middleware
5
+ app.middleware.use Middleware::Rack
6
6
  end
7
7
  end
8
8
  end
@@ -1,5 +1,5 @@
1
1
  module Circuitry
2
- class Middleware
3
- VERSION = '1.0.0'
2
+ module Middleware
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  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.0.0
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-08 00:00:00.000000000 Z
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.8
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.