roda-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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d32c5507cf9f2449bc36e21d29f1eeb087217928
4
+ data.tar.gz: 9f4d68448df122254a7ddab8eff885ad37abd2b5
5
+ SHA512:
6
+ metadata.gz: 4610b2553db33325da092ff3748692a2432677669e97b737ec39524cb2c13423be509c7b980c0441fb019a75131c311b4df0e2db1733bd799fbfd96d73fb208f
7
+ data.tar.gz: eea560dca3c96ac5365b19386230a04a2dd355c3abf26cdbd61947c4b57c65f2854491893a33498a169a965d91d6cb4e818e64727a29b8ea7c9d56db264b984e
data/.dockerignore ADDED
@@ -0,0 +1,98 @@
1
+ ### Ruby template
2
+ *.gem
3
+ *.rbc
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/examples.txt
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ # Used by dotenv library to load environment variables.
15
+ .env
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /rdoc/
21
+
22
+ ## Environment normalization:
23
+ /.bundle/
24
+ /vendor/bundle
25
+ /lib/bundler/man/
26
+ /.bundle
27
+
28
+ # Vojo is the gem, so ignore these files since the code is intended to run
29
+ # in multiple environments:
30
+ .ruby-version
31
+ .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+ ### JetBrains template
36
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
37
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
38
+
39
+ # User-specific stuff:
40
+ .idea/workspace.xml
41
+ .idea/tasks.xml
42
+
43
+ # Sensitive or high-churn files:
44
+ .idea/dataSources/
45
+ .idea/dataSources.ids
46
+ .idea/dataSources.xml
47
+ .idea/dataSources.local.xml
48
+ .idea/sqlDataSources.xml
49
+ .idea/dynamic.xml
50
+ .idea/uiDesigner.xml
51
+
52
+ # Gradle:
53
+ .idea/gradle.xml
54
+ .idea/libraries
55
+
56
+ # Mongo Explorer plugin:
57
+ .idea/mongoSettings.xml
58
+
59
+ ## File-based project format:
60
+ *.iws
61
+
62
+ ## Plugin-specific files:
63
+
64
+ # IntelliJ
65
+ /out/
66
+
67
+ # mpeltonen/sbt-idea plugin
68
+ .idea_modules/
69
+
70
+ # JIRA plugin
71
+ atlassian-ide-plugin.xml
72
+
73
+ # Crashlytics plugin (for Android Studio and IntelliJ)
74
+ com_crashlytics_export_strings.xml
75
+ crashlytics.properties
76
+ crashlytics-build.properties
77
+ fabric.properties
78
+ ### Rails template
79
+ capybara-*.html
80
+ .rspec
81
+ /log
82
+ /tmp
83
+ /db/*.sqlite3
84
+ /db/*.sqlite3-journal
85
+ /public/system
86
+ /spec/tmp
87
+ **.orig
88
+ rerun.txt
89
+ pickle-email-*.html
90
+
91
+ # Only include if you have production secrets in this file, which is no longer a Rails default
92
+ # config/secrets.yml
93
+
94
+ # Ignore Byebug command history file.
95
+ .byebug_history
96
+
97
+ # Ignore Git repositories
98
+ .git
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.ruby-version
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,71 @@
1
+ # See documentation at https://docs.gitlab.com/ee/ci/yaml/README.html
2
+ variables:
3
+ CI_REGISTRY_IMAGE_CURRENT: $CI_REGISTRY_IMAGE:$CI_BUILD_REF_NAME
4
+ CI_REGISTRY_IMAGE_LATEST: $CI_REGISTRY_IMAGE:latest
5
+ CI_REGISTRY_IMAGE_STABLE: $CI_REGISTRY_IMAGE:stable
6
+
7
+ .docker_build: &docker
8
+ image: docker:latest
9
+ services:
10
+ - docker:dind
11
+ before_script:
12
+ - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
13
+
14
+ .ruby_build: &ruby
15
+ image: $CI_REGISTRY_IMAGE_CURRENT
16
+ # Cache gems in between builds
17
+ cache:
18
+ paths:
19
+ - /cache
20
+ # This is a basic example for a gem or script which doesn't use
21
+ # services such as redis or postgres
22
+ before_script:
23
+ - bundle install -j $(nproc) --path=/vendor/bundle # (Re)Bundle dependencies
24
+
25
+ .release_docker_image: &release_docker_image
26
+ <<: *docker
27
+ stage: deploy
28
+ script:
29
+ - echo "Releasing ${$TARGET_IMAGE} from $CI_REGISTRY_IMAGE_CURRENT"
30
+ - docker pull $CI_REGISTRY_IMAGE_CURRENT
31
+ - docker tag $CI_REGISTRY_IMAGE_CURRENT ${$TARGET_IMAGE}
32
+ - docker push ${$TARGET_IMAGE}
33
+
34
+ build:
35
+ <<: *docker
36
+ stage: build
37
+ script:
38
+ - echo "Building ${CI_REGISTRY_IMAGE_CURRENT}"
39
+ - docker build --pull -t $CI_REGISTRY_IMAGE_CURRENT .
40
+ - docker push $CI_REGISTRY_IMAGE_CURRENT
41
+
42
+ style:
43
+ <<: *ruby
44
+ script: bin/rubocop
45
+ artifacts:
46
+ paths:
47
+ - doc/rubocop.html
48
+ - tmp/ci
49
+
50
+ specification:
51
+ <<: *ruby
52
+ script: bin/rake spec
53
+ artifacts:
54
+ paths:
55
+ - doc/spec.html
56
+ - coverage
57
+ - tmp/ci
58
+
59
+ documentation:
60
+ <<: *ruby
61
+ script: bin/rake doc
62
+ artifacts:
63
+ paths:
64
+ - rdoc
65
+
66
+ gem:
67
+ <<: *ruby
68
+ script: bin/rake build
69
+ artifacts:
70
+ paths:
71
+ - pkg
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+ DefaultFormatter: fuubar
4
+ DisplayCopNames: true
5
+ ExtraDetails: true
6
+ Exclude:
7
+ - spec/**/*.rb
8
+ - vendor/**/*.rb
9
+
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - rakelib/**/*.rb
13
+ - spec/**/*.rb
14
+ - vendor/**/*.rb
15
+
16
+ # It is 2017, UTF time!
17
+ Style/AsciiComments:
18
+ Enabled: false
data/.simplecov ADDED
@@ -0,0 +1,6 @@
1
+
2
+ SimpleCov.start do
3
+ add_filter '/spec/'
4
+ add_group('Missing') { |src| src.covered_percent < 100 }
5
+ add_group('Covered') { |src| src.covered_percent == 100 }
6
+ end
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.13.7
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at alex@semyonov.us. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Dockerfile ADDED
@@ -0,0 +1,11 @@
1
+ FROM ruby:2.4
2
+
3
+ RUN gem install bundler --no-ri --no-rdoc
4
+
5
+ RUN mkdir /gem
6
+ WORKDIR /gem
7
+
8
+ ADD lib/roda/monads/version.rb /gem/lib/roda/monads/version.rb
9
+ ADD *.gemspec /gem/
10
+ ADD Gemfile /gem/Gemfile
11
+ RUN bundle install -j $(nproc) --path=/vendor/bundle
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ # Specify your gem's dependencies in roda-monads.gemspec
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Alex Semyonov
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,41 @@
1
+ # Roda::Monads
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
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'roda-monads'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install roda-monads
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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
+
31
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/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
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ require 'bundler/setup'
3
+
4
+ task default: %i(spec cop bundle:audit doc)
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'roda/monads'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start
data/bin/rake ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rake' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require 'pathname'
11
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require 'rubygems'
15
+ require 'bundler/setup'
16
+
17
+ load Gem.bin_path('rake', 'rake')
data/bin/rspec ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rspec' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require 'pathname'
11
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require 'rubygems'
15
+ require 'bundler/setup'
16
+
17
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/rubocop ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rubocop' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require 'pathname'
11
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require 'rubygems'
15
+ require 'bundler/setup'
16
+
17
+ load Gem.bin_path('rubocop', 'rubocop')
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/yard ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'yard' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require 'pathname'
11
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require 'rubygems'
15
+ require 'bundler/setup'
16
+
17
+ load Gem.bin_path('yard', 'yard')
data/bin/yardoc ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'yardoc' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require 'pathname'
11
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require 'rubygems'
15
+ require 'bundler/setup'
16
+
17
+ load Gem.bin_path('yard', 'yardoc')
data/bin/yri ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'yri' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require 'pathname'
11
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require 'rubygems'
15
+ require 'bundler/setup'
16
+
17
+ load Gem.bin_path('yard', 'yri')
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Roda
4
+ module Monads
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ require 'roda/monads/version'
3
+ require 'roda'
4
+ require 'roda/plugins/monads'
5
+
6
+ class Roda
7
+ # `DRY::Monads` and `Roda` integration.
8
+ module Monads
9
+ end
10
+ end
@@ -0,0 +1,136 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'roda'
4
+ require 'dry-monads'
5
+
6
+ class Roda
7
+ # Module containing `Roda` plugins.
8
+ module RodaPlugins
9
+ # Makes `Roda` understand `Dry::Monads::Either` monad and provide results
10
+ # based on `Right` or `Left` monad handler.
11
+ #
12
+ # @see Monads::RequestMethods
13
+ # @see Monads::InstanceMethods
14
+ #
15
+ # @example
16
+ # plugin :monads
17
+ # route do |r|
18
+ # r.on '/right' do
19
+ # Right('Alright!')
20
+ # end
21
+ # r.on '/left' do
22
+ # Left('Wrong!')
23
+ # end
24
+ # r.on '/rack' do
25
+ # r.on '/right' do
26
+ # Right([:ok, {}, ['Alright!']])
27
+ # end
28
+ # r.on '/left' do
29
+ # Left('Wrong!')
30
+ # end
31
+ # end
32
+ # end
33
+ module Monads
34
+ # Loads `Dry::Monads` gem
35
+ # @param [Roda] app
36
+ # @raise [LoadError] if gem `dry-monads` cannot be loaded
37
+ def self.load_dependencies(app, *)
38
+ app.plugin :symbol_status
39
+ end
40
+
41
+ # Extends `app` with `Dry::Monads::Either::Mixin` to create monads easily
42
+ # @param [Roda] app
43
+ def self.configure(app, *)
44
+ app.extend Dry::Monads::Either::Mixin
45
+ app.include Dry::Monads::Either::Mixin
46
+ app.either_matcher(:right,
47
+ aliases: [:value]) { |either| match_right(either) }
48
+ app.either_matcher(:left,
49
+ aliases: [:status]) { |status| match_left(status) }
50
+ app.either_matcher(:either) { |either| match_either(either) }
51
+ app.either_matcher(:rack_either) { |value| match_rack_either(value) }
52
+ end
53
+
54
+ # Extends `Roda` class interface with {ClassMethods#either_matcher} method
55
+ module ClassMethods
56
+ # @param name [Symbol] name
57
+ # @param aliases [<Symbol>] aliases
58
+ # @param matcher [Proc] matcher
59
+ # @return [Proc]
60
+ def either_matcher(name = :either, aliases: [], &matcher)
61
+ @matchers ||= {}
62
+ @matchers[name] = matcher if block_given?
63
+ aliases.each { |alt| @matchers[alt] = @matchers[name] }
64
+ @matchers[name]
65
+ end
66
+ end
67
+
68
+ # Extends {Roda::RodaRequest#block_result}’s with an ability to respond to
69
+ # `Dry::Monads::Either` or compatible object (that responds to
70
+ # `#to_either` method, returning `Dry::Monads::Either`).
71
+ module RequestMethods
72
+ # Handle match block return values. By default, if a string is given
73
+ # and the response is empty, use the string as the response body.
74
+ def block_result(result)
75
+ return super(result) unless result.respond_to?(:to_either)
76
+ respond_with_either(result)
77
+ end
78
+
79
+ private
80
+
81
+ # @param [Dry::Monads::Either, #to_either] either
82
+ def match_either(either)
83
+ either = either.to_either if respond_to?(:to_either)
84
+ matcher = if rack_either?(either)
85
+ :rack_either
86
+ elsif either.right?
87
+ :right
88
+ else
89
+ :left
90
+ end
91
+ instance_exec(either, &roda_class.either_matcher(matcher))
92
+ end
93
+
94
+ # @param [Dry::Monads::Either::Right] either
95
+ def match_right(either)
96
+ return false unless either.right?
97
+ populate_body(either.value)
98
+ true
99
+ end
100
+
101
+ # @param [Dry::Monads::Either::Left] either
102
+ def match_left(either)
103
+ return false unless either.left?
104
+ response.status, body = either.value
105
+ populate_body(body)
106
+ true
107
+ end
108
+
109
+ def match_rack_either(either)
110
+ response.status, headers, body = either.value
111
+ headers.each { |header, value| response.headers[header] = value }
112
+ populate_body(body)
113
+ true
114
+ end
115
+
116
+ # @param [Dry::Monads::Either] either
117
+ def rack_either?(either)
118
+ either.value.is_a?(Array) && either.value.size == 3
119
+ end
120
+
121
+ # @param [String, Object] body
122
+ def populate_body(body)
123
+ response.write block_result_body(body) if response.empty?
124
+ end
125
+
126
+ # @param [Dry::Monads::Either, #to_either] either
127
+ # @return [void]
128
+ def respond_with_either(either)
129
+ instance_exec either, &roda_class.either_matcher(:either)
130
+ end
131
+ end
132
+ end
133
+
134
+ register_plugin :monads, Monads
135
+ end
136
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ require 'bundler/audit/task'
3
+
4
+ Bundler::Audit::Task.new
@@ -0,0 +1,2 @@
1
+ # frozen_string_literal: true
2
+ require 'bundler/gem_tasks'
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new :spec do |t|
5
+ t.rspec_path = 'bin/rspec'
6
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ require 'rubocop/rake_task'
3
+ require 'rubocop'
4
+
5
+ RuboCop::RakeTask.new(:cop)
data/rakelib/yard.rake ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ require 'yard'
3
+ require 'yard/rake/yardoc_task'
4
+
5
+ YARD::Rake::YardocTask.new :doc
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'roda/monads/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'roda-monads'
9
+ spec.version = Roda::Monads::VERSION
10
+ spec.authors = ['Alex Semyonov']
11
+ spec.email = ['alex@semyonov.us']
12
+
13
+ spec.summary = 'Roda matchers for DRY::Monads'
14
+ spec.description = 'Reuse business logic operations in Roda'
15
+ spec.homepage = 'http://alsemyonov.gitlab.com/pages/'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_runtime_dependency 'roda', '~> 2.21.0'
26
+ spec.add_runtime_dependency 'dry-monads', '~> 0.2.1'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.13'
29
+ spec.add_development_dependency 'bundler-audit', '~> 0.5.0'
30
+ spec.add_development_dependency 'rack-test', '~> 0.6.3'
31
+ spec.add_development_dependency 'rake', '~> 12.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.5'
33
+ spec.add_development_dependency 'rspec-its', '~> 1.2.0'
34
+ spec.add_development_dependency 'rubocop', '~> 0.47.0'
35
+ spec.add_development_dependency 'simplecov', '~> 0.12.0'
36
+ spec.add_development_dependency 'yard', '~> 0.9.5'
37
+ end
metadata ADDED
@@ -0,0 +1,228 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roda-monads
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alex Semyonov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: roda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.21.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.21.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-monads
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler-audit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.5.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.5.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.6.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.6.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '12.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '12.0'
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
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.2.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.2.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.47.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.47.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.12.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.12.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: yard
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.9.5
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.9.5
167
+ description: Reuse business logic operations in Roda
168
+ email:
169
+ - alex@semyonov.us
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".dockerignore"
175
+ - ".gitignore"
176
+ - ".gitlab-ci.yml"
177
+ - ".rspec"
178
+ - ".rubocop.yml"
179
+ - ".simplecov"
180
+ - ".travis.yml"
181
+ - CODE_OF_CONDUCT.md
182
+ - Dockerfile
183
+ - Gemfile
184
+ - LICENSE.txt
185
+ - README.md
186
+ - Rakefile
187
+ - bin/console
188
+ - bin/rake
189
+ - bin/rspec
190
+ - bin/rubocop
191
+ - bin/setup
192
+ - bin/yard
193
+ - bin/yardoc
194
+ - bin/yri
195
+ - lib/roda/monads.rb
196
+ - lib/roda/monads/version.rb
197
+ - lib/roda/plugins/monads.rb
198
+ - rakelib/bundle_audit.rake
199
+ - rakelib/bundler.rake
200
+ - rakelib/rspec.rake
201
+ - rakelib/rubocop.rake
202
+ - rakelib/yard.rake
203
+ - roda-monads.gemspec
204
+ homepage: http://alsemyonov.gitlab.com/pages/
205
+ licenses:
206
+ - MIT
207
+ metadata: {}
208
+ post_install_message:
209
+ rdoc_options: []
210
+ require_paths:
211
+ - lib
212
+ required_ruby_version: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ required_rubygems_version: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ requirements: []
223
+ rubyforge_project:
224
+ rubygems_version: 2.6.10
225
+ signing_key:
226
+ specification_version: 4
227
+ summary: Roda matchers for DRY::Monads
228
+ test_files: []