worker_plugins 0.0.1 → 0.0.2

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: b02032cf4ca7cab9ca6d43aa634f0a1e1f4c50dd
4
- data.tar.gz: 7bf7f0008e1164b6dafbdae020f501076e3069ca
3
+ metadata.gz: 52655eb17a18d0572ef81a2f987d7292064c4e76
4
+ data.tar.gz: dced538dc719887acdb52872cd03fac55980ec9f
5
5
  SHA512:
6
- metadata.gz: e93cdf09a3e34fedf235cc4f97434b4c6179ccd9d5dce40f59ab1959c4e259cecb73e5aba5e3da2c4103d5fddc165fd83c0a017ff85a6683cd78ab2bcff260a8
7
- data.tar.gz: 1b449b9c8255ef3fd147afd4d87e0f490e68473263ad7756e4a3b53210f82cb53b42a4ac28e64cb8fa36139e1aa25b667554aecc7ca085d6dde83d91efb33a19
6
+ metadata.gz: a52d62435a2b7e04b756c8c570d2b903686d6ce311942264c4b0995ebde3d53c20b33e312e975200582646023182c95beb853a3a89c9e2515ff2e6d4ad50a043
7
+ data.tar.gz: e6e897b847cc6d5968dc8cbe9c67228a2853aadcf75cfa5e5262f7e6468d0aa17178016bf5c3445a1604480c9059aafce78e13ef8d354c918173e4b21051b1b2
data/README.md CHANGED
@@ -1,3 +1,27 @@
1
1
  # WorkerPlugins
2
2
 
3
+ ## Install
4
+
5
+ Add to your Gemfile and bundle:
6
+ ```ruby
7
+ gem 'worker_plugins'
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ Add a lot of objects to a workspace through transactions:
13
+
14
+ ```ruby
15
+ users = User.where('id > 0')
16
+ workspace.add_links_to_objects(users)
17
+ ```
18
+
19
+ Optimally loop over resources on a workspace:
20
+
21
+ ```ruby
22
+ workspace.each_resource(types: ['User']) do |user|
23
+ ```
24
+
25
+ ## License
26
+
3
27
  This project rocks and uses MIT-LICENSE.
@@ -34,7 +34,10 @@ class WorkerPlugins::Workplace < ActiveRecord::Base
34
34
  def each_resource(args = {})
35
35
  count = 0
36
36
 
37
- workplace_links.group('worker_plugins_workplace_links.resource_type').order('worker_plugins_workplace_links.id').each do |workplace_link|
37
+ links_query = workplace_links.group('worker_plugins_workplace_links.resource_type').order('worker_plugins_workplace_links.id')
38
+ links_query = links_query.where(resource_type: args[:types]) if args[:types]
39
+
40
+ links_query.each do |workplace_link|
38
41
  constant = Object.const_get(workplace_link.resource_type)
39
42
  ids = workplace_links.select(:resource_id).where(resource_type: workplace_link.resource_type).map(&:resource_id)
40
43
 
@@ -46,8 +49,20 @@ class WorkerPlugins::Workplace < ActiveRecord::Base
46
49
  end
47
50
  end
48
51
  end
52
+ end
49
53
 
50
- return
54
+ def each_query_for_resources
55
+ workplace_links.group('worker_plugins_workplace_links.resource_type').order('worker_plugins_workplace_links.id').each do |workplace_link|
56
+ resource_type = workplace_link.resource_type
57
+ constant = Object.const_get(resource_type)
58
+ ids = workplace_links.select(:resource_id).where(resource_type: workplace_link.resource_type).map(&:resource_id)
59
+
60
+ ids.each_slice(500) do |ids_slice|
61
+ query = constant.where(id: ids_slice)
62
+
63
+ yield(query: query, resource_type: resource_type)
64
+ end
65
+ end
51
66
  end
52
67
 
53
68
  def truncate
@@ -1,3 +1,3 @@
1
1
  module WorkerPlugins
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worker_plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johanmsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-21 00:00:00.000000000 Z
11
+ date: 2015-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.21
27
- - !ruby/object:Gem::Dependency
28
- name: cancancan
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
27
  - !ruby/object:Gem::Dependency
42
28
  name: active-record-transactioner
43
29
  requirement: !ruby/object:Gem::Requirement