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 Dry | |
module Types | |
class Hash < Definition | |
class Safe < Hash | |
def call(hash, meth = :call) | |
member_types.each_with_object({}) do |(key, type), result| | |
if hash.key?(key) | |
result[key] = type.__send__(meth, hash[key]) | |
elsif type.is_a?(Default) | |
result[key] = type.evaluate |
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 resolve_missing_value(result, key, type) | |
if type.is_a?(Default) | |
result[key] = type[type.evaluate] | |
else | |
result[key] = type[nil] | |
end | |
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 Dry | |
module Monad | |
class Either | |
attr_reader :right, :left | |
def ==(other) | |
other.is_a?(Either) && right == other.right && left == other.left | |
end | |
class Right < Either |
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 Dry | |
module Monad | |
class Maybe | |
def self.lift(value) | |
if value.nil? | |
None.instance | |
else | |
Some.new(value) | |
end | |
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 Users < ROM::Relation[:sql] | |
schema(:users) do | |
attribute :id, Types::Serial | |
attribute :name, Types::String | |
associate do | |
many :posts | |
many :labels, through: :posts | |
end | |
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.new(ROM::Repository[relation]) do | |
defines :mapping | |
commands :create, update: :by_id, delete: :by_id, mapper: mapping | |
self.mapping mapping | |
def find(id) | |
collection.by_id(id).one | |
end | |
def all |
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 Imprint | |
class Container | |
extend Dry::Container::Mixin | |
class << self | |
attr_reader :root | |
def register_dir(dir, eager: false, instantiate: true) | |
Dir["#{root}/#{dir}/**/*.rb"].map do |path| | |
name = path.sub("#{root}/", '').sub('.rb', '') |
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 Imprint | |
Import = Dry::AutoInject(Container) | |
KwargsImport = Import.kwargs | |
class << self | |
def inject(target) | |
-> *values { target.send(:include, KwargsImport[*values]) } | |
end | |
def args_inject(target) |
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 CommandPlugins | |
module ActiveRecordTimestamps | |
class HashWithTimestamps | |
def initialize(input) | |
@input = input | |
end | |
def [](*args) | |
tuple = @input[*args] |
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 Service | |
class TransactionWrapper | |
TransactionFailed = Class.new(StandardError) | |
attr_reader :sequence | |
delegate :append, :prepend, to: :sequence | |
def initialize(sequence, connection) | |
@sequence = sequence | |
@connection = connection |