roda-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 +5 -5
- data/Gemfile +1 -0
- data/README.md +55 -9
- data/Rakefile +2 -1
- data/bin/rake +1 -0
- data/bin/rspec +1 -0
- data/bin/rubocop +1 -0
- data/bin/yard +1 -0
- data/bin/yardoc +1 -0
- data/bin/yri +1 -0
- data/lib/roda/monads.rb +1 -0
- data/lib/roda/monads/version.rb +1 -1
- data/lib/roda/plugins/monads.rb +21 -20
- data/rakelib/bundle_audit.rake +1 -0
- data/rakelib/bundler.rake +1 -0
- data/rakelib/rspec.rake +1 -0
- data/rakelib/rubocop.rake +1 -0
- data/rakelib/yard.rake +1 -0
- data/roda-monads.gemspec +7 -8
- metadata +17 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dcb1258ede01bcd6c407276d0f610205d390d462407f184cf08b620e2d4226b1
|
4
|
+
data.tar.gz: 33f9686b70e5cb2373f546cf58171f512fa0fd97761623c9f481164db14ce6fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6770812d24035cc1860cea8ef7da931d66f9d297027f1438a6b72a8df7670a1a9e380fccdce6f49ab9cb33b307098eea5780aa9876c0a84e0bd0a31725286e24
|
7
|
+
data.tar.gz: 53ce5f6bad43d4aa7ed7a2881ac2dca0be5737ce0c3e0fd860d88bc7cae129c304d661e91f18d3ca9d77631094ae0fc454c85a3368680b6c55dbc79f5a717489
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# Roda::Monads
|
2
2
|
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/roda/monads`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
3
|
## Installation
|
8
4
|
|
9
5
|
Add this line to your application's Gemfile:
|
@@ -14,28 +10,78 @@ gem 'roda-monads'
|
|
14
10
|
|
15
11
|
And then execute:
|
16
12
|
|
17
|
-
|
13
|
+
```bash
|
14
|
+
bundle
|
15
|
+
```
|
18
16
|
|
19
17
|
Or install it yourself as:
|
20
18
|
|
21
|
-
|
19
|
+
```bash
|
20
|
+
gem install roda-monads
|
21
|
+
```
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
```ruby
|
26
|
+
require 'bundler/inline'
|
27
|
+
|
28
|
+
gemfile do
|
29
|
+
gem 'roda-monads'
|
30
|
+
end
|
31
|
+
|
32
|
+
class App < Roda
|
33
|
+
plugin :monads
|
34
|
+
|
35
|
+
route do |r|
|
36
|
+
r.on 'value' do
|
37
|
+
Success('Alright')
|
38
|
+
end
|
39
|
+
|
40
|
+
r.on 'status' do
|
41
|
+
Failure(:unauthorized)
|
42
|
+
end
|
43
|
+
|
44
|
+
r.on 'rack' do
|
45
|
+
r.on 'symbol' do
|
46
|
+
r.on 'right' do
|
47
|
+
Success([:ok, {}, 'OK'])
|
48
|
+
end
|
49
|
+
|
50
|
+
r.on 'left' do
|
51
|
+
Failure([:found, { 'Location' => '/rack_right' }, nil])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
r.on 'right' do
|
56
|
+
Success([200, {}, 'OK'])
|
57
|
+
end
|
58
|
+
|
59
|
+
r.on 'left' do
|
60
|
+
Failure([:unauthorized, {}, nil])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
r.on 'neither' do
|
65
|
+
'neither'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
```
|
26
70
|
|
27
71
|
## Development
|
28
72
|
|
29
73
|
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.
|
30
74
|
|
31
|
-
To install this gem onto your local machine, run `
|
75
|
+
To install this gem onto your local machine, run `bin/rake install`. To release a new version, update the version number in `version.rb`, and then run `bin/rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
76
|
|
33
77
|
## Contributing
|
34
78
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://gitlab.com/alsemyonov/roda-monads. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
80
|
|
37
81
|
|
38
82
|
## License
|
39
83
|
|
40
84
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
85
|
|
86
|
+
|
87
|
+
© [Alex Semyonov](https://alex.semyonov.us/), <[alex@semyonov.us](mailto:alex@semyonov.us?subject=roda-monads)> 2017
|
data/Rakefile
CHANGED
data/bin/rake
CHANGED
data/bin/rspec
CHANGED
data/bin/rubocop
CHANGED
data/bin/yard
CHANGED
data/bin/yardoc
CHANGED
data/bin/yri
CHANGED
data/lib/roda/monads.rb
CHANGED
data/lib/roda/monads/version.rb
CHANGED
data/lib/roda/plugins/monads.rb
CHANGED
@@ -6,8 +6,8 @@ require 'dry-monads'
|
|
6
6
|
class Roda
|
7
7
|
# Module containing `Roda` plugins.
|
8
8
|
module RodaPlugins
|
9
|
-
# Makes `Roda` understand `Dry::Monads::
|
10
|
-
# based on `
|
9
|
+
# Makes `Roda` understand `Dry::Monads::Result` monad and provide results
|
10
|
+
# based on `Success` or `Failure` monad handler.
|
11
11
|
#
|
12
12
|
# @see Monads::RequestMethods
|
13
13
|
# @see Monads::InstanceMethods
|
@@ -16,17 +16,17 @@ class Roda
|
|
16
16
|
# plugin :monads
|
17
17
|
# route do |r|
|
18
18
|
# r.on '/right' do
|
19
|
-
#
|
19
|
+
# Success('Alright!')
|
20
20
|
# end
|
21
21
|
# r.on '/left' do
|
22
|
-
#
|
22
|
+
# Failure('Wrong!')
|
23
23
|
# end
|
24
24
|
# r.on '/rack' do
|
25
25
|
# r.on '/right' do
|
26
|
-
#
|
26
|
+
# Success([:ok, {}, ['Alright!']])
|
27
27
|
# end
|
28
28
|
# r.on '/left' do
|
29
|
-
#
|
29
|
+
# Failure('Wrong!')
|
30
30
|
# end
|
31
31
|
# end
|
32
32
|
# end
|
@@ -38,11 +38,11 @@ class Roda
|
|
38
38
|
app.plugin :symbol_status
|
39
39
|
end
|
40
40
|
|
41
|
-
# Extends `app` with `Dry::Monads::
|
41
|
+
# Extends `app` with `Dry::Monads::Result::Mixin` to create monads easily
|
42
42
|
# @param [Roda] app
|
43
43
|
def self.configure(app, *)
|
44
|
-
app.extend Dry::Monads::
|
45
|
-
app.include Dry::Monads::
|
44
|
+
app.extend Dry::Monads::Result::Mixin
|
45
|
+
app.include Dry::Monads::Result::Mixin
|
46
46
|
app.either_matcher(:right,
|
47
47
|
aliases: [:value]) { |either| match_right(either) }
|
48
48
|
app.either_matcher(:left,
|
@@ -66,8 +66,8 @@ class Roda
|
|
66
66
|
end
|
67
67
|
|
68
68
|
# Extends {Roda::RodaRequest#block_result}’s with an ability to respond to
|
69
|
-
# `Dry::Monads::
|
70
|
-
# `#to_either` method, returning `Dry::Monads::
|
69
|
+
# `Dry::Monads::Result` or compatible object (that responds to
|
70
|
+
# `#to_either` method, returning `Dry::Monads::Result`).
|
71
71
|
module RequestMethods
|
72
72
|
# Handle match block return values. By default, if a string is given
|
73
73
|
# and the response is empty, use the string as the response body.
|
@@ -78,7 +78,7 @@ class Roda
|
|
78
78
|
|
79
79
|
private
|
80
80
|
|
81
|
-
# @param [Dry::Monads::
|
81
|
+
# @param [Dry::Monads::Result, #to_either] either
|
82
82
|
def match_either(either)
|
83
83
|
either = either.to_either if respond_to?(:to_either)
|
84
84
|
matcher = if rack_either?(either)
|
@@ -91,31 +91,32 @@ class Roda
|
|
91
91
|
instance_exec(either, &roda_class.either_matcher(matcher))
|
92
92
|
end
|
93
93
|
|
94
|
-
# @param [Dry::Monads::
|
94
|
+
# @param [Dry::Monads::Result::Success] either
|
95
95
|
def match_right(either)
|
96
96
|
return false unless either.right?
|
97
|
-
populate_body(either.
|
97
|
+
populate_body(either.success)
|
98
98
|
true
|
99
99
|
end
|
100
100
|
|
101
|
-
# @param [Dry::Monads::
|
101
|
+
# @param [Dry::Monads::Result::Failure] either
|
102
102
|
def match_left(either)
|
103
103
|
return false unless either.left?
|
104
|
-
response.status, body = either.
|
104
|
+
response.status, body = either.failure
|
105
105
|
populate_body(body)
|
106
106
|
true
|
107
107
|
end
|
108
108
|
|
109
109
|
def match_rack_either(either)
|
110
|
-
response.status, headers, body = either.
|
110
|
+
response.status, headers, body = either.value_or(&:itself)
|
111
111
|
headers.each { |header, value| response.headers[header] = value }
|
112
112
|
populate_body(body)
|
113
113
|
true
|
114
114
|
end
|
115
115
|
|
116
|
-
# @param [Dry::Monads::
|
116
|
+
# @param [Dry::Monads::Result] either
|
117
117
|
def rack_either?(either)
|
118
|
-
|
118
|
+
value = either.value_or(&:itself)
|
119
|
+
value.is_a?(Array) && value.size == 3
|
119
120
|
end
|
120
121
|
|
121
122
|
# @param [String, Object] body
|
@@ -123,7 +124,7 @@ class Roda
|
|
123
124
|
response.write block_result_body(body) if response.empty?
|
124
125
|
end
|
125
126
|
|
126
|
-
# @param [Dry::Monads::
|
127
|
+
# @param [Dry::Monads::Result, #to_either] either
|
127
128
|
# @return [void]
|
128
129
|
def respond_with_either(either)
|
129
130
|
instance_exec either, &roda_class.either_matcher(:either)
|
data/rakelib/bundle_audit.rake
CHANGED
data/rakelib/bundler.rake
CHANGED
data/rakelib/rspec.rake
CHANGED
data/rakelib/rubocop.rake
CHANGED
data/rakelib/yard.rake
CHANGED
data/roda-monads.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
# frozen_string_literal: true
|
3
|
-
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
require 'roda/monads/version'
|
6
6
|
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
|
13
13
|
spec.summary = 'Roda matchers for DRY::Monads'
|
14
14
|
spec.description = 'Reuse business logic operations in Roda'
|
15
|
-
spec.homepage = 'http://alsemyonov.gitlab.com/
|
15
|
+
spec.homepage = 'http://alsemyonov.gitlab.com/roda-monads/'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -22,16 +22,15 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ['lib']
|
24
24
|
|
25
|
-
spec.add_runtime_dependency '
|
26
|
-
spec.add_runtime_dependency '
|
25
|
+
spec.add_runtime_dependency 'dry-monads', '~> 0.4.0'
|
26
|
+
spec.add_runtime_dependency 'roda', '>= 2.21'
|
27
27
|
|
28
28
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
29
29
|
spec.add_development_dependency 'bundler-audit', '~> 0.5.0'
|
30
30
|
spec.add_development_dependency 'rack-test', '~> 0.6.3'
|
31
31
|
spec.add_development_dependency 'rake', '~> 12.0'
|
32
|
-
spec.add_development_dependency 'rspec', '~>
|
33
|
-
spec.add_development_dependency '
|
34
|
-
spec.add_development_dependency 'rubocop', '~> 0.47.0'
|
32
|
+
spec.add_development_dependency 'rspec-roda', '~> 0.1.0'
|
33
|
+
spec.add_development_dependency 'rubocop', '~> 0.57'
|
35
34
|
spec.add_development_dependency 'simplecov', '~> 0.12.0'
|
36
35
|
spec.add_development_dependency 'yard', '~> 0.9.5'
|
37
36
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roda-monads
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Semyonov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: dry-monads
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.4.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.4.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: roda
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '2.21'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '2.21'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,47 +95,33 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '12.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: rspec
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '3.5'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '3.5'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rspec-its
|
98
|
+
name: rspec-roda
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
101
|
- - "~>"
|
116
102
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.
|
103
|
+
version: 0.1.0
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
108
|
- - "~>"
|
123
109
|
- !ruby/object:Gem::Version
|
124
|
-
version: 1.
|
110
|
+
version: 0.1.0
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: rubocop
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
115
|
- - "~>"
|
130
116
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0.
|
117
|
+
version: '0.57'
|
132
118
|
type: :development
|
133
119
|
prerelease: false
|
134
120
|
version_requirements: !ruby/object:Gem::Requirement
|
135
121
|
requirements:
|
136
122
|
- - "~>"
|
137
123
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0.
|
124
|
+
version: '0.57'
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
126
|
name: simplecov
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -201,7 +187,7 @@ files:
|
|
201
187
|
- rakelib/rubocop.rake
|
202
188
|
- rakelib/yard.rake
|
203
189
|
- roda-monads.gemspec
|
204
|
-
homepage: http://alsemyonov.gitlab.com/
|
190
|
+
homepage: http://alsemyonov.gitlab.com/roda-monads/
|
205
191
|
licenses:
|
206
192
|
- MIT
|
207
193
|
metadata: {}
|
@@ -221,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
207
|
version: '0'
|
222
208
|
requirements: []
|
223
209
|
rubyforge_project:
|
224
|
-
rubygems_version: 2.6
|
210
|
+
rubygems_version: 2.7.6
|
225
211
|
signing_key:
|
226
212
|
specification_version: 4
|
227
213
|
summary: Roda matchers for DRY::Monads
|