worker_plugins 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: b02032cf4ca7cab9ca6d43aa634f0a1e1f4c50dd
4
+ data.tar.gz: 7bf7f0008e1164b6dafbdae020f501076e3069ca
5
+ SHA512:
6
+ metadata.gz: e93cdf09a3e34fedf235cc4f97434b4c6179ccd9d5dce40f59ab1959c4e259cecb73e5aba5e3da2c4103d5fddc165fd83c0a017ff85a6683cd78ab2bcff260a8
7
+ data.tar.gz: 1b449b9c8255ef3fd147afd4d87e0f490e68473263ad7756e4a3b53210f82cb53b42a4ac28e64cb8fa36139e1aa25b667554aecc7ca085d6dde83d91efb33a19
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # WorkerPlugins
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'WorkerPlugins'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,77 @@
1
+ class WorkerPlugins::Workplace < ActiveRecord::Base
2
+ has_many :workplace_links, dependent: :destroy
3
+
4
+ belongs_to :user, polymorphic: true
5
+
6
+ validates_presence_of :name
7
+
8
+ def add_links_to_objects(objects)
9
+ require 'active-record-transactioner'
10
+
11
+ # Cache inserted objects.
12
+ inserted_ids = load_inserted_ids
13
+
14
+ # Add given objects through transactions.
15
+ ActiveRecordTransactioner.new do |trans|
16
+ stream_each(objects) do |object|
17
+ class_name = object.class.name.to_s
18
+ inserted_ids[class_name] ||= {}
19
+
20
+ unless inserted_ids[class_name].key?(object.id)
21
+ inserted_ids[class_name][object.id] = true
22
+ link = WorkerPlugins::WorkplaceLink.new(
23
+ workplace: self,
24
+ resource: object
25
+ )
26
+ trans.save!(link)
27
+ end
28
+ end
29
+ end
30
+
31
+ return
32
+ end
33
+
34
+ def each_resource(args = {})
35
+ count = 0
36
+
37
+ workplace_links.group('worker_plugins_workplace_links.resource_type').order('worker_plugins_workplace_links.id').each do |workplace_link|
38
+ constant = Object.const_get(workplace_link.resource_type)
39
+ ids = workplace_links.select(:resource_id).where(resource_type: workplace_link.resource_type).map(&:resource_id)
40
+
41
+ ids.each_slice(500) do |ids_slice|
42
+ constant.where(id: ids_slice).each do |resource|
43
+ yield resource
44
+ count += 1
45
+ return if args[:limit] && count >= args[:limit]
46
+ end
47
+ end
48
+ end
49
+
50
+ return
51
+ end
52
+
53
+ def truncate
54
+ workplace_links.delete_all
55
+ end
56
+
57
+ private
58
+
59
+ def stream_each(list, &blk)
60
+ if list.respond_to?(:find_each)
61
+ list.find_each(&blk)
62
+ else
63
+ list.each(&blk)
64
+ end
65
+ end
66
+
67
+ def load_inserted_ids
68
+ inserted_ids = {}
69
+
70
+ workplace_links.select(worker_plugins_workplace_links: [:resource_type, :resource_id]).find_each do |workplace_link|
71
+ inserted_ids[workplace_link.resource_type] ||= {}
72
+ inserted_ids[workplace_link.resource_type][workplace_link.resource_id] = true
73
+ end
74
+
75
+ return inserted_ids
76
+ end
77
+ end
@@ -0,0 +1,6 @@
1
+ class WorkerPlugins::WorkplaceLink < ActiveRecord::Base
2
+ belongs_to :workplace
3
+ belongs_to :resource, polymorphic: true
4
+
5
+ validates_presence_of :workplace, :resource
6
+ end
@@ -0,0 +1,16 @@
1
+ ---
2
+ da:
3
+ activerecord:
4
+ models:
5
+ worker_plugins/workplace:
6
+ one: Arbejdsplads
7
+ other: Arbejdspladser
8
+ attributes:
9
+ worker_plugins/workplace:
10
+ id: ID
11
+ name: Navn
12
+ user_id: Bruger ID
13
+ created_at: Oprettet d.
14
+ updated_at: Opdateret d.
15
+ workplace_links: Arbejdsplads links
16
+ user: Bruger
@@ -0,0 +1,16 @@
1
+ ---
2
+ en:
3
+ activerecord:
4
+ models:
5
+ worker_plugins/workplace:
6
+ one: Workplace
7
+ other: Workplaces
8
+ attributes:
9
+ worker_plugins/workplace:
10
+ id: ID
11
+ name: Name
12
+ user_id: User ID
13
+ created_at: Created at
14
+ updated_at: Updated at
15
+ workplace_links: Workplace links
16
+ user: User
@@ -0,0 +1,18 @@
1
+ ---
2
+ da:
3
+ activerecord:
4
+ models:
5
+ worker_plugins/workplace_link:
6
+ one: Arbejdspladslink
7
+ other: Arbejdspladslinks
8
+ attributes:
9
+ worker_plugins/workplace_link:
10
+ id: ID
11
+ workplace_id: Arbejdsplads ID
12
+ resource_id: Resource ID
13
+ resource_type: Resource type
14
+ custom_data: Selvvalgt data
15
+ created_at: Oprettet d.
16
+ updated_at: Opdateret d.
17
+ workplace: Arbejdsplads
18
+ resource: Resource
@@ -0,0 +1,18 @@
1
+ ---
2
+ en:
3
+ activerecord:
4
+ models:
5
+ worker_plugins/workplace_link:
6
+ one: Workplace link
7
+ other: Workplace links
8
+ attributes:
9
+ worker_plugins/workplace_link:
10
+ id: ID
11
+ workplace_id: Workplace ID
12
+ resource_id: Resource ID
13
+ resource_type: Resource type
14
+ custom_data: Custom data
15
+ created_at: Created at
16
+ updated_at: Updated at
17
+ workplace: Workplace
18
+ resource: Resource
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,13 @@
1
+ class CreateWorkerPluginsWorkplaces < ActiveRecord::Migration
2
+ def change
3
+ create_table :worker_plugins_workplaces do |t|
4
+ t.string :name
5
+ t.boolean :active
6
+ t.belongs_to :user, polymorphic: true
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :worker_plugins_workplaces, :user_id
11
+ add_index :worker_plugins_workplaces, :active
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ class CreateWorkerPluginsWorkplaceLinks < ActiveRecord::Migration
2
+ def change
3
+ create_table :worker_plugins_workplace_links do |t|
4
+ t.belongs_to :workplace
5
+ t.belongs_to :resource, polymorphic: true
6
+ t.text :custom_data
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :worker_plugins_workplace_links, :workplace_id
11
+ add_index :worker_plugins_workplace_links, [:workplace_id, :resource_type, :resource_id], unique: true, name: 'unique_resource_on_workspace'
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :worker_plugins do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,15 @@
1
+ module WorkerPlugins
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace WorkerPlugins
4
+
5
+ # Add translations to load path.
6
+ path = File.realpath(File.join(File.dirname(__FILE__), '..', '..', 'config', 'locales'))
7
+ I18n.load_path += Dir[File.join(path, '**', '*.{rb,yml}')]
8
+
9
+ initializer :append_migrations do |app|
10
+ unless app.root.to_s.match root.to_s
11
+ app.config.paths['db/migrate'] += config.paths['db/migrate'].expanded
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module WorkerPlugins
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'worker_plugins/engine'
2
+
3
+ module WorkerPlugins
4
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: worker_plugins
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kasper Johanmsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.21
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
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
+ - !ruby/object:Gem::Dependency
42
+ name: active-record-transactioner
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
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-rails
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: factory_girl_rails
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
+ - !ruby/object:Gem::Dependency
98
+ name: awesome_translations
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Rails framework for easily choosing and creating lists of objects and
112
+ execute plugins against them.
113
+ email:
114
+ - k@spernj.org
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - MIT-LICENSE
120
+ - README.md
121
+ - Rakefile
122
+ - app/models/worker_plugins/workplace.rb
123
+ - app/models/worker_plugins/workplace_link.rb
124
+ - config/locales/awesome_translations/models/worker_plugins__workplace/da.yml
125
+ - config/locales/awesome_translations/models/worker_plugins__workplace/en.yml
126
+ - config/locales/awesome_translations/models/worker_plugins__workplace_link/da.yml
127
+ - config/locales/awesome_translations/models/worker_plugins__workplace_link/en.yml
128
+ - config/routes.rb
129
+ - db/migrate/20150521114555_create_worker_plugins_workplaces.rb
130
+ - db/migrate/20150521114659_create_worker_plugins_workplace_links.rb
131
+ - lib/tasks/worker_plugins_tasks.rake
132
+ - lib/worker_plugins.rb
133
+ - lib/worker_plugins/engine.rb
134
+ - lib/worker_plugins/version.rb
135
+ homepage: https://www.github.com/kaspernj/worker_plugins
136
+ licenses: []
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.4.0
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Rails framework for easily choosing and creating lists of objects and execute
158
+ plugins against them.
159
+ test_files: []