controller_commands 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/controller_commands/command.rb +15 -1
- data/lib/controller_commands/concern.rb +7 -3
- data/lib/controller_commands/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b572a0cf6772f76c3039b9893c074167dc3f59db
|
4
|
+
data.tar.gz: 3198a8fc029d7e03d5aee2c93858a84d6270b152
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df631afa94ad29311361df8a3ea246c47d0500a954aaf899fc3ed0d7eed9fa77ebb0ea7875fe884414950e13fa11ebb8a2b6ff1655e00a3cca73f31100f647b4
|
7
|
+
data.tar.gz: c1f963bfcf98838ac4a309d52d31a5455d6704bc3cec1ba63fc055181f99fe5ce6bcadf6c0580d1939b992c8ca6d904b431a0e6b8eefd3e0f87553fec894dae1
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
controller_commands (0.1.
|
4
|
+
controller_commands (0.1.2)
|
5
5
|
dry-validation (~> 0.11)
|
6
6
|
hash_key_transformer (~> 0.1)
|
7
7
|
rails (>= 4.2)
|
@@ -49,7 +49,7 @@ GEM
|
|
49
49
|
arel (8.0.0)
|
50
50
|
builder (3.2.3)
|
51
51
|
concurrent-ruby (1.0.5)
|
52
|
-
crass (1.0.
|
52
|
+
crass (1.0.4)
|
53
53
|
dry-configurable (0.7.0)
|
54
54
|
concurrent-ruby (~> 1.0)
|
55
55
|
dry-container (0.6.0)
|
@@ -29,6 +29,16 @@ module ControllerCommands
|
|
29
29
|
def perform(context, validated_params)
|
30
30
|
@perform_block.call(context, validated_params)
|
31
31
|
end
|
32
|
+
|
33
|
+
def before_success_render(&block)
|
34
|
+
@before_render_success_block = block
|
35
|
+
end
|
36
|
+
|
37
|
+
def execute_before_success_render(context, output)
|
38
|
+
@before_render_success_block ?
|
39
|
+
@before_render_success_block.call(context, output) :
|
40
|
+
output
|
41
|
+
end
|
32
42
|
end
|
33
43
|
|
34
44
|
def self.included(base)
|
@@ -65,5 +75,9 @@ module ControllerCommands
|
|
65
75
|
self.class.perform(@context, validated_params)
|
66
76
|
end
|
67
77
|
|
78
|
+
def render_success(output)
|
79
|
+
self.class.execute_before_success_render(@context, output)
|
80
|
+
end
|
81
|
+
|
68
82
|
end
|
69
|
-
end
|
83
|
+
end
|
@@ -17,8 +17,11 @@ module ControllerCommands
|
|
17
17
|
is_command_valid = command.validate_params
|
18
18
|
result =
|
19
19
|
if is_command_valid
|
20
|
-
flash
|
21
|
-
|
20
|
+
if respond_to?(:flash)
|
21
|
+
flash[:notice] = command.success_message
|
22
|
+
end
|
23
|
+
output = {data: command.perform}
|
24
|
+
command.render_success(output)
|
22
25
|
else
|
23
26
|
{errors: command.errors}
|
24
27
|
end
|
@@ -38,7 +41,8 @@ module ControllerCommands
|
|
38
41
|
# The default JSON parsing in Rails replaces empty arrays with nil as a part of their solution to the CVE above.
|
39
42
|
# This is the reason we are manually parsing the JSON request body. Consistent use of dry-validation schema types
|
40
43
|
# should protect us from this CVE and also provide the same protection as Rails strong parameters.
|
41
|
-
|
44
|
+
body = request.body.read
|
45
|
+
parsed_params = (body.present? ? JSON.parse(body) : {})
|
42
46
|
HashKeyTransformer.send(key_transformer_strategy, parsed_params)
|
43
47
|
end
|
44
48
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: controller_commands
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Rood
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|