forked from sorbet/sorbet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMixinEncryptedProp.h
42 lines (37 loc) · 1.24 KB
/
MixinEncryptedProp.h
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
#ifndef SORBET_REWRITER_MIXIN_ENCRYPTED_PROP_H
#define SORBET_REWRITER_MIXIN_ENCRYPTED_PROP_H
#include "ast/ast.h"
namespace sorbet::rewriter {
/**
* This class desugars things of the form
*
* encrypted_prop :foo
*
* into
*
* sig {returns(T.nilable(String))}
* def foo; T.cast(nil, T.nilable(String)); end
* sig {params(arg0: String).returns(NilClass)}
* def foo=(arg0); end
* sig {returns(T.nilable(String))}
* def encrypted_foo; T.cast(nil, T.nilable(String)); end
* sig {params(arg0: String).returns(NilClass)}
* def encrypted_foo=(arg0); end
*
* We try to implement a simple approximation of the functionality that
* M::Mixins::Encryptable.encrypted_prop has. This isn't full fidelity, but we're trying to
* straddle the line between complexity and usefulness. Specifically:
*
* Any `encrypted_prop` method call in a class body whose shape matches is considered.
* The getter will return `T.nilable(String)` and the setter will take `String`.
*
* Any deviation from this expected shape stops the desugaring.
*
*/
class MixinEncryptedProp final {
public:
static std::vector<ast::ExpressionPtr> run(core::MutableContext ctx, ast::Send *send);
MixinEncryptedProp() = delete;
};
} // namespace sorbet::rewriter
#endif