take_care 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fa95c237faea234849c224d4c8e00e69fc37af63
4
+ data.tar.gz: 7a3006a04abcdb2afcccd02407cac1efbe068d14
5
+ SHA512:
6
+ metadata.gz: fc341db5e388cdae6c349a1870d6429d137977ce0641fd9f4d4963e07385418c1d320a8830734ffd480c5fbcb5e516ae0902d0b9f74999a111c38bd9740dbcbe
7
+ data.tar.gz: ba4dec1f20f71aa8347ec9d1f9e9422e2f39a21a6ae1f0dd8984cd276c639e0ebe03057a47217977fc132f321a8fa045e63ebe80649cbc5c7e4ea7c12f61fa2b
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 take_care.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alexander Avoyants
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,46 @@
1
+ # TakeCare
2
+
3
+ Sidekiq wrapper for activerecord model
4
+
5
+ Method #take_care(method, *args) that delegates actual performing to sidekiq
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'take_care'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install take_care
20
+
21
+ ## Usage
22
+
23
+ Include TakeCare::Reliable into your model and you will get #take_care method inside of it.
24
+
25
+ ```rb
26
+ class Human < ActiveRecord::Base
27
+ include TakeCare::Reliable
28
+
29
+ def hard_work(box1, box2)
30
+ # Code that needs to be executed in background
31
+ end
32
+ end
33
+
34
+ human = Human.create(name: 'Alex')
35
+
36
+ human.take_care :hard_work, 'heavy box', 'second heavy box' # This goes to sidekiq
37
+
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ module TakeCare
2
+ module Reliable
3
+ def take_care(method, *args)
4
+ TakeCare::Worker.perform_async(self.class.to_s, self.id, method, *args)
5
+ end
6
+ alias_method :take_care_of, :take_care
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module TakeCare
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,12 @@
1
+ require "sidekiq"
2
+ require "active_support"
3
+
4
+ module TakeCare
5
+ class Worker
6
+ include ::Sidekiq::Worker
7
+
8
+ def perform(class_name, instance_id, instance_method, *args)
9
+ class_name.constantize.find(instance_id).__send__(instance_method, *args)
10
+ end
11
+ end
12
+ end
data/lib/take_care.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "take_care/version"
2
+ require "take_care/worker"
3
+ require "take_care/reliable"
4
+
5
+ module TakeCare
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,7 @@
1
+ require "take_care"
2
+
3
+ Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
4
+
5
+ RSpec.configure do |config|
6
+ config.mock_with :rspec
7
+ end
@@ -0,0 +1,8 @@
1
+ class Human
2
+ def id
3
+ 4
4
+ end
5
+
6
+ def hard_work(box1, box2)
7
+ end
8
+ end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ describe TakeCare::Reliable do
4
+ let(:human) { Human.new.extend(TakeCare::Reliable) }
5
+
6
+ describe "#take_care" do
7
+ it "delegates method calls to Worker" do
8
+ TakeCare::Worker.should_receive(:perform_async).with("Human", 4, :hard_work, :box1, :box2)
9
+ human.take_care :hard_work, :box1, :box2
10
+ end
11
+ end
12
+
13
+ describe "#take_care_of (alias of #take_care)" do
14
+ it "delegates method calls to Worker" do
15
+ TakeCare::Worker.should_receive(:perform_async).with("Human", 4, :hard_work, :box1, :box2)
16
+ human.take_care_of :hard_work, :box1, :box2
17
+ end
18
+ end
19
+
20
+ # context "Dinamic methods 'take_care_...'" do
21
+ # it "delegates method calls to Worker" do
22
+ # TakeCare::Worker.should_receive(:perform_async).with("Human", 4, :hard_work, :box1, :box2)
23
+ # human.take_care_of_hard_work :box1, :box2
24
+ # end
25
+ # end
26
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ describe TakeCare::Worker do
4
+ describe '#perform' do
5
+ it "should include Sidekiq::Worker" do
6
+ described_class.ancestors.should include Sidekiq::Worker
7
+ end
8
+
9
+ it "finds class instance by id and calls mathod with received args" do
10
+ duty = double("Human instance")
11
+ Human.should_receive(:find).with(4).and_return(duty)
12
+ duty.should_receive(:hard_work).with(:box1, :box2)
13
+ subject.perform("Human", 4, :hard_work, :box1, :box2)
14
+ end
15
+ end
16
+ end
data/take_care.gemspec ADDED
@@ -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 'take_care/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "take_care"
8
+ spec.version = TakeCare::VERSION
9
+ spec.authors = ["Alexander Avoyants"]
10
+ spec.email = ["shhavel@gmail.com"]
11
+ spec.description = %q{Sidekiq wrapper for activerecord model}
12
+ spec.summary = %q{Sidekiq wrapper for activerecord model (any class which instances fetched by id)}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
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 "activesupport"
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: take_care
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Avoyants
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-22 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: activesupport
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: rspec
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: Sidekiq wrapper for activerecord model
84
+ email:
85
+ - shhavel@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/take_care.rb
96
+ - lib/take_care/reliable.rb
97
+ - lib/take_care/version.rb
98
+ - lib/take_care/worker.rb
99
+ - spec/spec_helper.rb
100
+ - spec/support/human.rb
101
+ - spec/take_care/reliable_spec.rb
102
+ - spec/take_care/worker_spec.rb
103
+ - take_care.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.0.6
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Sidekiq wrapper for activerecord model (any class which instances fetched
128
+ by id)
129
+ test_files:
130
+ - spec/spec_helper.rb
131
+ - spec/support/human.rb
132
+ - spec/take_care/reliable_spec.rb
133
+ - spec/take_care/worker_spec.rb