haku 1.1.0 → 1.2.0

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: d706591454ee0f992403b400e7dc75e621bccb120978050d98f55f2aaceca5bd
4
- data.tar.gz: 18652ffbeff0a83d8a7344d7de7e7f4bb905d973a740fecc99a14a05d1258d46
3
+ metadata.gz: b65774c4966531378070fabd031b8bdb943b10b7ec18f6fea1424d00d5ab382d
4
+ data.tar.gz: 7505219941e0b0dcb7189671dcf9a8593f3cdaa6d9c893b0b4ba6c438c6ee56b
5
5
  SHA512:
6
- metadata.gz: f4ad33422d9efcba85416ee72099e1c577b1172f6e4a40bea8c9d28cfd4edb8f3259eb5f04671a54ca67dcab0cc796bb407f39111d5ecb9fd30cc6d2d6bf235a
7
- data.tar.gz: ee0e64b2f70d88f833cedbf96b56af02a9ffaaa17e29df5d582ae6b71a6199935e6897b8bbc704f4d2c035215be45b9767e5814275da002aa8836e627f5c5db8
6
+ metadata.gz: e310f74ec63fe80d30381b56e36515311786dc6e8c13b065dab9d99a93ee6c9b87891582017f0de199c3e7e18d5ea2534adc9f7927633151127a2abb236fec91
7
+ data.tar.gz: c9ca7c513ec7cb2f92b9719071e84d0817d8722480274409b1937aa33062995845eb979bd91314ee41337756dcfe6faa55e7cfe8170fd89aae9a92056cbe92fa
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.2.0] - 2022-04-20
4
+ - Refactor how response is created on finish
5
+
3
6
  ## [1.1.0] - 2022-04-19
4
7
  - Allow to configure Haku using block
5
8
  - Add Eventable module to fire events
data/Gemfile.lock CHANGED
@@ -11,7 +11,7 @@ GIT
11
11
  PATH
12
12
  remote: .
13
13
  specs:
14
- haku (1.1.0)
14
+ haku (1.2.0)
15
15
  activesupport (>= 6.0, < 8.0)
16
16
 
17
17
  GEM
data/README.md CHANGED
@@ -47,6 +47,7 @@ end
47
47
  response = Users::Update.call(user: User.first, attributes: { name: "Javier" })
48
48
 
49
49
  response.success? # => true
50
+ response.result # => { resource: <User id="1" ...> }
50
51
  response.resource # => <User id="1" ...>
51
52
  ````
52
53
 
data/lib/haku/core.rb CHANGED
@@ -44,12 +44,17 @@ module Haku
44
44
  end
45
45
  end
46
46
 
47
+ Finish = Struct.new("Finish", :status, :payload)
48
+
47
49
  module Callable
48
50
  def call
49
- result = super
51
+ response = catch(:finish) { super }
52
+
53
+ status = response.is_a?(Finish) ? response.status : :success
54
+ payload = response.is_a?(Finish) ? response.payload : response
50
55
 
51
- Result.new(_haku_status, _haku_response.merge(result: result)).tap do
52
- _haku_run_callbacks
56
+ Result.new(status, payload).tap do
57
+ _haku_run_callbacks(status)
53
58
  end
54
59
  end
55
60
  end
@@ -57,9 +62,6 @@ module Haku
57
62
  def initialize(params={})
58
63
  @params = params
59
64
 
60
- @_haku_status = :success
61
- @_haku_response = {}
62
-
63
65
  self.class.haku_inputs.each do |name|
64
66
  define_singleton_method(name) { @params[name] } unless respond_to?(name)
65
67
  end
@@ -67,32 +69,16 @@ module Haku
67
69
 
68
70
  private
69
71
 
70
- def success!(response={})
71
- @_haku_status = :success
72
- @_haku_response = _haku_normalize_response(response)
73
- nil
74
- end
75
-
76
- def failure!(response={})
77
- @_haku_status = :failure
78
- @_haku_response = _haku_normalize_response(response)
79
- nil
80
- end
81
-
82
- def _haku_normalize_response(response)
83
- response.is_a?(Hash) ? response : { data: response }
84
- end
85
-
86
- def _haku_status
87
- @_haku_status
72
+ def success!(data=nil)
73
+ throw :finish, Finish.new(:success, data)
88
74
  end
89
75
 
90
- def _haku_response
91
- @_haku_response
76
+ def failure!(data=nil)
77
+ throw :finish, Finish.new(:failure, data)
92
78
  end
93
79
 
94
- def _haku_run_callbacks
95
- (self.class.send("haku_#{_haku_status}_callbacks") || []).each { |cb| send(cb) }
80
+ def _haku_run_callbacks(status)
81
+ (self.class.send("haku_#{status}_callbacks") || []).each { |cb| send(cb) }
96
82
  end
97
83
  end
98
84
  end
data/lib/haku/result.rb CHANGED
@@ -4,15 +4,21 @@ require "active_support/string_inquirer"
4
4
 
5
5
  module Haku
6
6
  class Result
7
- def initialize(status, response)
7
+ def initialize(status, payload)
8
8
  @status = ActiveSupport::StringInquirer.new(status.to_s)
9
- @response = response
9
+ @payload = payload
10
10
 
11
- @response.each_key do |key|
12
- define_singleton_method(key) { @response[key] }
11
+ return unless @payload.respond_to?(:to_h)
12
+
13
+ @payload.to_h.each_key do |key|
14
+ define_singleton_method(key) { @payload[key] }
13
15
  end
14
16
  end
15
17
 
18
+ def result
19
+ @payload
20
+ end
21
+
16
22
  def success?
17
23
  @status.success?
18
24
  end
data/lib/haku/version.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Haku
4
4
  module VERSION
5
5
  MAJOR = 1
6
- MINOR = 1
6
+ MINOR = 2
7
7
  TINY = 0
8
8
  PRE = nil
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haku
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Aranda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-19 00:00:00.000000000 Z
11
+ date: 2022-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -68,8 +68,8 @@ licenses:
68
68
  - MIT
69
69
  metadata:
70
70
  homepage_uri: https://github.com/javierav/haku
71
- source_code_uri: https://github.com/javierav/haku/tree/v1.1.0
72
- changelog_uri: https://github.com/javierav/haku/blob/v1.1.0/CHANGELOG.md
71
+ source_code_uri: https://github.com/javierav/haku/tree/v1.2.0
72
+ changelog_uri: https://github.com/javierav/haku/blob/v1.2.0/CHANGELOG.md
73
73
  rubygems_mfa_required: 'true'
74
74
  post_install_message:
75
75
  rdoc_options: