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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36bafb17cd8fd87bc3e0620cdb2039455756a137
4
- data.tar.gz: dd9be985a889af52c7da67708620f112edda743a
3
+ metadata.gz: b572a0cf6772f76c3039b9893c074167dc3f59db
4
+ data.tar.gz: 3198a8fc029d7e03d5aee2c93858a84d6270b152
5
5
  SHA512:
6
- metadata.gz: df277e23aff68fa1d2ffb4f71500c68bdd5db7f13011aa013de283f7a0467c06fb3ec796f710e82517d6f1c588680be4ef804fc7f3efbafc1cd3ff9eafca155f
7
- data.tar.gz: 588f52c7e4a644dca8c2911c6670866965a8d1db4add06b692ffc358c96c7a0a9abbea536b11e87e689dddd9d1e8da847c635d871ac9cc674ed806a3790ec1a1
6
+ metadata.gz: df631afa94ad29311361df8a3ea246c47d0500a954aaf899fc3ed0d7eed9fa77ebb0ea7875fe884414950e13fa11ebb8a2b6ff1655e00a3cca73f31100f647b4
7
+ data.tar.gz: c1f963bfcf98838ac4a309d52d31a5455d6704bc3cec1ba63fc055181f99fe5ce6bcadf6c0580d1939b992c8ca6d904b431a0e6b8eefd3e0f87553fec894dae1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- controller_commands (0.1.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.3)
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[:notice] = command.success_message
21
- {data: command.perform}
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
- parsed_params = JSON.parse(request.body.read)
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
 
@@ -1,3 +1,3 @@
1
1
  module ControllerCommands
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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-04-16 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler