resol 0.2.1 → 0.3.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: ace6271ca99729b99ebf4828dd8915078834d010d883ee14e71f98ac28534602
4
- data.tar.gz: c3c864c2622e681e0dba5bae64020083a7754604ed0f67623779cc73fc324a9a
3
+ metadata.gz: 95f5ea4fd61a180568a08289a20f53847d1709e70c07623086eb588948afa71e
4
+ data.tar.gz: b425c633f442b13ff8885b840fa792b94f28a6df9037581fe0def1aa7feeffd6
5
5
  SHA512:
6
- metadata.gz: dcbbc7fc8aed320aae8dbc8134ba1bf04b9226bb0555d49889777ba72f113b215a31986168a6248ab1d3001619ac3ba0f5c82f63aaed8db143f7f9f4aced4930
7
- data.tar.gz: 01ff693499b76bad144bdd215e1709db905b0ceedb6d805ebc4796538dcc96c0e1213623e0dec0b337da649d4b409a703a2dde01d2df5b6c8a877d402dfd0968
6
+ metadata.gz: cb48dfe79e77f5ee8bbc71c2c7438d2d414ab72fb428d634dc424d81d4bb7e5be940af252bd5bce2096c216e45e2872c081111c31eb3a3b8863db1eac565acec
7
+ data.tar.gz: de35e8196047e2af8100be471f1ec1fb1c2a920994215483fac1865089e19b9a5ee09112c0544041bf41f02471208be40ef5c3dace4b7756019dfb963b18eb1a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- resol (0.2.1)
4
+ resol (0.3.0)
5
5
  smart_initializer (~> 0.5)
6
6
  uber (~> 0.1)
7
7
 
data/README.md CHANGED
@@ -63,6 +63,34 @@ All incoming params and options can be defined using a [smart_initializer](https
63
63
  - `success!(value)` – finish with a success value
64
64
  - `fail!(code, data = nil)` – fail with any error code and optional data
65
65
 
66
+ #### Define callbacks
67
+
68
+ You can define callbacks to be executed before calling the `#call` method.
69
+
70
+ ```ruby
71
+ class FindUser < Resol::Service
72
+ param :id
73
+
74
+ before_call :set_user
75
+
76
+ def call
77
+ if user
78
+ success!(user)
79
+ else
80
+ fail!(:not_found)
81
+ end
82
+ end
83
+
84
+ private
85
+
86
+ attr_accessor :user
87
+
88
+ def set_user
89
+ self.user = User.find(id)
90
+ end
91
+ end
92
+ ```
93
+
66
94
  ### Result objects
67
95
 
68
96
  Methods:
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Resol
4
+ module Callbacks
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ base.instance_variable_set(:@__callback_methods__, [])
8
+ end
9
+
10
+ module ClassMethods
11
+ def inherited(subclass)
12
+ super
13
+ subclass.instance_variable_set(:@__callback_methods__, @__callback_methods__.dup)
14
+ end
15
+
16
+ def before_call(method_name)
17
+ @__callback_methods__ << method_name
18
+ end
19
+
20
+ private
21
+
22
+ def __run_callbacks__(instance)
23
+ @__callback_methods__.each { |method_name| instance.send(method_name) }
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/resol/service.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "builder"
4
+ require_relative "callbacks"
4
5
  require_relative "result"
5
6
 
6
7
  module Resol
@@ -41,6 +42,7 @@ module Resol
41
42
 
42
43
  include SmartCore::Initializer
43
44
  include Resol::Builder
45
+ include Resol::Callbacks
44
46
 
45
47
  class << self
46
48
  def inherited(klass)
@@ -51,6 +53,7 @@ module Resol
51
53
 
52
54
  def call(*args, &block)
53
55
  command = build(*args)
56
+ __run_callbacks__(command)
54
57
  command.call(&block)
55
58
 
56
59
  error_message = "No success! or fail! called in the #call method in #{command.class}"
data/lib/resol/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Resol
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Bespalov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-19 00:00:00.000000000 Z
11
+ date: 2021-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: smart_initializer
@@ -171,6 +171,7 @@ files:
171
171
  - bin/setup
172
172
  - lib/resol.rb
173
173
  - lib/resol/builder.rb
174
+ - lib/resol/callbacks.rb
174
175
  - lib/resol/result.rb
175
176
  - lib/resol/service.rb
176
177
  - lib/resol/version.rb