rails-add_ons 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/concerns/resources_controller/kaminari.rb +15 -0
- data/app/concerns/service_controller/rest_actions.rb +72 -0
- data/app/concerns/service_controller/rest_service_urls.rb +25 -0
- data/app/concerns/service_controller/service.rb +11 -0
- data/app/concerns/service_controller/service_inflections.rb +15 -0
- data/app/controllers/api/resources_controller/base.rb +5 -3
- data/app/helpers/rails/add_ons/table_helper.rb +2 -2
- data/lib/rails/add_ons/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e074f79fe60106ad1f033af4e541a57c3408043
|
4
|
+
data.tar.gz: 34397cc5eecf03f97f98f2f7a91b283f2518f63f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 605848c5d9f91c7ee298c810300436ff487b82d4b5bbf5cd59ff0bc1f0a6abfa4ee3e6a82d396d87f0f3ec79255c5ca4363fa078e51775f659d2b0c68dc5b9f3
|
7
|
+
data.tar.gz: 654ae257f587810df2202ba8f403b497e8038cfbfb32b0eb52140c342b6e4b530fb94cefe5aa8ab48ca3248df5364695299c465aaee7b12ae02a4c54f48bb9a8
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module ServiceController::RestActions
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
respond_to :html
|
6
|
+
responders :flash
|
7
|
+
|
8
|
+
if respond_to?(:before_action)
|
9
|
+
before_action :initialize_service_for_invoke, only: [:invoke]
|
10
|
+
before_action :initialize_service_for_call, only: [:call]
|
11
|
+
else
|
12
|
+
before_filter :initialize_service_for_invoke, only: [:invoke]
|
13
|
+
before_filter :initialize_service_for_call, only: [:call]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def index
|
18
|
+
end
|
19
|
+
|
20
|
+
def invoke
|
21
|
+
respond_with @service
|
22
|
+
end
|
23
|
+
|
24
|
+
def call
|
25
|
+
@result = execute_service
|
26
|
+
if @result.success?
|
27
|
+
|
28
|
+
if respond_to?(:after_success_location)
|
29
|
+
redirect_to(after_success_location, notice: success_message)
|
30
|
+
else
|
31
|
+
flash.now[:success] = success_message
|
32
|
+
render :success
|
33
|
+
end
|
34
|
+
else
|
35
|
+
render :invoke
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def success_message
|
42
|
+
t('flash.actions.perform.notice', resource_name: @resource.class.model_name.human)
|
43
|
+
end
|
44
|
+
|
45
|
+
def execute_service
|
46
|
+
@service.send(execute_method)
|
47
|
+
end
|
48
|
+
|
49
|
+
def execute_method
|
50
|
+
:perform
|
51
|
+
end
|
52
|
+
|
53
|
+
def hashified_params
|
54
|
+
if permitted_params.respond_to?(:to_h)
|
55
|
+
permitted_params.to_h
|
56
|
+
else
|
57
|
+
permitted_params
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def initialize_service_for_invoke
|
62
|
+
service_class.new
|
63
|
+
end
|
64
|
+
|
65
|
+
def initialize_service_for_call
|
66
|
+
service_class.new(hashified_params)
|
67
|
+
end
|
68
|
+
|
69
|
+
def permitted_params
|
70
|
+
raise "Not implemented"
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ServiceController::RestServiceUrls
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
helper_method :collection_path,
|
6
|
+
:call_service_path,
|
7
|
+
:invoke_service_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def collection_path
|
11
|
+
resource_router.send(:url_for, { action: :index, only_path: true })
|
12
|
+
end
|
13
|
+
|
14
|
+
def invoke_service_path
|
15
|
+
resource_router.send(:url_for, { action: :invoke, only_path: true })
|
16
|
+
end
|
17
|
+
|
18
|
+
def call_service_path
|
19
|
+
resource_router.send(:url_for, { action: :call, only_path: true })
|
20
|
+
end
|
21
|
+
|
22
|
+
def resource_router
|
23
|
+
self
|
24
|
+
end
|
25
|
+
end
|
@@ -119,6 +119,10 @@ module Api
|
|
119
119
|
scope = scope.order(condition)
|
120
120
|
when 'includes'
|
121
121
|
scope = scope.includes(condition.map(&:to_sym))
|
122
|
+
when 'scopes'
|
123
|
+
condition.each do |scope_name|
|
124
|
+
scope = scope.send(scope_name.to_sym)
|
125
|
+
end
|
122
126
|
else
|
123
127
|
condition_statement = ::Api::ResourcesController::ConditionParser.new(scope, field, condition).condition_statement
|
124
128
|
scope = scope.where(condition_statement)
|
@@ -153,9 +157,7 @@ module Api
|
|
153
157
|
|
154
158
|
def serialize_collection(collection)
|
155
159
|
collection.collect do |resource|
|
156
|
-
|
157
|
-
json[:errors] = serialize_errors(resource.errors) if resource.errors.any?
|
158
|
-
json
|
160
|
+
serialize_resource(resource)
|
159
161
|
end
|
160
162
|
end
|
161
163
|
|
@@ -25,7 +25,7 @@ module Rails
|
|
25
25
|
end
|
26
26
|
|
27
27
|
@view_context = view_context
|
28
|
-
@column_name = column_name
|
28
|
+
@column_name = @options[:column_name] || column_name
|
29
29
|
@title = title
|
30
30
|
|
31
31
|
if h.params[:sort_direction].present?
|
@@ -47,4 +47,4 @@ module Rails
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
|
-
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-add_ons
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Vasquez Angel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01
|
11
|
+
date: 2018-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- app/components/component/resource_table.rb
|
192
192
|
- app/concerns/api_controller_concerns/exception_handling.rb
|
193
193
|
- app/concerns/controller/query_conditions.rb
|
194
|
+
- app/concerns/resources_controller/kaminari.rb
|
194
195
|
- app/concerns/resources_controller/location_history.rb
|
195
196
|
- app/concerns/resources_controller/pagination.rb
|
196
197
|
- app/concerns/resources_controller/resource_inflections.rb
|
@@ -199,6 +200,10 @@ files:
|
|
199
200
|
- app/concerns/resources_controller/rest_resource_urls.rb
|
200
201
|
- app/concerns/resources_controller/sorting.rb
|
201
202
|
- app/concerns/resources_controller/will_paginate.rb
|
203
|
+
- app/concerns/service_controller/rest_actions.rb
|
204
|
+
- app/concerns/service_controller/rest_service_urls.rb
|
205
|
+
- app/concerns/service_controller/service.rb
|
206
|
+
- app/concerns/service_controller/service_inflections.rb
|
202
207
|
- app/controllers/api/resources_controller/base.rb
|
203
208
|
- app/controllers/api/service_controller/base.rb
|
204
209
|
- app/controllers/rails/add_ons/widgets_controller.rb
|