chewy_kiqqer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a364d1e2c036ad050b57aa91e61a72ee3319191e
4
+ data.tar.gz: 9cefa2b4bdf0e56a55c6c5b532374c4735aabd24
5
+ SHA512:
6
+ metadata.gz: 765a041ec58e3f32c1a853f686320cf5fb2d681c608f966a7781bad2c6894e67fad3b39c0bdc9009982f293aabda00e0aa460b38d5533a067a34da2c81a4d782
7
+ data.tar.gz: 9df08fe3e7e40a4d275782fb7739aff7d0e01168b39af27f9f9408854ac66e2755e8efd3a1f1d5946e07940240ced3187788869f06475036f1026ddfb3832cf8
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chewy_kiqqer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Daniel Hahn
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.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # ChewyKiqqer
2
+
3
+ This is an alternative udpate/callback mechanism for [Chewy](https://github.com/toptal/chewy). It queues the updates as [Sidekiq](https://github.com/mperham/sidekiq) jobs.
4
+
5
+ Unlike the standard update_index mechnism it will **always** use the record's index for updates (at this time at least). If you need to do bulk updates, just use chewy's built-in mechanisms.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'chewy_kiqqer'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install chewy_kiqqer
20
+
21
+ ## Usage
22
+
23
+ Just add the module and set it up:
24
+
25
+ class User < ActiveRecord::Base
26
+ include ChewyKiqqer::Mixin
27
+
28
+ async_update_index 'users#user'
29
+ end
30
+
31
+ You can also include the mixin into ActiveRecord::Base in an initializer if it should be generally available.
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ Bundler.require
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chewy_kiqqer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chewy_kiqqer"
8
+ spec.version = ChewyKiqqer::VERSION
9
+ spec.authors = ["Daniel Hahn"]
10
+ spec.email = ["dha@betterplace.org"]
11
+ spec.description = %q{Sidekiq integration for chewy and sidekiq}
12
+ spec.summary = %q{Small helper gem that allows you to automatically run all chewy index updates in sidekiq}
13
+ spec.homepage = ""
14
+ spec.license = "Apache V2"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'sidekiq'
22
+ spec.add_dependency 'chewy'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "kaminari"
27
+ spec.add_development_dependency "rspec"
28
+ end
@@ -0,0 +1,3 @@
1
+ require "chewy_kiqqer/version"
2
+ require "chewy_kiqqer/mixin"
3
+ require "chewy_kiqqer/worker"
@@ -0,0 +1,24 @@
1
+ require 'active_support/concern'
2
+
3
+ module ChewyKiqqer
4
+ module Mixin
5
+
6
+ extend ActiveSupport::Concern
7
+
8
+ module ClassMethods
9
+
10
+ attr_reader :index_name
11
+
12
+ def async_update_index(index_name)
13
+ @index_name = index_name
14
+ after_save :queue_job
15
+ after_destroy :queue_job
16
+ end
17
+
18
+ end
19
+
20
+ def queue_job
21
+ ChewyKiqqer::Worker.perform_async(self.class.index_name, id)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module ChewyKiqqer
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'sidekiq'
2
+
3
+ module ChewyKiqqer
4
+ class Worker
5
+ include Sidekiq::Worker
6
+ end
7
+ end
@@ -0,0 +1,39 @@
1
+ require 'chewy_kiqqer'
2
+
3
+ class Gummi
4
+ include ChewyKiqqer::Mixin
5
+
6
+ def self.after_save(*args) ; end
7
+ def self.after_destroy(*args) ; end
8
+ def id ; 17 ; end
9
+
10
+ end
11
+
12
+ describe ChewyKiqqer::Mixin do
13
+
14
+ context 'class methods' do
15
+ it 'installs the hooks' do
16
+ Gummi.should_receive(:after_save).with(:queue_job)
17
+ Gummi.should_receive(:after_destroy).with(:queue_job)
18
+ Gummi.async_update_index('xxx')
19
+ end
20
+
21
+ it 'knows the index_name' do
22
+ Gummi.async_update_index('bar#foo')
23
+ Gummi.index_name.should eq 'bar#foo'
24
+ end
25
+ end
26
+
27
+ context '#queue_job' do
28
+
29
+ let(:record) { Gummi.new }
30
+
31
+ it 'queues the job' do
32
+ Gummi.async_update_index 'foo#bar'
33
+ ChewyKiqqer::Worker.should_receive(:perform_async).with('foo#bar', 17)
34
+ record.queue_job
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,15 @@
1
+ require 'chewy_kiqqer'
2
+
3
+ desribe ChewyKiqqer::Worker do
4
+
5
+ let(:worker) { ChewyKiqqer::Worker.new }
6
+
7
+ it 'calls the indexing with chewy' do
8
+ index = double
9
+ Chewy.should_receive(:derive_type).with('foo#bar').and_return(index)
10
+ index.should_receive(:import).with(17)
11
+
12
+ worker.perform('foo#bar', index)
13
+ end
14
+
15
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chewy_kiqqer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Hahn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sidekiq
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: chewy
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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: kaminari
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
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Sidekiq integration for chewy and sidekiq
98
+ email:
99
+ - dha@betterplace.org
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - chewy_kiqqer.gemspec
110
+ - lib/chewy_kiqqer.rb
111
+ - lib/chewy_kiqqer/mixin.rb
112
+ - lib/chewy_kiqqer/version.rb
113
+ - lib/chewy_kiqqer/worker.rb
114
+ - spec/mixin_spec.rb
115
+ - spec/workder.spec.rb
116
+ homepage: ''
117
+ licenses:
118
+ - Apache V2
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.0.3
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Small helper gem that allows you to automatically run all chewy index updates
140
+ in sidekiq
141
+ test_files:
142
+ - spec/mixin_spec.rb
143
+ - spec/workder.spec.rb