Skip to content

Commit 9ee5195

Browse files
Add some description for the new func
1 parent b17da80 commit 9ee5195

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

README.md

+45-8
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,37 @@ and method `.call!` returns a value or throws an error (in case of `fail!` has b
5454

5555
#### Params defining
5656

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+
class FirstService < 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+
class SecondService < 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.
5888

5989
#### Return a result
6090

@@ -95,13 +125,15 @@ end
95125

96126
Methods:
97127

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.
105137

106138
### Error object
107139

@@ -115,6 +147,11 @@ methods `code` and `data`.
115147
Configuration constant references to `SmartCore::Initializer::Configuration`. You can read
116148
about available configuration options [here](https://github.com/smart-rb/smart_initializer#configuration).
117149

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+
118155
## Development
119156

120157
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests.

0 commit comments

Comments
 (0)