rails-on-sorbet 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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +204 -0
- data/Rakefile +16 -0
- data/lib/rails/on/sorbet/active_record_serializer.rb +77 -0
- data/lib/rails/on/sorbet/alias_association.rb +46 -0
- data/lib/rails/on/sorbet/current_attributes.rb +53 -0
- data/lib/rails/on/sorbet/map.rb +21 -0
- data/lib/rails/on/sorbet/map.rbi +935 -0
- data/lib/rails/on/sorbet/shims.rbi +598 -0
- data/lib/rails/on/sorbet/timelike.rb +5 -0
- data/lib/rails/on/sorbet/version.rb +9 -0
- data/lib/rails/on/sorbet.rb +18 -0
- data/lib/tapioca/dsl/compilers/rails_on_sorbet_active_record_serializer.rb +52 -0
- data/lib/tapioca/dsl/compilers/rails_on_sorbet_alias_association.rb +52 -0
- data/lib/tapioca/dsl/compilers/rails_on_sorbet_currrent_attributes.rb +57 -0
- metadata +102 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Tapioca
|
5
|
+
module Compilers
|
6
|
+
# Creates .rbi files with types for classes that use `alias_association`
|
7
|
+
#
|
8
|
+
#: [ConstantType = Class & ::Rails::On::Sorbet::AliasAssociation]
|
9
|
+
class RailsOnSorbetAliasAssociation < Tapioca::Dsl::Compiler
|
10
|
+
class << self
|
11
|
+
# @override
|
12
|
+
#: -> Enumerable[Module]
|
13
|
+
def gather_constants
|
14
|
+
all_classes.select do |klass|
|
15
|
+
klass.singleton_class < ::Rails::On::Sorbet::AliasAssociation
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# @override
|
21
|
+
#:-> void
|
22
|
+
def decorate
|
23
|
+
definitions = constant._alias_association_definitions
|
24
|
+
return unless definitions.present?
|
25
|
+
|
26
|
+
root.create_path(constant) do |klass|
|
27
|
+
definitions.each do |alias_name, target_name|
|
28
|
+
create_aliases(klass, alias_name, target_name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
#: (RBI::Scope, Symbol, Symbol) -> void
|
34
|
+
def create_aliases(klass, alias_name, target_name)
|
35
|
+
association = constant.reflect_on_all_associations.find { |e| e.name == target_name }
|
36
|
+
type_string = association.class_name.to_s
|
37
|
+
type = "T.nilable(#{type_string})"
|
38
|
+
|
39
|
+
klass.create_method(
|
40
|
+
alias_name.to_s,
|
41
|
+
return_type: type,
|
42
|
+
)
|
43
|
+
|
44
|
+
klass.create_method(
|
45
|
+
"#{alias_name}=",
|
46
|
+
parameters: [create_param('val', type: type)],
|
47
|
+
return_type: 'void',
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Tapioca
|
5
|
+
module Compilers
|
6
|
+
#: [ConstantType = Class & ::Rails::On::Sorbet::CurrentAttributes]
|
7
|
+
class RailsOnSorbetCurrentAttributes < Tapioca::Dsl::Compiler
|
8
|
+
|
9
|
+
class << self
|
10
|
+
# @override
|
11
|
+
#: -> Enumerable[Module]
|
12
|
+
def gather_constants
|
13
|
+
all_classes.select do |klass|
|
14
|
+
klass.singleton_class < ::Rails::On::Sorbet::CurrentAttributes
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
MOD_NAME = 'RailsOnSorbetCurrentAttributeMethods'
|
20
|
+
|
21
|
+
# @override
|
22
|
+
#: -> void
|
23
|
+
def decorate
|
24
|
+
root.create_path(constant) do |klass|
|
25
|
+
mod = klass.create_module(MOD_NAME)
|
26
|
+
klass.create_include(MOD_NAME)
|
27
|
+
klass.create_extend(MOD_NAME)
|
28
|
+
attrs = constant.attribute_map.sort_by do |key, _|
|
29
|
+
key.to_s
|
30
|
+
end
|
31
|
+
# For each setting accessor defined in the class
|
32
|
+
attrs.each do |attr_name, attr_type|
|
33
|
+
attr_type_str = attr_type.type.to_s
|
34
|
+
doc = attr_type.doc
|
35
|
+
comments = []
|
36
|
+
comments << RBI::Comment.new(doc) if doc
|
37
|
+
# Create the RBI definitions for all the missing methods
|
38
|
+
mod.create_method(
|
39
|
+
attr_name.to_s,
|
40
|
+
comments:,
|
41
|
+
return_type: attr_type_str,
|
42
|
+
)
|
43
|
+
mod.create_method(
|
44
|
+
"#{attr_name}=",
|
45
|
+
comments:,
|
46
|
+
parameters: [create_param('value', type: attr_type_str)],
|
47
|
+
return_type: attr_type_str,
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-on-sorbet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mateusz Drewniak
|
8
|
+
- Espago
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: booleans
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '7.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '7.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sorbet-runtime
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.6'
|
55
|
+
description: A Rails extension that expands support for sorbet
|
56
|
+
email:
|
57
|
+
- matmg24@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- CHANGELOG.md
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- lib/rails/on/sorbet.rb
|
67
|
+
- lib/rails/on/sorbet/active_record_serializer.rb
|
68
|
+
- lib/rails/on/sorbet/alias_association.rb
|
69
|
+
- lib/rails/on/sorbet/current_attributes.rb
|
70
|
+
- lib/rails/on/sorbet/map.rb
|
71
|
+
- lib/rails/on/sorbet/map.rbi
|
72
|
+
- lib/rails/on/sorbet/shims.rbi
|
73
|
+
- lib/rails/on/sorbet/timelike.rb
|
74
|
+
- lib/rails/on/sorbet/version.rb
|
75
|
+
- lib/tapioca/dsl/compilers/rails_on_sorbet_active_record_serializer.rb
|
76
|
+
- lib/tapioca/dsl/compilers/rails_on_sorbet_alias_association.rb
|
77
|
+
- lib/tapioca/dsl/compilers/rails_on_sorbet_currrent_attributes.rb
|
78
|
+
homepage: https://github.com/espago/rails-on_sorbet
|
79
|
+
licenses: []
|
80
|
+
metadata:
|
81
|
+
homepage_uri: https://github.com/espago/rails-on_sorbet
|
82
|
+
source_code_uri: https://github.com/espago/rails-on_sorbet
|
83
|
+
changelog_uri: https://raw.githubusercontent.com/espago/rails-on_sorbet/refs/heads/main/CHANGELOG.md
|
84
|
+
rubygems_mfa_required: 'true'
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 3.3.0
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubygems_version: 3.6.9
|
100
|
+
specification_version: 4
|
101
|
+
summary: A Rails extension that expands support for sorbet
|
102
|
+
test_files: []
|