You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+45-8
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,37 @@ and method `.call!` returns a value or throws an error (in case of `fail!` has b
54
54
55
55
#### Params defining
56
56
57
-
All incoming params and options can be defined using a [smart_initializer](https://github.com/smart-rb/smart_initializer) gem interface.
57
+
`Resol` supports two gems, which provide abstract initialization flow for classes:
58
+
59
+
1.[smart_initializer](https://github.com/smart-rb/smart_initializer), which was default provider for a very long time.
60
+
2.[dry-initializer](https://dry-rb.org/gems/dry-initializer/3.1), additional provider with DSL almost identical to the smart_core's DSL.
61
+
62
+
There is an _important restriction_ on using different initializers in different services.
63
+
Descendants of a parent, into which initializer logic has already been imported, cannot override the provider
64
+
65
+
You can use both providers for a different services:
66
+
67
+
```ruby
68
+
69
+
# Types is a namespace for all types, defined by smart_types.
70
+
classFirstService < Resol::Service
71
+
use_initializer! :smartcore
72
+
73
+
param :first, Types::String
74
+
param :second, Types::Integer
75
+
end
76
+
77
+
# Types is a namespace for all types, defined by dry-types.
78
+
classSecondService < Resol::Service
79
+
use_initializer! :dry
80
+
81
+
param :first, Types::Strict::String
82
+
param :second, Types::Strict::Integer
83
+
end
84
+
```
85
+
86
+
Both initializers support inheritance. And base features for initialization flow
87
+
like default value, arguments accessors visibility level, coercible attributes and so on.
58
88
59
89
#### Return a result
60
90
@@ -95,13 +125,15 @@ end
95
125
96
126
Methods:
97
127
98
-
-`success?` – returns `true` for success result and `false` for failure result
99
-
-`failure?` – returns `true` for failure result and `false` for success result
100
-
-`value!` – unwraps a result object, returns the value for success result, and throws an error for failure result
101
-
-`value_or(other_value, &block)` – returns a value for success result or `other_value` for failure result (either calls `block` in case it given)
102
-
-`error` – returns `nil` for success result and error object (with code and data) for failure result
103
-
-`or(&block)` – calls block for failure result, for success result does nothing
104
-
-`either(success_proc, failure_proc)` – for success result calls success_proc with result value in args, for failure result calls failure_proc with error in args.
128
+
-`success?` — returns `true` for success result and `false` for failure result
129
+
-`failure?` — returns `true` for failure result and `false` for success result
130
+
-`value!` — unwraps a result object, returns the value for success result, and throws an error for failure result
131
+
-`value_or(other_value, &block)` — returns a value for success result or `other_value` for failure result (either calls `block` in case it given)
132
+
-`error` — returns `nil` for success result and error object (with code and data) for failure result
133
+
-`or(&block)` — calls block for failure result, for success result does nothing
134
+
-`either(success_proc, failure_proc)` — for success result calls success_proc with result value in args, for failure result calls failure_proc with error in args.
135
+
-`bind` — using with `block` for success result resolve value and pass it to the `block`, used to chain multiple monads. Block can return anything. Failure result ignore block and return `self`.
136
+
-`fmap` — like the `bind`, but wraps value returned by block by success monad.
105
137
106
138
### Error object
107
139
@@ -115,6 +147,11 @@ methods `code` and `data`.
115
147
Configuration constant references to `SmartCore::Initializer::Configuration`. You can read
116
148
about available configuration options [here](https://github.com/smart-rb/smart_initializer#configuration).
117
149
150
+
### Plugin System
151
+
152
+
Resol implements the basic logic of using plugins to extend and change the base service class.
153
+
You can write your own plugin and applie it by calling `Resol::Service#plugin(plugin_name)`.
154
+
118
155
## Development
119
156
120
157
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests.
0 commit comments