snfoil-rails 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 +28 -0
- data/Rakefile +29 -0
- data/lib/sn_foil/rails.rb +11 -0
- data/lib/sn_foil/rails/controller/api.rb +22 -0
- data/lib/sn_foil/rails/controller/concerns/change_controller_concern.rb +28 -0
- data/lib/sn_foil/rails/controller/concerns/create_controller_concern.rb +40 -0
- data/lib/sn_foil/rails/controller/concerns/destroy_controller_concern.rb +42 -0
- data/lib/sn_foil/rails/controller/concerns/index_controller_concern.rb +72 -0
- data/lib/sn_foil/rails/controller/concerns/setup_controller_concern.rb +110 -0
- data/lib/sn_foil/rails/controller/concerns/show_controller_concern.rb +38 -0
- data/lib/sn_foil/rails/controller/concerns/update_controller_concern.rb +40 -0
- data/lib/sn_foil/rails/railtie.rb +10 -0
- data/lib/sn_foil/rails/searcher.rb +127 -0
- data/lib/sn_foil/rails/version.rb +7 -0
- data/lib/tasks/sn_foil/rails_tasks.rake +5 -0
- metadata +199 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 95946ad8c9da4c8cf3498f8394145465131694074e3aef1b7f3849ae334b9358
|
4
|
+
data.tar.gz: 817e82e8f00557815290a724aa27f69a2c7d01e2c3f28ac5b66e0bd9834b51ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 53d257a20b1cc16a9a8d7c54ec62f6c15cfc0b9bf377edc2d86c206af79331078746e9ea0e266103aff15407eaecdad56887c9c72dd790db4142d339f2effccb
|
7
|
+
data.tar.gz: 5863066aa0bb468aef6796d8336e69fda0b207b5b161999ebd86fa3ff2d2ece2500a4a868b0d1fbb83a2509ad486f1b958e29861dfaf99441c23bb7b95922596
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2019 Matthew Howes
|
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,28 @@
|
|
1
|
+
# Sn::Foil::Rails
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'sn-foil-rails'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install sn-foil-rails
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
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,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rdoc/task'
|
10
|
+
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.rdoc_dir = 'rdoc'
|
13
|
+
rdoc.title = 'Sn::Foil::Rails'
|
14
|
+
rdoc.options << '--line-numbers'
|
15
|
+
rdoc.rdoc_files.include('README.md')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'bundler/gem_tasks'
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
|
23
|
+
Rake::TestTask.new(:test) do |t|
|
24
|
+
t.libs << 'test'
|
25
|
+
t.pattern = 'test/**/*_test.rb'
|
26
|
+
t.verbose = false
|
27
|
+
end
|
28
|
+
|
29
|
+
task default: :test
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'action_controller/api'
|
4
|
+
require_relative 'concerns/create_controller_concern'
|
5
|
+
require_relative 'concerns/destroy_controller_concern'
|
6
|
+
require_relative 'concerns/index_controller_concern'
|
7
|
+
require_relative 'concerns/show_controller_concern'
|
8
|
+
require_relative 'concerns/update_controller_concern'
|
9
|
+
|
10
|
+
module SnFoil
|
11
|
+
module Rails
|
12
|
+
module Controller
|
13
|
+
class API < ::ActionController::API
|
14
|
+
include Concerns::CreateControllerConcern
|
15
|
+
include Concerns::DestroyControllerConcern
|
16
|
+
include Concerns::IndexControllerConcern
|
17
|
+
include Concerns::ShowControllerConcern
|
18
|
+
include Concerns::UpdateControllerConcern
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require_relative 'setup_controller_concern'
|
5
|
+
|
6
|
+
module SnFoil
|
7
|
+
module Rails
|
8
|
+
module Controller
|
9
|
+
module Concerns
|
10
|
+
module ChangeControllerConcern
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
include SetupControllerConcern
|
15
|
+
end
|
16
|
+
|
17
|
+
def render_change(model, **_options)
|
18
|
+
if model.errors.empty?
|
19
|
+
render model
|
20
|
+
else
|
21
|
+
render model.errors, status: :unprocessable_entity
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require_relative 'setup_controller_concern'
|
5
|
+
require_relative 'change_controller_concern'
|
6
|
+
|
7
|
+
module SnFoil
|
8
|
+
module Rails
|
9
|
+
module Controller
|
10
|
+
module Concerns
|
11
|
+
module CreateControllerConcern
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
included do
|
15
|
+
include SetupControllerConcern
|
16
|
+
include ChangeControllerConcern
|
17
|
+
end
|
18
|
+
|
19
|
+
def create(**options)
|
20
|
+
options = setup_create(**options)
|
21
|
+
model = process_create(**options)
|
22
|
+
render_create(model, **options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup_create(**options)
|
26
|
+
setup_options(**options.merge(deserialize: true))
|
27
|
+
end
|
28
|
+
|
29
|
+
def process_create(**options)
|
30
|
+
current_context(**options).create(**options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def render_create(model, **options)
|
34
|
+
render_change(model, **options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require_relative 'setup_controller_concern'
|
5
|
+
|
6
|
+
module SnFoil
|
7
|
+
module Rails
|
8
|
+
module Controller
|
9
|
+
module Concerns
|
10
|
+
module DestroyControllerConcern
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
include SetupControllerConcern
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy(**options)
|
18
|
+
options = setup_update(**options)
|
19
|
+
model = process_destroy(**options)
|
20
|
+
render_destroy(model, **options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_destroy(**options)
|
24
|
+
setup_options(**options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def process_destroy(**options)
|
28
|
+
current_context(**options).destroy(**options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def render_destroy(model, **_options)
|
32
|
+
if model.errors.empty?
|
33
|
+
render nil
|
34
|
+
else
|
35
|
+
render model.errors, status: :unprocessable_entity
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require_relative 'setup_controller_concern'
|
5
|
+
|
6
|
+
module SnFoil
|
7
|
+
module Rails
|
8
|
+
module Controller
|
9
|
+
module Concerns
|
10
|
+
module IndexControllerConcern
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
include SetupControllerConcern
|
15
|
+
end
|
16
|
+
|
17
|
+
def index(**options)
|
18
|
+
options = setup_index(**options)
|
19
|
+
results = process_index(**options)
|
20
|
+
render_index(results, **options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_index(**options)
|
24
|
+
setup_options(**options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def process_index(**options)
|
28
|
+
searcher = options.fetch(:searcher) do
|
29
|
+
current_context(**options).index(options)
|
30
|
+
end
|
31
|
+
searcher.results
|
32
|
+
end
|
33
|
+
|
34
|
+
def render_index(results, **options)
|
35
|
+
paginate(results, **options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def paginate(results, **options)
|
39
|
+
return results unless results.respond_to?(:page)
|
40
|
+
|
41
|
+
results.page(page(**options))
|
42
|
+
.per(per_page(**options))
|
43
|
+
end
|
44
|
+
|
45
|
+
def page(**options)
|
46
|
+
options[:params].fetch(:page, 1).to_i
|
47
|
+
end
|
48
|
+
|
49
|
+
def per_page(**options)
|
50
|
+
per_page_param = options[:params].fetch(:per_page, 10).to_i
|
51
|
+
return 10_000 if per_page_param.zero?
|
52
|
+
|
53
|
+
per_page_param
|
54
|
+
end
|
55
|
+
|
56
|
+
def meta(results, **options)
|
57
|
+
total_pages = results&.total_pages
|
58
|
+
total_count = results&.total_count
|
59
|
+
paginated = total_pages && total_count
|
60
|
+
|
61
|
+
{
|
62
|
+
page: paginated ? page(**options) : nil,
|
63
|
+
pages: total_pages || 1,
|
64
|
+
total: total_count || 1,
|
65
|
+
per: paginated ? per_page(**options) : nil
|
66
|
+
}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
|
5
|
+
module SnFoil
|
6
|
+
module Rails
|
7
|
+
module Controller
|
8
|
+
module Concerns
|
9
|
+
module SetupControllerConcern
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
class_methods do
|
13
|
+
attr_reader :i_deserializer, :i_serializer, :i_context
|
14
|
+
|
15
|
+
def context(klass = nil)
|
16
|
+
@i_context = klass
|
17
|
+
end
|
18
|
+
|
19
|
+
def serializer(klass = nil)
|
20
|
+
@i_serializer = klass
|
21
|
+
end
|
22
|
+
|
23
|
+
def deserializer(klass = nil)
|
24
|
+
@i_deserializer = klass
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def context(**options)
|
29
|
+
options[:context] || self.class.i_context
|
30
|
+
end
|
31
|
+
|
32
|
+
def serializer(**options)
|
33
|
+
options[:serializer] || self.class.i_serializer
|
34
|
+
end
|
35
|
+
|
36
|
+
def deserializer(**options)
|
37
|
+
options[:deserializer] || self.class.i_deserializer
|
38
|
+
end
|
39
|
+
|
40
|
+
def setup_options(**options)
|
41
|
+
options = inject_params(**options)
|
42
|
+
options = inject_id(**options)
|
43
|
+
options = inject_includes(**options)
|
44
|
+
options = inject_controller_action(**options)
|
45
|
+
inject_deserialized_params(**options)
|
46
|
+
end
|
47
|
+
|
48
|
+
def current_context(**options)
|
49
|
+
@current_context ||= context(**options).new(context_user)
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
def pundit_not_authorized
|
55
|
+
head :forbidden
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# Grab the rails params and inject them into the options
|
61
|
+
def inject_params(**options)
|
62
|
+
return options unless params
|
63
|
+
|
64
|
+
options[:params] = params.to_unsafe_h.deep_symbolize_keys
|
65
|
+
options[:controller_params] = options[:params]
|
66
|
+
options
|
67
|
+
end
|
68
|
+
|
69
|
+
def inject_id(**options)
|
70
|
+
return options if options[:id]
|
71
|
+
|
72
|
+
options[:id] = id if defined? id
|
73
|
+
options[:id] ||= options[:params][:id]
|
74
|
+
options
|
75
|
+
end
|
76
|
+
|
77
|
+
def inject_includes(**options)
|
78
|
+
return options if options[:include]
|
79
|
+
return options unless options.dig(:params, :include)
|
80
|
+
|
81
|
+
options[:include] = options.dig(:params, :include)
|
82
|
+
.split(',')
|
83
|
+
.map { |item| item.underscore.to_sym }
|
84
|
+
options
|
85
|
+
end
|
86
|
+
|
87
|
+
def inject_controller_action(**options)
|
88
|
+
return options if options[:controller_action]
|
89
|
+
return options unless options.dig(:params, :action)
|
90
|
+
|
91
|
+
options[:controller_action] = options[:params][:action]
|
92
|
+
options
|
93
|
+
end
|
94
|
+
|
95
|
+
def inject_deserialized_params(**options)
|
96
|
+
return options unless options[:params].present? && options[:deserialize] == true
|
97
|
+
return options unless deserializer(**options)
|
98
|
+
|
99
|
+
options[:params] = deserializer(**options).new(options[:params], **options).to_h
|
100
|
+
options
|
101
|
+
end
|
102
|
+
|
103
|
+
def context_user
|
104
|
+
return current_user if defined? current_user
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require_relative 'setup_controller_concern'
|
5
|
+
|
6
|
+
module SnFoil
|
7
|
+
module Rails
|
8
|
+
module Controller
|
9
|
+
module Concerns
|
10
|
+
module ShowControllerConcern
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
include SetupControllerConcern
|
15
|
+
end
|
16
|
+
|
17
|
+
def show(**options)
|
18
|
+
options = setup_show(**options)
|
19
|
+
model = process_show(**options)
|
20
|
+
render_show(model, **options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def setup_show(**options)
|
24
|
+
setup_options(**options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def process_show(**options)
|
28
|
+
current_context(**options).show(**options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def render_show(model, **_options)
|
32
|
+
render model
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require_relative 'setup_controller_concern'
|
5
|
+
require_relative 'change_controller_concern'
|
6
|
+
|
7
|
+
module SnFoil
|
8
|
+
module Rails
|
9
|
+
module Controller
|
10
|
+
module Concerns
|
11
|
+
module UpdateControllerConcern
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
included do
|
15
|
+
include SetupControllerConcern
|
16
|
+
include ChangeControllerConcern
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(**options)
|
20
|
+
options = setup_update(**options)
|
21
|
+
model = process_update(**options)
|
22
|
+
render_update(model, **options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup_update(**options)
|
26
|
+
setup_options(**options.merge(deserialize: true))
|
27
|
+
end
|
28
|
+
|
29
|
+
def process_update(**options)
|
30
|
+
current_context(**options).update(**options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def render_update(model, **options)
|
34
|
+
render_change(model, **options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'sn_foil/searcher'
|
5
|
+
|
6
|
+
module SnFoil
|
7
|
+
module Rails
|
8
|
+
module Searcher
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
include SnFoil::Searcher
|
13
|
+
|
14
|
+
module_eval do
|
15
|
+
alias_method :base_search, :search
|
16
|
+
|
17
|
+
# patch the additional search capabilities into the method
|
18
|
+
def search(params = {})
|
19
|
+
filtered_scope = base_search(params)
|
20
|
+
additional_search(filtered_scope, params)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
ASC ||= 'ASC'
|
25
|
+
DESC ||= 'DESC'
|
26
|
+
end
|
27
|
+
|
28
|
+
class_methods do
|
29
|
+
attr_reader :i_include_params, :i_order_method, :i_order_block, :i_order_by_attr, :i_order_by_direction, :i_is_distinct
|
30
|
+
|
31
|
+
def order(method = nil, &block)
|
32
|
+
@i_order_method = method
|
33
|
+
@i_order_block = block
|
34
|
+
end
|
35
|
+
|
36
|
+
def order_by(attr, direction = nil)
|
37
|
+
@i_order_by_attr = attr
|
38
|
+
@i_order_by_direction = direction
|
39
|
+
end
|
40
|
+
|
41
|
+
def distinct(bool = true)
|
42
|
+
@i_is_distinct = bool
|
43
|
+
end
|
44
|
+
|
45
|
+
def includes(*array)
|
46
|
+
@i_include_params ||= [] # create new array if none exists
|
47
|
+
@i_include_params |= array # combine unique elements of both arrays
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def distinct?
|
52
|
+
self.class.i_is_distinct || false
|
53
|
+
end
|
54
|
+
|
55
|
+
def included_params
|
56
|
+
self.class.i_include_params
|
57
|
+
end
|
58
|
+
|
59
|
+
def order_by(params = {})
|
60
|
+
if params[:order_by].present?
|
61
|
+
params[:order_by] = params[:order_by].to_s.underscore
|
62
|
+
return params[:order_by].to_sym if model.attribute_names.include?(params[:order_by])
|
63
|
+
end
|
64
|
+
|
65
|
+
self.class.i_order_by_attr || :id
|
66
|
+
end
|
67
|
+
|
68
|
+
def order(params = {})
|
69
|
+
if params[:order].present?
|
70
|
+
params[:order] = params[:order].to_s.upcase
|
71
|
+
return params[:order] if params[:order].eql?(ASC) || params[:order].eql?(DESC)
|
72
|
+
end
|
73
|
+
|
74
|
+
self.class.i_order_by_direction || ASC
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def additional_search(filtered_scope, params = {})
|
80
|
+
filtered_scope = apply_order(filtered_scope, params)
|
81
|
+
filtered_scope = apply_includes(filtered_scope)
|
82
|
+
apply_distinct(filtered_scope, params)
|
83
|
+
end
|
84
|
+
|
85
|
+
def apply_includes(filtered_scope)
|
86
|
+
return filtered_scope unless included_params
|
87
|
+
|
88
|
+
filtered_scope.includes(*included_params)
|
89
|
+
end
|
90
|
+
|
91
|
+
def apply_order(filtered_scope, params)
|
92
|
+
return apply_default_order(filtered_scope, params) if params[:order_by].blank? && params[:order].blank?
|
93
|
+
|
94
|
+
filtered_scope.order(order_by(params) => order(params))
|
95
|
+
end
|
96
|
+
|
97
|
+
def apply_default_order(filtered_scope, params)
|
98
|
+
return order_method(filtered_scope, params) if order_method?
|
99
|
+
return order_block(filtered_scope, params) if order_block?
|
100
|
+
|
101
|
+
filtered_scope.order(order_by => order)
|
102
|
+
end
|
103
|
+
|
104
|
+
def order_method(filtered_scope, params)
|
105
|
+
send(self.class.i_order_method, filtered_scope, params)
|
106
|
+
end
|
107
|
+
|
108
|
+
def order_method?
|
109
|
+
self.class.i_order_method.present?
|
110
|
+
end
|
111
|
+
|
112
|
+
def order_block(filtered_scope, params)
|
113
|
+
self.class.i_order_block.call(filtered_scope, params)
|
114
|
+
end
|
115
|
+
|
116
|
+
def order_block?
|
117
|
+
self.class.i_order_block.present?
|
118
|
+
end
|
119
|
+
|
120
|
+
def apply_distinct(filtered_scope, params)
|
121
|
+
return filtered_scope unless distinct? || params[:distinct] == true
|
122
|
+
|
123
|
+
filtered_scope.distinct
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
metadata
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: snfoil-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Howes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.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.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.1.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.1.7
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '13.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '13.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.9'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.9'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.76.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.76.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.36.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.36.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: sqlite3
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description:
|
154
|
+
email:
|
155
|
+
- howeszy@gmail.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- MIT-LICENSE
|
161
|
+
- README.md
|
162
|
+
- Rakefile
|
163
|
+
- lib/sn_foil/rails.rb
|
164
|
+
- lib/sn_foil/rails/controller/api.rb
|
165
|
+
- lib/sn_foil/rails/controller/concerns/change_controller_concern.rb
|
166
|
+
- lib/sn_foil/rails/controller/concerns/create_controller_concern.rb
|
167
|
+
- lib/sn_foil/rails/controller/concerns/destroy_controller_concern.rb
|
168
|
+
- lib/sn_foil/rails/controller/concerns/index_controller_concern.rb
|
169
|
+
- lib/sn_foil/rails/controller/concerns/setup_controller_concern.rb
|
170
|
+
- lib/sn_foil/rails/controller/concerns/show_controller_concern.rb
|
171
|
+
- lib/sn_foil/rails/controller/concerns/update_controller_concern.rb
|
172
|
+
- lib/sn_foil/rails/railtie.rb
|
173
|
+
- lib/sn_foil/rails/searcher.rb
|
174
|
+
- lib/sn_foil/rails/version.rb
|
175
|
+
- lib/tasks/sn_foil/rails_tasks.rake
|
176
|
+
homepage: https://github.com/howeszy/snfoil-rails
|
177
|
+
licenses:
|
178
|
+
- MIT
|
179
|
+
metadata: {}
|
180
|
+
post_install_message:
|
181
|
+
rdoc_options: []
|
182
|
+
require_paths:
|
183
|
+
- lib
|
184
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
requirements: []
|
195
|
+
rubygems_version: 3.0.3
|
196
|
+
signing_key:
|
197
|
+
specification_version: 4
|
198
|
+
summary: Additional functionality gem for using SnFoil with Rails
|
199
|
+
test_files: []
|