tenantify-sidekiq 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7a3d0a302c33f8e373a688d80529a4d06e0db67a
4
+ data.tar.gz: 0f08ff80e0f2ea6a514d671e6d1486de2e7ee8fc
5
+ SHA512:
6
+ metadata.gz: e8ee753355deb7c0231ec3f03e3b9e5cfaf1a45900ffde29f00514b9d01ceb7eed0e8ff43b5b314af7f3304767b63bbf27f52e7ad3e199b79821b4df679ceac2
7
+ data.tar.gz: 552c4ccfe737d0c02ec024f3ae682c44ba0f6a9977555a6d52554a97e8b62bd9647c3caa53aab2164182377eaa78502d2550407042dc3954c32bc8c313cdbdfa
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tenantify-sidekiq.gemspec
4
+ gemspec
5
+
6
+ gem "tenantify", :git => "https://jcabotc@bitbucket.org/qustodian/tenantify.git"
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jaime Cabot Campins
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # Tenantify::Sidekiq
2
+
3
+ This gem provides a client and a server middlewares for Sidekiq to work with the tenantify gem
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'tenantify-sidekiq'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ Just add the client and the server middlewares to its respective middleware chains:
20
+
21
+ ```ruby
22
+ require 'tenantify-sidekiq'
23
+
24
+ Sidekiq.configure_client do |config|
25
+ config.client_middleware do |chain|
26
+ chain.add Tenantify::Sidekiq::Middlewares::Client
27
+ end
28
+ end
29
+
30
+ Sidekiq.configure_server do |config|
31
+ config.server_middleware do |chain|
32
+ chain.add Tenantify::Sidekiq::Middlewares::Server
33
+ end
34
+ end
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it ( https://github.com/[my-github-username]/tenantify-sidekiq/fork )
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,9 @@
1
+ require "tenantify/sidekiq/version"
2
+
3
+ require "tenantify/sidekiq/middlewares/client"
4
+ require "tenantify/sidekiq/middlewares/server"
5
+
6
+ module Tenantify
7
+ module Sidekiq
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module Tenantify
2
+ module Sidekiq
3
+ module Middlewares
4
+ class Client
5
+
6
+ def call worker_class, job, queue, redis_pool
7
+ job["tenant"] = ::Tenantify::Perform.current
8
+ yield
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module Tenantify
2
+ module Sidekiq
3
+ module Middlewares
4
+ class Server
5
+
6
+ def call worker, job, queue
7
+ tenant = job.fetch("tenant")
8
+
9
+ ::Tenantify::Perform.with(tenant) { yield }
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module Tenantify
2
+ module Sidekiq
3
+
4
+ VERSION = "0.0.1"
5
+
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ require 'pry'
2
+
3
+ RSpec.configure do |config|
4
+
5
+ config.expect_with :rspec do |expectations|
6
+ # Best error messages on chained expectations
7
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
8
+ end
9
+
10
+ config.mock_with :rspec do |mocks|
11
+ # Prevents you from stubbing a method that does not exist on a real object
12
+ mocks.verify_partial_doubles = true
13
+ end
14
+
15
+ config.disable_monkey_patching!
16
+ config.order = :random
17
+
18
+ end
@@ -0,0 +1,31 @@
1
+ require 'tenantify'
2
+ require 'tenantify/sidekiq/middlewares/client'
3
+
4
+ RSpec.describe Tenantify::Sidekiq::Middlewares::Client do
5
+
6
+ subject { described_class.new }
7
+
8
+ describe '#call' do
9
+ let(:worker_class) { double 'worker_class' }
10
+ let(:queue) { double 'queue' }
11
+ let(:redis_pool) { double 'redis_pool' }
12
+
13
+ let(:job) { { "fake" => "value" } }
14
+
15
+ let(:tenant_name) { "a_tenant" }
16
+
17
+ it 'adds a tenant key to the job hash' do
18
+ block_called = false
19
+
20
+ Tenantify::Perform.with tenant_name do
21
+ subject.call(worker_class, job, queue, redis_pool) do
22
+ block_called = true
23
+ end
24
+ end
25
+
26
+ expect(job["tenant"]).to eq tenant_name
27
+ expect(block_called).to eq true
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,28 @@
1
+ require 'tenantify'
2
+ require 'tenantify/sidekiq/middlewares/server'
3
+
4
+ RSpec.describe Tenantify::Sidekiq::Middlewares::Server do
5
+
6
+ subject { described_class.new }
7
+
8
+ describe '#call' do
9
+ let(:worker_class) { double 'worker_class' }
10
+ let(:queue) { double 'queue' }
11
+
12
+ let(:tenant_name) { "a_tenant" }
13
+ let(:job) { { "tenant" => tenant_name } }
14
+
15
+ it 'adds a tenant key to the job hash' do
16
+ block_called = false
17
+
18
+ subject.call(worker_class, job, queue) do
19
+ expect(Tenantify::Perform.current).to eq tenant_name
20
+
21
+ block_called = true
22
+ end
23
+
24
+ expect(block_called).to eq true
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tenantify/sidekiq/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tenantify-sidekiq"
8
+ spec.version = Tenantify::Sidekiq::VERSION
9
+ spec.authors = ["Jaime Cabot Campins"]
10
+ spec.email = ["jcabot@gmail.com"]
11
+ spec.summary = %q{Provides middlewares to work with the tenantify gem and sidekiq}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "tenantify"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "pry"
26
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tenantify-sidekiq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jaime Cabot Campins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tenantify
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - jcabot@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/tenantify/sidekiq.rb
97
+ - lib/tenantify/sidekiq/middlewares/client.rb
98
+ - lib/tenantify/sidekiq/middlewares/server.rb
99
+ - lib/tenantify/sidekiq/version.rb
100
+ - spec/spec_helper.rb
101
+ - spec/tenantify/sidekiq/middlewares/client_spec.rb
102
+ - spec/tenantify/sidekiq/middlewares/server_spec.rb
103
+ - tenantify-sidekiq.gemspec
104
+ homepage: ''
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Provides middlewares to work with the tenantify gem and sidekiq
128
+ test_files:
129
+ - spec/spec_helper.rb
130
+ - spec/tenantify/sidekiq/middlewares/client_spec.rb
131
+ - spec/tenantify/sidekiq/middlewares/server_spec.rb