Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin functional, initializers loader, additional methods to monads, refactor code, remove ReturnEngine class #12

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
420b2f9
Add kind of factory for different initializers
AnotherRegularDude Dec 14, 2024
21128f4
Small fixes and specs fix
AnotherRegularDude Dec 14, 2024
72d2929
Write specs
AnotherRegularDude Dec 14, 2024
5777ce4
Refacor, plugins feature, initializer feature
AnotherRegularDude Dec 14, 2024
3a674f9
Some fixes, processing specs
AnotherRegularDude Dec 14, 2024
c179520
Fix and write specs, fix bugs, change minimal ruby version
AnotherRegularDude Dec 14, 2024
42b0969
Remove rbs because it so painful
AnotherRegularDude Dec 14, 2024
b17da80
Remove qonfig from Gemfile
AnotherRegularDude Dec 14, 2024
9ee5195
Add some description for the new func
AnotherRegularDude Dec 14, 2024
e667384
Remove some classes, use new ones, add di
AnotherRegularDude Dec 15, 2024
9c27c02
Fix oops
AnotherRegularDude Dec 15, 2024
ad5c7ff
Fixing specs
AnotherRegularDude Dec 15, 2024
31dd7d6
Fix
AnotherRegularDude Dec 15, 2024
70cb439
Finish refactoring and fixing after refactoring
AnotherRegularDude Dec 15, 2024
6740cfe
Install gems with 3.1
AnotherRegularDude Dec 15, 2024
ce03d81
Limiting versions of gems in gemspec
AnotherRegularDude Dec 15, 2024
5f9edf5
require all lib files after module definition
AnotherRegularDude Dec 15, 2024
eb9d721
Fix
AnotherRegularDude Dec 16, 2024
cb905b5
Fix bug, where the block was not transferred when the instance was split
AnotherRegularDude Dec 16, 2024
a4eebfc
Move all requirements below first module definition
AnotherRegularDude Dec 16, 2024
52567c4
Remove DI, small refactoring
AnotherRegularDude Jan 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.1"
ruby-version: "3.4"
bundler-cache: true
- name: Run Linter
run: bundle exec ci-helper RubocopLint
Expand All @@ -43,7 +43,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby: ["2.7", "3.0"]
ruby: ["3.1", "3.2", "3.3"]
experimental: [false]
include:
- ruby: head
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ inherit_gem:

AllCops:
DisplayCopNames: true
TargetRubyVersion: 2.7
TargetRubyVersion: 3.1

Naming/MethodParameterName:
AllowedNames: ["x", "y", "z"]
Expand Down
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ gem "rspec"
gem "rubocop-config-umbrellio"
gem "simplecov"
gem "simplecov-lcov"

gem "dry-initializer"
gem "smart_initializer"
173 changes: 94 additions & 79 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,118 +1,130 @@
PATH
remote: .
specs:
resol (0.9.0)
smart_initializer (~> 0.7)
resol (1.0.0)
dry-configurable (~> 1.2.0)

GEM
remote: https://rubygems.org/
specs:
activesupport (7.1.2)
activesupport (7.2.2.1)
base64
benchmark (>= 0.3)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.4)
bundler-audit (0.9.1)
benchmark (0.4.0)
bigdecimal (3.1.9)
bundler-audit (0.9.2)
bundler (>= 1.2.0, < 3)
thor (~> 1.0)
ci-helper (0.5.0)
colorize (~> 0.8)
dry-inflector (~> 0.2)
umbrellio-sequel-plugins (~> 0.4)
ci-helper (0.7.0)
colorize (~> 1.1)
dry-inflector (~> 1.0)
umbrellio-sequel-plugins (~> 0.14)
coderay (1.1.3)
colorize (0.8.1)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
diff-lcs (1.5.0)
docile (1.4.0)
drb (2.2.0)
ruby2_keywords
dry-inflector (0.3.0)
i18n (1.14.1)
colorize (1.1.0)
concurrent-ruby (1.3.4)
connection_pool (2.5.0)
diff-lcs (1.5.1)
docile (1.4.1)
drb (2.2.1)
dry-configurable (1.2.0)
dry-core (~> 1.0, < 2)
zeitwerk (~> 2.6)
dry-core (1.1.0)
concurrent-ruby (~> 1.0)
json (2.6.3)
method_source (1.0.0)
minitest (5.20.0)
mutex_m (0.2.0)
parallel (1.23.0)
parser (3.2.2.4)
logger
zeitwerk (~> 2.6)
dry-inflector (1.2.0)
dry-initializer (3.2.0)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.9.1)
language_server-protocol (3.17.0.3)
logger (1.6.5)
method_source (1.1.0)
minitest (5.25.4)
parallel (1.26.3)
parser (3.3.6.0)
ast (~> 2.4.1)
racc
pry (0.14.2)
pry (0.15.2)
coderay (~> 1.1)
method_source (~> 1.0)
qonfig (0.28.0)
racc (1.7.3)
rack (3.0.8)
qonfig (0.30.0)
base64 (>= 0.2)
racc (1.8.1)
rack (3.1.8)
rainbow (3.1.1)
rake (13.1.0)
regexp_parser (2.8.2)
rexml (3.2.6)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
rake (13.2.1)
regexp_parser (2.10.0)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.2)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (1.50.2)
rspec-support (~> 3.13.0)
rspec-support (3.13.2)
rubocop (1.69.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.0.0)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.36.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.19.0)
rubocop (~> 1.41)
rubocop-config-umbrellio (1.50.0.85)
rubocop (~> 1.50.0)
rubocop-performance (~> 1.17.0)
rubocop-rails (~> 2.19.0)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.37.0)
parser (>= 3.3.1.0)
rubocop-config-umbrellio (1.69.0.101)
rubocop (~> 1.69.0)
rubocop-factory_bot (~> 2.26.0)
rubocop-performance (~> 1.23.0)
rubocop-rails (~> 2.28.0)
rubocop-rake (~> 0.6.0)
rubocop-rspec (~> 2.20.0)
rubocop-sequel (~> 0.3.3)
rubocop-performance (1.17.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.19.1)
rubocop-rspec (~> 3.3.0)
rubocop-sequel (~> 0.3.0)
rubocop-factory_bot (2.26.1)
rubocop (~> 1.61)
rubocop-performance (1.23.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.28.0)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop (>= 1.52.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.20.0)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
rubocop-sequel (0.3.4)
rubocop-rspec (3.3.0)
rubocop (~> 1.61)
rubocop-sequel (0.3.8)
rubocop (~> 1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sequel (5.74.0)
securerandom (0.4.1)
sequel (5.88.0)
bigdecimal
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov-html (0.13.1)
simplecov-lcov (0.8.0)
simplecov_json_formatter (0.1.4)
smart_engine (0.17.0)
Expand All @@ -122,14 +134,15 @@ GEM
smart_types (~> 0.8)
smart_types (0.8.0)
smart_engine (~> 0.11)
symbiont-ruby (0.7.0)
thor (1.3.0)
thor (1.3.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
umbrellio-sequel-plugins (0.14.0.189)
umbrellio-sequel-plugins (0.17.0)
sequel
symbiont-ruby
unicode-display_width (2.5.0)
unicode-display_width (3.1.3)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
zeitwerk (2.6.18)

PLATFORMS
arm64-darwin-21
Expand All @@ -142,13 +155,15 @@ PLATFORMS
DEPENDENCIES
bundler-audit
ci-helper
dry-initializer
pry
rake
resol!
rspec
rubocop-config-umbrellio
simplecov
simplecov-lcov
smart_initializer

BUNDLED WITH
2.4.10
2.6.2
54 changes: 46 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,38 @@ and method `.call!` returns a value or throws an error (in case of `fail!` has b

#### Params defining

All incoming params and options can be defined using a [smart_initializer](https://github.com/smart-rb/smart_initializer) gem interface.
`Resol` supports two gems, which provide abstract initialization flow for classes:

1. [smart_initializer](https://github.com/smart-rb/smart_initializer), which was default provider for a very long time.
2. [dry-initializer](https://dry-rb.org/gems/dry-initializer/3.1), additional provider with DSL almost identical to the smart_core's DSL.

There is an _important restriction_ on using different initializers in different services.
Descendants of a parent, into which initializer logic has already been imported, cannot override the provider

You can use both providers for a different services:

```ruby
# Types is a namespace for all types, defined by smart_types.
class FirstService < Resol::Service
inject_initializer :smartcore_injector

param :first, Types::String
param :second, Types::Integer
end

# Types is a namespace for all types, defined by dry-types.
class SecondService < Resol::Service
inject_initializer :dry_injector

param :first, Types::Strict::String
param :second, Types::Strict::Integer
end
```

Both initializers support inheritance. And base features for initialization flow
like default value, arguments accessors visibility level, coercible attributes and so on.

List of all supported initializers you can see at `DependencyContainer` definition.

#### Return a result

Expand Down Expand Up @@ -95,13 +126,15 @@ end

Methods:

- `success?` – returns `true` for success result and `false` for failure result
- `failure?` – returns `true` for failure result and `false` for success result
- `value!` – unwraps a result object, returns the value for success result, and throws an error for failure result
- `value_or(other_value, &block)` – returns a value for success result or `other_value` for failure result (either calls `block` in case it given)
- `error` – returns `nil` for success result and error object (with code and data) for failure result
- `or(&block)` – calls block for failure result, for success result does nothing
- `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.
- `success?` — returns `true` for success result and `false` for failure result
- `failure?` — returns `true` for failure result and `false` for success result
- `value!` — unwraps a result object, returns the value for success result, and throws an error for failure result
- `value_or(other_value, &block)` — returns a value for success result or `other_value` for failure result (either calls `block` in case it given)
- `error` — returns `nil` for success result and error object (with code and data) for failure result
- `or(&block)` — calls block for failure result, for success result does nothing
- `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.
- `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`.
- `fmap` — like the `bind`, but wraps value returned by block by success monad.

### Error object

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

### Plugin System

Resol implements the basic logic of using plugins to extend and change the base service class.
You can write your own plugin and applie it by calling `Resol::Service#plugin(plugin_name)`.

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests.
Expand Down
13 changes: 9 additions & 4 deletions lib/resol.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# frozen_string_literal: true

require "smart_core/initializer"

require "dry-configurable"
require_relative "resol/version"
require_relative "resol/return_engine"
require_relative "resol/configuration"

require_relative "resol/injector"
require_relative "resol/plugins"
require_relative "resol/service"

module Resol
extend self

extend Dry::Configurable

setting :classes_allowed_to_patch, default: ["Resol::Service"]
end
Loading
Loading