-
-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathdo.rbs
More file actions
102 lines (89 loc) · 2.56 KB
/
Copy pathdo.rbs
File metadata and controls
102 lines (89 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
module Dry
module Monads
# An implementation of do-notation.
#
# @see Do.for
module Do
extend Mixin
VISIBILITY_WORD: untyped
# @api private
class Halt < StandardError
# @api private
attr_reader result: untyped
def initialize: (untyped result) -> untyped
end
# @api private
class MethodTracker < ::Module
# @api private
def initialize: (untyped tracked_methods, untyped base, untyped wrapper) -> untyped
end
# Generates a module that passes a block to methods
# that either unwraps a single-valued monadic value or halts
# the execution.
#
# @example A complete example
#
# class CreateUser
# include Dry::Monads::Result::Mixin
# include Dry::Monads::Try::Mixin
# include Dry::Monads::Do.for(:call)
#
# attr_reader :user_repo
#
# def initialize(:user_repo)
# @user_repo = user_repo
# end
#
# def call(params)
# json = yield parse_json(params)
# hash = yield validate(json)
#
# user_repo.transaction do
# user = yield create_user(hash[:user])
# yield create_profile(user, hash[:profile])
# end
#
# Success(user)
# end
#
# private
#
# def parse_json(params)
# Try(JSON::ParserError) {
# JSON.parse(params)
# }.to_result
# end
#
# def validate(json)
# UserSchema.(json).to_monad
# end
#
# def create_user(user_data)
# Try(Sequel::Error) {
# user_repo.create(user_data)
# }.to_result
# end
#
# def create_profile(user, profile_data)
# Try(Sequel::Error) {
# user_repo.create_profile(user, profile_data)
# }.to_result
# end
# end
#
# @param [Array<Symbol>] methods
# @return [Module]
def self.for: (*untyped methods) -> untyped
# @api private
def self.included: (untyped base) -> untyped
# @api private
def self.wrap_method: (untyped target, untyped method, untyped visibility) -> untyped
# @api private
def self.method_visibility: (untyped mod, untyped method) -> untyped
# @api private
def self.coerce_to_monad: (untyped monads) -> untyped
# @api private
def self.halt: (untyped result) -> untyped
end
end
end