not_monads 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e9974bab26e9af1e3ec8fad57c6b72b706bcbc1933fed1ec606050103252bb3
4
- data.tar.gz: 560ddae392216cc701cc94281471084c22dd9042f44e561b80cfe7a76fb98f36
3
+ metadata.gz: 51ce5c00e76f8aa00897fc8a93c27a0a3557814c55a7841446a4d649133a47c4
4
+ data.tar.gz: c68de7cd3dae2961d8ba53c6ce52cc00030403d91f707bebf68ef682abe4130d
5
5
  SHA512:
6
- metadata.gz: bf6b4273f3e41abd484a1022fb1475431b73dc3ee60a0c7df5ecca9939e55bb8e40bcae2b05f8989cb2315200fd5b426ebd7f9d51b907c1961121f00ef4dc5b4
7
- data.tar.gz: e658304d770247652411c4855f670d367119916dd132d720ff57a9a374a67c4adac16021adcbf6c8c38b0c65e24930366d56c715af04fc4f307488a21d4eefac
6
+ metadata.gz: 1027b7cc8cabdb8607dd164d23f4e5405400733eb0dde1bf0d40071a8deabc7ae731aa2e77531e881a7b77b031bc2772a106771b9605907310110e3bfa0cd031
7
+ data.tar.gz: 7bfb1f258c6afd7dc99861031bdb5e9402d49b66133d61afa9ee5348b71e070bc92fc1f879504512a67c0cfaa8cdc1a0fae3e125f77e7bfb3f5e6a1d82a28b39
@@ -1,4 +1,3 @@
1
- version: '3.4'
2
1
  services:
3
2
  # Update this to the name of the service you want to work with in your docker-compose.yml file
4
3
  not_monads:
data/.dockerignore CHANGED
@@ -1,25 +1,28 @@
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
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
26
+
27
+ .DS_Store
28
+ */**/.DS_Store
data/.rubocop.yml CHANGED
@@ -1,11 +1,11 @@
1
- require:
1
+ plugins:
2
2
  - rubocop-rake
3
3
  - rubocop-rspec
4
4
  - rubocop-performance
5
5
  - rubocop-thread_safety
6
6
 
7
7
  AllCops:
8
- TargetRubyVersion: 3.0
8
+ TargetRubyVersion: 3.1
9
9
  NewCops: enable
10
10
 
11
11
  Style/Documentation:
data/Dockerfile CHANGED
@@ -1,8 +1,11 @@
1
- FROM ruby:3.3-alpine
1
+ FROM ruby:3.3.6-alpine
2
2
 
3
3
  LABEL Name=not_monads Version=0.1.0
4
4
 
5
- RUN apk add --update git
5
+ RUN apk add --update \
6
+ build-base \
7
+ git \
8
+ openssh-client
6
9
 
7
10
  # throw errors if Gemfile has been modified since Gemfile.lock
8
11
  # RUN bundle config --global frozen 1
data/README.md CHANGED
@@ -20,13 +20,13 @@ If bundler is not being used to manage dependencies, install the gem by executin
20
20
 
21
21
  Add module to your class with prepend:
22
22
 
23
- ```
23
+ ```ruby
24
24
  class CreateUser
25
25
  prepend NotMonads::Do[:call]
26
26
 
27
27
  def call(params)
28
- do_something validate(params)
29
- user = do_something save(params)
28
+ doit validate(params)
29
+ user = doit save(params)
30
30
  Success(user)
31
31
  end
32
32
 
@@ -43,14 +43,40 @@ class CreateUser
43
43
  end
44
44
  ```
45
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)
46
+ Prepend with a module call with array of method names in square brackets. (`prepend NotMonads::Do[:call, :step1, :step3]`) Use method `doit` to verify result, just like dry-monads with `yield`.
47
+
48
+ Then you can access result just like in dry-monads:
49
+
50
+ For success
51
+
52
+ ```ruby
53
+ result = CreateUser.new.call(params)
54
+ result.success? # true
55
+ result.value! # User#123
56
+ result.value_or(42) # User#123
57
+ ```
58
+
59
+ For failure
47
60
 
61
+ ```ruby
62
+ result = CreateUser.new.call(params)
63
+ result.success? # false
64
+ result.value! # raises NotMonads::Error
65
+ result.value_or(42) # 42
66
+ result.failure # user.errors
67
+ ```
48
68
 
49
69
  ## Development
50
70
 
51
71
  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
72
 
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).
73
+ To install this gem onto your local machine, run `bundle exec rake install`.
74
+
75
+ 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).
76
+
77
+ To release from docker container make sure your host have access to key `ssh-add -l` and `ssh -T git@github.com`, if no access run `ssh-add`. Then you can release with `bundle exec rake release`.
78
+
79
+ To run specs `bundle exec rspec`, to run rubocop `bundle exec rubocop`.
54
80
 
55
81
  ## License
56
82
 
data/docker-compose.yml CHANGED
@@ -1,5 +1,3 @@
1
- version: '3.4'
2
-
3
1
  services:
4
2
  not_monads:
5
3
  image: not_monads
@@ -10,6 +8,11 @@ services:
10
8
  volumes:
11
9
  - .:/app:cached
12
10
  - bundle:/usr/local/bundle
11
+ - type: bind
12
+ source: /run/host-services/ssh-auth.sock
13
+ target: /run/host-services/ssh-auth.sock
14
+ environment:
15
+ - SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock
13
16
 
14
17
  volumes:
15
18
  bundle:
data/lib/not_monads/do.rb CHANGED
@@ -15,8 +15,8 @@ module NotMonads
15
15
  end
16
16
  # rubocop:enable Naming/MethodName
17
17
 
18
- def do_something(result)
19
- return result.success if result.success?
18
+ def doit(result)
19
+ return result.value! if result.success?
20
20
 
21
21
  halt(result)
22
22
  end
@@ -2,14 +2,11 @@
2
2
 
3
3
  module NotMonads
4
4
  class Result
5
- attr_reader :success, :failure
5
+ def initialize(value)
6
+ @value = value
7
+ end
6
8
 
7
9
  class Success < Result
8
- def initialize(value)
9
- super()
10
- @success = value
11
- end
12
-
13
10
  def failure?
14
11
  false
15
12
  end
@@ -19,16 +16,16 @@ module NotMonads
19
16
  end
20
17
 
21
18
  def to_s
22
- "Success(#{success.inspect})"
19
+ "Success(#{value!.inspect})"
23
20
  end
24
21
  alias inspect to_s
25
22
 
26
23
  def value!
27
- success
24
+ @value
28
25
  end
29
26
 
30
27
  def value_or(_val = nil)
31
- success
28
+ @value
32
29
  end
33
30
 
34
31
  def ==(other)
@@ -41,11 +38,6 @@ module NotMonads
41
38
  end
42
39
 
43
40
  class Failure < Result
44
- def initialize(value)
45
- super()
46
- @failure = value
47
- end
48
-
49
41
  def failure?
50
42
  true
51
43
  end
@@ -71,6 +63,10 @@ module NotMonads
71
63
  end
72
64
  end
73
65
 
66
+ def failure
67
+ @value
68
+ end
69
+
74
70
  def ==(other)
75
71
  other.is_a?(self.class) && failure == other.failure
76
72
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NotMonads
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: not_monads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kolas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-10 00:00:00.000000000 Z
11
+ date: 2025-03-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Simple copy of [dry-monads](https://github.com/dry-rb/dry-monads) do
14
14
  monads, it implements only mixin for your service object and Success/Failure result
@@ -52,14 +52,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: 3.0.0
55
+ version: 3.1.0
56
56
  required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  requirements: []
62
- rubygems_version: 3.5.3
62
+ rubygems_version: 3.5.22
63
63
  signing_key:
64
64
  specification_version: 4
65
65
  summary: Simple service objects