bulk_routing 0.1.0
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +55 -0
- data/Rakefile +17 -0
- data/lib/bulk_routing.rb +75 -0
- data/lib/bulk_routing.rb~ +73 -0
- data/lib/bulk_routing/railtie.rb~ +4 -0
- data/lib/bulk_routing/version.rb +3 -0
- data/lib/bulk_routing/version.rb~ +3 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 33608276d02ad4737d80f8164966568b4b56cc60
|
4
|
+
data.tar.gz: 566149ba459ec07e54bab5afdcec6992c99b785f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 606afe627536b08bf4242dad4a63ed7b119e607ef41c55f27c123a1a96f9a3bfd3d2fca0d539746d033bdbf0fe6750eef49609387e73eb1fe57e4b21cc886616
|
7
|
+
data.tar.gz: b0434600dc944a3b87628903cd35c14ba27a8474e544465e0a333f019f0dd53f0a650d271c08a449ad354d61b0c717ba5eae2ab6866abc6fb270339f2c309651
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018
|
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,55 @@
|
|
1
|
+
# BulkRouting
|
2
|
+
add bulk_create, bulk_update, bulk_destroy to Rails routes
|
3
|
+
|
4
|
+
[](https://travis-ci.org/booink/rails-bulk_routing)
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'bulk_routing'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
```bash
|
15
|
+
$ bundle
|
16
|
+
```
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
```bash
|
20
|
+
$ gem install bulk_routing
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
Example
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# config/routes.rb
|
28
|
+
|
29
|
+
Rails.application.routes.draw do
|
30
|
+
resources :articles, bulk: [:create, :update, :destroy]
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
and, show `rails routes`
|
35
|
+
|
36
|
+
```
|
37
|
+
Prefix Verb URI Pattern Controller#Action
|
38
|
+
bulk_create_articles POST /articles/bulk(.:format) articles#bulk_create
|
39
|
+
bulk_update_articles PUT /articles/bulk(.:format) articles#bulk_update
|
40
|
+
bulk_destroy_articles DELETE /articles/bulk(.:format) articles#bulk_destroy
|
41
|
+
articles GET /articles(.:format) articles#index
|
42
|
+
POST /articles(.:format) articles#create
|
43
|
+
new_article GET /articles/new(.:format) articles#new
|
44
|
+
edit_article GET /articles/:id/edit(.:format) articles#edit
|
45
|
+
article GET /articles/:id(.:format) articles#show
|
46
|
+
PATCH /articles/:id(.:format) articles#update
|
47
|
+
PUT /articles/:id(.:format) articles#update
|
48
|
+
DELETE /articles/:id(.:format) articles#destroy
|
49
|
+
```
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/booink/rails-bulk_routing
|
53
|
+
|
54
|
+
## License
|
55
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'BulkRouting'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
data/lib/bulk_routing.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# When you use BulkRouting, bulk_* routes becomes possible.
|
2
|
+
module BulkRouting
|
3
|
+
# patch to ActionDispatch::Routing::Mapper
|
4
|
+
module Resources
|
5
|
+
# patch to ActionDispatch::Routing::Mapper::Resources::Resource
|
6
|
+
module Resource
|
7
|
+
def initialize(entities, api_only, shallow, options = {})
|
8
|
+
super
|
9
|
+
@bulk = options[:bulk] || []
|
10
|
+
end
|
11
|
+
|
12
|
+
def actions
|
13
|
+
actions = super
|
14
|
+
actions += bulk_actions if @bulk
|
15
|
+
actions
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def bulk_actions
|
21
|
+
Array(@bulk).map do |action|
|
22
|
+
"bulk_#{action}".to_sym
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
BULK_ACTIONS = %w[bulk_create bulk_update bulk_destroy].freeze
|
28
|
+
|
29
|
+
def resources(*resources, &block)
|
30
|
+
super do
|
31
|
+
yield if block_given?
|
32
|
+
|
33
|
+
actions = parent_resource.actions
|
34
|
+
collection do
|
35
|
+
post :bulk_create if actions.include?(:bulk_create)
|
36
|
+
put :bulk_update if actions.include?(:bulk_update)
|
37
|
+
delete :bulk_destroy if actions.include?(:bulk_destroy)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def bulk_action?(action)
|
45
|
+
resource_method_scope? && BULK_ACTIONS.include?(action.to_s)
|
46
|
+
end
|
47
|
+
|
48
|
+
def path_for_action(action, path)
|
49
|
+
if bulk_action?(action)
|
50
|
+
"#{@scope[:path]}/bulk"
|
51
|
+
else
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# rubocop:disable Style/Documentation
|
59
|
+
module ActionDispatch
|
60
|
+
module Routing
|
61
|
+
class Mapper
|
62
|
+
prepend BulkRouting::Resources
|
63
|
+
module Resources
|
64
|
+
remove_const(:RESOURCE_OPTIONS)
|
65
|
+
RESOURCE_OPTIONS = %i[as controller path only
|
66
|
+
except param concerns bulk].freeze
|
67
|
+
|
68
|
+
class Resource
|
69
|
+
prepend BulkRouting::Resources::Resource
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
# rubocop:enable Style/Documentation
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# blah
|
2
|
+
module BulkRouting
|
3
|
+
module Resources
|
4
|
+
module Resource
|
5
|
+
def initialize(entities, api_only, shallow, options = {})
|
6
|
+
super
|
7
|
+
@bulk = options[:bulk] || []
|
8
|
+
end
|
9
|
+
|
10
|
+
def actions
|
11
|
+
actions = super
|
12
|
+
actions += bulk_actions if @bulk
|
13
|
+
actions
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def bulk_actions
|
19
|
+
Array(@bulk).map do |action|
|
20
|
+
"bulk_#{action}".to_sym
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
BULK_ACTIONS = %w[bulk_create bulk_update bulk_destroy].freeze
|
26
|
+
|
27
|
+
def resources(*resources, &block)
|
28
|
+
super do
|
29
|
+
yield if block_given?
|
30
|
+
|
31
|
+
actions = parent_resource.actions
|
32
|
+
collection do
|
33
|
+
post :bulk_create if actions.include?(:bulk_create)
|
34
|
+
put :bulk_update if actions.include?(:bulk_update)
|
35
|
+
delete :bulk_destroy if actions.include?(:bulk_destroy)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def bulk_action?(action)
|
43
|
+
resource_method_scope? && BULK_ACTIONS.include?(action.to_s)
|
44
|
+
end
|
45
|
+
|
46
|
+
def path_for_action(action, path)
|
47
|
+
if bulk_action?(action)
|
48
|
+
"#{@scope[:path]}/bulk"
|
49
|
+
else
|
50
|
+
super
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# rubocop:disable Style/Documentation
|
57
|
+
module ActionDispatch
|
58
|
+
module Routing
|
59
|
+
class Mapper
|
60
|
+
prepend BulkRouting::Resources
|
61
|
+
module Resources
|
62
|
+
remove_const(:RESOURCE_OPTIONS)
|
63
|
+
RESOURCE_OPTIONS = %i[as controller path only
|
64
|
+
except param concerns bulk].freeze
|
65
|
+
|
66
|
+
class Resource
|
67
|
+
prepend BulkRouting::Resources::Resource
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
# rubocop:enable Style/Documentation
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bulk_routing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- booink
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-13 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: 5.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: bulk processing routing for Rails
|
56
|
+
email:
|
57
|
+
- booink.work@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- lib/bulk_routing.rb
|
66
|
+
- lib/bulk_routing.rb~
|
67
|
+
- lib/bulk_routing/railtie.rb~
|
68
|
+
- lib/bulk_routing/version.rb
|
69
|
+
- lib/bulk_routing/version.rb~
|
70
|
+
homepage: https://github.com/booink/rails-bulk_routing
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.6.11
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: bulk processing routing for Rails
|
94
|
+
test_files: []
|