not_monads 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.devcontainer/devcontainer.json +52 -0
- data/.devcontainer/docker-compose.yml +26 -0
- data/.dockerignore +25 -0
- data/.editorconfig +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +18 -0
- data/CHANGELOG.md +5 -0
- data/Dockerfile +18 -0
- data/LICENSE.txt +21 -0
- data/README.md +57 -0
- data/Rakefile +12 -0
- data/docker-compose.yml +15 -0
- data/lib/not_monads/do.rb +54 -0
- data/lib/not_monads/result.rb +83 -0
- data/lib/not_monads/version.rb +5 -0
- data/lib/not_monads.rb +8 -0
- data/sig/not_monads.rbs +4 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2e9974bab26e9af1e3ec8fad57c6b72b706bcbc1933fed1ec606050103252bb3
|
4
|
+
data.tar.gz: 560ddae392216cc701cc94281471084c22dd9042f44e561b80cfe7a76fb98f36
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf6b4273f3e41abd484a1022fb1475431b73dc3ee60a0c7df5ecca9939e55bb8e40bcae2b05f8989cb2315200fd5b426ebd7f9d51b907c1961121f00ef4dc5b4
|
7
|
+
data.tar.gz: e658304d770247652411c4855f670d367119916dd132d720ff57a9a374a67c4adac16021adcbf6c8c38b0c65e24930366d56c715af04fc4f307488a21d4eefac
|
@@ -0,0 +1,52 @@
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
2
|
+
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
|
3
|
+
{
|
4
|
+
"name": "not_monads devcontainer",
|
5
|
+
|
6
|
+
// Update the 'dockerComposeFile' list if you have more compose files or use different names.
|
7
|
+
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
|
8
|
+
"dockerComposeFile": [
|
9
|
+
"../docker-compose.yml",
|
10
|
+
"docker-compose.yml"
|
11
|
+
],
|
12
|
+
|
13
|
+
// The 'service' property is the name of the service for the container that VS Code should
|
14
|
+
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
|
15
|
+
"service": "not_monads",
|
16
|
+
|
17
|
+
// The optional 'workspaceFolder' property is the path VS Code should open by default when
|
18
|
+
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
|
19
|
+
// "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}"
|
20
|
+
"workspaceFolder": "/app",
|
21
|
+
"customizations": {
|
22
|
+
"vscode": {
|
23
|
+
"extensions": [
|
24
|
+
"ms-azuretools.vscode-docker",
|
25
|
+
"EditorConfig.EditorConfig",
|
26
|
+
"eamodio.gitlens",
|
27
|
+
"Shopify.ruby-extensions-pack"
|
28
|
+
]
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
// Features to add to the dev container. More info: https://containers.dev/features.
|
33
|
+
// "features": {},
|
34
|
+
|
35
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
36
|
+
// "forwardPorts": [],
|
37
|
+
|
38
|
+
// Uncomment the next line if you want start specific services in your Docker Compose config.
|
39
|
+
// "runServices": [],
|
40
|
+
|
41
|
+
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
|
42
|
+
// "shutdownAction": "none",
|
43
|
+
|
44
|
+
// Uncomment the next line to run commands after the container is created.
|
45
|
+
// "postCreateCommand": "cat /etc/os-release",
|
46
|
+
|
47
|
+
// Configure tool-specific properties.
|
48
|
+
// "customizations": {},
|
49
|
+
|
50
|
+
// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
|
51
|
+
// "remoteUser": "devcontainer"
|
52
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
version: '3.4'
|
2
|
+
services:
|
3
|
+
# Update this to the name of the service you want to work with in your docker-compose.yml file
|
4
|
+
not_monads:
|
5
|
+
# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
|
6
|
+
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
|
7
|
+
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
|
8
|
+
# array). The sample below assumes your primary file is in the root of your project.
|
9
|
+
#
|
10
|
+
# build:
|
11
|
+
# context: .
|
12
|
+
# dockerfile: .devcontainer/Dockerfile
|
13
|
+
|
14
|
+
# volumes:
|
15
|
+
# # Update this to wherever you want VS Code to mount the folder of your project
|
16
|
+
# - ..:/workspaces:cached
|
17
|
+
|
18
|
+
# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
|
19
|
+
# cap_add:
|
20
|
+
# - SYS_PTRACE
|
21
|
+
# security_opt:
|
22
|
+
# - seccomp:unconfined
|
23
|
+
|
24
|
+
# Overrides default command so things don't shut down after the process ends.
|
25
|
+
command: /bin/sh -c "while sleep 1000; do :; done"
|
26
|
+
|
data/.dockerignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
**/.classpath
|
2
|
+
**/.dockerignore
|
3
|
+
**/.env
|
4
|
+
**/.git
|
5
|
+
**/.gitignore
|
6
|
+
**/.project
|
7
|
+
**/.settings
|
8
|
+
**/.toolstarget
|
9
|
+
**/.vs
|
10
|
+
**/.vscode
|
11
|
+
**/*.*proj.user
|
12
|
+
**/*.dbmdl
|
13
|
+
**/*.jfm
|
14
|
+
**/bin
|
15
|
+
**/charts
|
16
|
+
**/docker-compose*
|
17
|
+
**/compose*
|
18
|
+
**/Dockerfile*
|
19
|
+
**/node_modules
|
20
|
+
**/npm-debug.log
|
21
|
+
**/obj
|
22
|
+
**/secrets.dev.yaml
|
23
|
+
**/values.dev.yaml
|
24
|
+
LICENSE
|
25
|
+
README.md
|
data/.editorconfig
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
- rubocop-performance
|
5
|
+
- rubocop-thread_safety
|
6
|
+
|
7
|
+
AllCops:
|
8
|
+
TargetRubyVersion: 3.0
|
9
|
+
NewCops: enable
|
10
|
+
|
11
|
+
Style/Documentation:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
RSpec/MultipleExpectations:
|
15
|
+
Max: 4
|
16
|
+
|
17
|
+
Style/CaseEquality:
|
18
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
data/Dockerfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
FROM ruby:3.3-alpine
|
2
|
+
|
3
|
+
LABEL Name=not_monads Version=0.1.0
|
4
|
+
|
5
|
+
RUN apk add --update git
|
6
|
+
|
7
|
+
# throw errors if Gemfile has been modified since Gemfile.lock
|
8
|
+
# RUN bundle config --global frozen 1
|
9
|
+
|
10
|
+
WORKDIR /app
|
11
|
+
|
12
|
+
COPY Gemfile Gemfile.lock not_monads.gemspec ./
|
13
|
+
COPY lib/not_monads/version.rb lib/not_monads/version.rb
|
14
|
+
RUN bundle install
|
15
|
+
|
16
|
+
COPY . /app
|
17
|
+
|
18
|
+
# CMD ["ruby", "serviceobjects.rb"]
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 kolas
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# NotMonads
|
2
|
+
|
3
|
+
Simple copy of [dry-monads](https://github.com/dry-rb/dry-monads) do monads, it implements only mixin for your service object and Success/Failure result object.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
$ bundle add not_monads
|
10
|
+
|
11
|
+
or add to Gemfile
|
12
|
+
|
13
|
+
gem 'not_monads'
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install not_monads
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Add module to your class with prepend:
|
22
|
+
|
23
|
+
```
|
24
|
+
class CreateUser
|
25
|
+
prepend NotMonads::Do[:call]
|
26
|
+
|
27
|
+
def call(params)
|
28
|
+
do_something validate(params)
|
29
|
+
user = do_something save(params)
|
30
|
+
Success(user)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def validate(params)
|
36
|
+
Success() || Failure(:error)
|
37
|
+
end
|
38
|
+
|
39
|
+
def save(params)
|
40
|
+
Success(user) || Failure(errors)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
Prepend with a module call with array of method names in square brackets. (`prepend NotMonads::Do[:call, :step1, :step3]`) Use method `do_something` to verify result, just like dry-monads with `yield` (`do_something` is a temporary method name, idk how to name it better yet)
|
47
|
+
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/docker-compose.yml
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'result'
|
4
|
+
|
5
|
+
module NotMonads
|
6
|
+
module Do
|
7
|
+
module MixinInstance
|
8
|
+
# rubocop:disable Naming/MethodName
|
9
|
+
def Success(value = nil)
|
10
|
+
NotMonads::Result::Success.new(value)
|
11
|
+
end
|
12
|
+
|
13
|
+
def Failure(value = nil)
|
14
|
+
NotMonads::Result::Failure.new(value)
|
15
|
+
end
|
16
|
+
# rubocop:enable Naming/MethodName
|
17
|
+
|
18
|
+
def do_something(result)
|
19
|
+
return result.success if result.success?
|
20
|
+
|
21
|
+
halt(result)
|
22
|
+
end
|
23
|
+
|
24
|
+
def halt(result)
|
25
|
+
raise Halt, result
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Halt < StandardError
|
30
|
+
attr_reader :result
|
31
|
+
|
32
|
+
def initialize(result)
|
33
|
+
super()
|
34
|
+
@result = result
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class << self
|
39
|
+
def [](*methods)
|
40
|
+
Module.new do
|
41
|
+
methods.each do |method|
|
42
|
+
define_method(method) do |*args, **kwargs, &block|
|
43
|
+
super(*args, **kwargs, &block)
|
44
|
+
rescue Halt => e
|
45
|
+
e.result
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
include MixinInstance
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module NotMonads
|
4
|
+
class Result
|
5
|
+
attr_reader :success, :failure
|
6
|
+
|
7
|
+
class Success < Result
|
8
|
+
def initialize(value)
|
9
|
+
super()
|
10
|
+
@success = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def failure?
|
14
|
+
false
|
15
|
+
end
|
16
|
+
|
17
|
+
def success?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
"Success(#{success.inspect})"
|
23
|
+
end
|
24
|
+
alias inspect to_s
|
25
|
+
|
26
|
+
def value!
|
27
|
+
success
|
28
|
+
end
|
29
|
+
|
30
|
+
def value_or(_val = nil)
|
31
|
+
success
|
32
|
+
end
|
33
|
+
|
34
|
+
def ==(other)
|
35
|
+
other.is_a?(self.class) && value! == other.value!
|
36
|
+
end
|
37
|
+
|
38
|
+
def ===(other)
|
39
|
+
other.instance_of?(self.class) && value! === other.value!
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Failure < Result
|
44
|
+
def initialize(value)
|
45
|
+
super()
|
46
|
+
@failure = value
|
47
|
+
end
|
48
|
+
|
49
|
+
def failure?
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
53
|
+
def success?
|
54
|
+
false
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_s
|
58
|
+
"Failure(#{failure.inspect})"
|
59
|
+
end
|
60
|
+
alias inspect to_s
|
61
|
+
|
62
|
+
def value!
|
63
|
+
raise Error, "value! was called on #{self}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def value_or(val = nil)
|
67
|
+
if block_given?
|
68
|
+
yield
|
69
|
+
else
|
70
|
+
val
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def ==(other)
|
75
|
+
other.is_a?(self.class) && failure == other.failure
|
76
|
+
end
|
77
|
+
|
78
|
+
def ===(other)
|
79
|
+
other.instance_of?(self.class) && failure === other.failure
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/not_monads.rb
ADDED
data/sig/not_monads.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: not_monads
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kolas
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-01-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Simple copy of [dry-monads](https://github.com/dry-rb/dry-monads) do
|
14
|
+
monads, it implements only mixin for your service object and Success/Failure result
|
15
|
+
object.
|
16
|
+
email:
|
17
|
+
- kolas.krytoi@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- ".devcontainer/devcontainer.json"
|
23
|
+
- ".devcontainer/docker-compose.yml"
|
24
|
+
- ".dockerignore"
|
25
|
+
- ".editorconfig"
|
26
|
+
- ".rspec"
|
27
|
+
- ".rubocop.yml"
|
28
|
+
- CHANGELOG.md
|
29
|
+
- Dockerfile
|
30
|
+
- LICENSE.txt
|
31
|
+
- README.md
|
32
|
+
- Rakefile
|
33
|
+
- docker-compose.yml
|
34
|
+
- lib/not_monads.rb
|
35
|
+
- lib/not_monads/do.rb
|
36
|
+
- lib/not_monads/result.rb
|
37
|
+
- lib/not_monads/version.rb
|
38
|
+
- sig/not_monads.rbs
|
39
|
+
homepage: https://github.com/kolasss/not_monads
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata:
|
43
|
+
homepage_uri: https://github.com/kolasss/not_monads
|
44
|
+
source_code_uri: https://github.com/kolasss/not_monads
|
45
|
+
changelog_uri: https://github.com/kolasss/not_monads/blob/master/CHANGELOG.md
|
46
|
+
rubygems_mfa_required: 'true'
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 3.0.0
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubygems_version: 3.5.3
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Simple service objects
|
66
|
+
test_files: []
|