blacksheep 0.2.2 → 0.2.3

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
  SHA256:
3
- metadata.gz: 0f9f95a300f2d7c84826615cb86a66fabe8ecdd680edabf6b9e960973d8f5f83
4
- data.tar.gz: 3cdfd65ec9647bed1ff5df0261b000227f395d379a9c310e8def4de9b0439c83
3
+ metadata.gz: 4b520c717b2b72704b7f6854ce506fca8e47773a3b2fe48d54344d2622a9ac8b
4
+ data.tar.gz: b3dfe30943535dbc03e6a9e81c088e2267528c775aa484524d12710e50b2cf64
5
5
  SHA512:
6
- metadata.gz: ac515283bff176a47ffa4b6159e169c7a3776bc1e2d0f587182e479420b805b0633e2f909a9720bbff15bcc68776ce9f180e51e6a014e2e2ef2ae261b6114d94
7
- data.tar.gz: 1c7008322b347109e570b87f8a83b6512a7380c4021e779655fb80f8bd426efc9aad3a1a606c73dd09e7735f2a85dd927e5f8f472ce5650323ec7d90283c82cf
6
+ metadata.gz: 3d3ee10c9acc1381e10e95101c42d7bbd17b6972c94b526aabc28b1b142bec56634da37b2ff0bd71f752ec158846ba888439af2d87bd3120c4fdda7e0a75c010
7
+ data.tar.gz: '0401960e858de894e369599234431f8c91014e5ea0419924d00bb20396c48dd50d3faa04f2fa0d266f79e3d10795e9ad93ffa1ae45aa72b232d786a0a44db8e4'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blacksheep (0.2.2)
4
+ blacksheep (0.2.3)
5
5
  dry-matcher
6
6
 
7
7
  GEM
data/lib/blacksheep.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  require "blacksheep/version"
2
2
  require "blacksheep/action_result"
3
3
  require "blacksheep/action_decorator"
4
+ require "blacksheep/decorators/error_handler"
4
5
  require "blacksheep/decorators/default_error_handler"
5
6
  require "blacksheep/decorators/json_transformer"
6
7
  require "blacksheep/decorators/result_matcher"
8
+ require "blacksheep/decorators/localizer"
7
9
  require "blacksheep/action"
8
10
  require "blacksheep/version"
9
11
 
@@ -28,11 +28,16 @@ module Blacksheep
28
28
  @@decorators ||= []
29
29
  end
30
30
 
31
+ #
32
+ # Adds a decorator to the list of decorated to be applied on Balcksheep::Actions
33
+ # @param decorator [type] [description]
34
+ #
35
+ # @return [type] [description]
31
36
  def add_decorator(decorator)
32
- decorators << decorator
37
+ decorators << decorator unless decorators.include?(decorator)
33
38
  end
34
39
 
35
- def new(*)
40
+ def new(*arguments, &block)
36
41
  instance = super
37
42
 
38
43
  decorators.each do |decorator|
@@ -1,9 +1,29 @@
1
1
  require 'delegate'
2
2
 
3
3
  module Blacksheep
4
+ # @class Blacksheep::ActionDecorator
4
5
  class ActionDecorator < SimpleDelegator
6
+
7
+ # Access to the decorators class - since original class is overwritten to return the model class.
8
+ #
9
+ # @return [Class] The class of the deocrator.
10
+ # @see [#class]
11
+ alias_method :__class__, :class
12
+
5
13
  def class
6
14
  __getobj__.class
7
15
  end
16
+
17
+ #
18
+ # Just for curiosity - get the decorators chain
19
+ #
20
+ # @return [type] [description]
21
+ def decorators_chain
22
+ decorated = __getobj__
23
+ chain = decorated.kind_of?(Blacksheep::ActionDecorator) ? decorated.decorators_chain : [ decorated.class ]
24
+
25
+ chain.unshift(self.__class__)
26
+ end
27
+
8
28
  end
9
29
  end
@@ -1,7 +1,7 @@
1
1
  module Blacksheep
2
2
  module Decorators
3
- # @class Blacksheep::Decorators::ErrorHandler
4
- class ErrorHandler
3
+ # @module Blacksheep::Decorators::ErrorHandler
4
+ module ErrorHandler
5
5
 
6
6
  def call(*)
7
7
  super
@@ -5,10 +5,10 @@ module Blacksheep
5
5
 
6
6
  attr_reader :case, :params
7
7
 
8
- def call(params, **options)
8
+ def call(params, current_user: nil, **options)
9
9
  detect_case(params)
10
10
 
11
- transformed_params = self.transformed_params(params)
11
+ transformed_params = self.transform_params(params)
12
12
 
13
13
  json = super(transformed_params, **options)
14
14
 
@@ -20,9 +20,10 @@ module Blacksheep
20
20
  def perform(params, current_user: nil, **options, &block)
21
21
  detect_case(params)
22
22
 
23
- transformed_params = self.transformed_params(params)
23
+ transformed_params = self.transform_params(params)
24
+
25
+ json = super(transformed_params, current_user: current_user, **options, &block)
24
26
 
25
- json = block.call(transformed_params)
26
27
  transformed_json = transform_result(json)
27
28
 
28
29
  ActionResult.new(transformed_json, :ok)
@@ -34,7 +35,7 @@ module Blacksheep
34
35
  #
35
36
  # @return [Array, Hash] The params converted into snake_case
36
37
  # @see #snakecase_keys
37
- def transformed_params(params)
38
+ def transform_params(params)
38
39
  case @case
39
40
  when 'snake', 'as_is'
40
41
  params
@@ -1,10 +1,10 @@
1
1
  module Blacksheep
2
2
  module Decorators
3
3
 
4
- # @class Blacksheep::Decorators::Localozer
4
+ # @class Blacksheep::Decorators::Localizer
5
5
  class Localizer < ActionDecorator
6
6
 
7
- def call(params, **)
7
+ def call(params, current_user: nil, **options)
8
8
  if (locale = params[:_locale])
9
9
  I18n.with_locale(locale) do
10
10
  super
@@ -14,7 +14,8 @@ module Blacksheep
14
14
  end
15
15
  end
16
16
 
17
- def perform(params, **)
17
+ def perform(params, current_user: nil, **options)
18
+
18
19
  if (locale = params[:_locale])
19
20
  I18n.with_locale(locale) do
20
21
  super
@@ -1,3 +1,3 @@
1
1
  module Blacksheep
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacksheep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Schweizer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-17 00:00:00.000000000 Z
11
+ date: 2021-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-matcher