This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'fiber' | |
| class RunState | |
| def call(fiber, state = {}, *xs) | |
| result = fiber.resume(*xs) | |
| if fiber.alive? | |
| op, *args = result | |
| case op | |
| when :read |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rack' | |
| require 'puma' | |
| require 'thread' | |
| class Middleware | |
| def initialize(app) | |
| @app = app | |
| @queue = Queue.new | |
| @thread = Thread.new { run_loop } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module MyValidation | |
| include Dry::Monads::Validated::Mixin | |
| def Invalid(message) | |
| super(message.to_s.split('_').map(&:capitalize).join(' ')) | |
| end | |
| end | |
| class CreateUser | |
| include MyValidation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Matcher | |
| def self.[](pattern) | |
| Class.new do | |
| define_singleton_method(:===) { |exc| pattern === exc.message } | |
| end | |
| end | |
| end | |
| begin | |
| 1 / 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Foo | |
| def self.===(obj) | |
| true | |
| end | |
| end | |
| begin | |
| 1 / 0 | |
| rescue Foo | |
| puts 'Rescued!' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def search_tags(query, tags) | |
| tag_queries = tags.map { |t| pattern(t) } | |
| query.where { tag_queries.reduce(`false`) { |acc, q| acc | array_to_string(self.tags, ',').ilike(q) } } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Templates < ROM::Relation[:sql] | |
| schema do | |
| attribute :possible_resolution_ids, Types::PG::Array('bigint') | |
| associations do | |
| has_many :resolutions, | |
| as: :possible_resolutions, | |
| relation: :resolutions, | |
| view: :for_possible_resolutions_in_templates, | |
| foreign_key: :template_id, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Maybe | |
| class Some < Maybe | |
| end | |
| class None | |
| end | |
| end | |
| class Result | |
| class Success < Result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'bundler/inline' | |
| gemfile do | |
| source 'https://rubygems.org' | |
| gem 'dry-auto_inject' | |
| gem 'dry-transaction' | |
| gem 'dry-container', git: 'https://github.com/dry-rb/dry-container' | |
| end | |
| class Container |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User < Dry::Struct | |
| MissingAttribute = Class.new(NameError) | |
| def name | |
| [first_name, last_name].join(' ') | |
| end | |
| attribute :name, Dry::Types['strict.string'] | |
| attribute :first_name, Dry::Types['strict.string'] |