sorbet_erb 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4076d96d59afeaf2c9f40b7c6cb176482b78ffc0b48e0d262cf71bdc4f49a8ce
4
- data.tar.gz: c697a0a90d4f9526fdac049f722a802f9f09f5c4a30c3c9447db3e3d0a7503bd
3
+ metadata.gz: 066514027114bf88c8a5fe55bf534b6fde19c739faa0ee8a95878a6a337e735c
4
+ data.tar.gz: b709e8f1e30f9280ce1143fd8348e1099b31b3f2040716557fd177caf6eb8b39
5
5
  SHA512:
6
- metadata.gz: 1cfc74f6346706dee3bec11195b74ed0328f1e304f084d732b74b255eb8f6c8817aa41b10f9df8a0fa9b5c4d1384caab7285ac54b32ea69fed64e5a553abf4a8
7
- data.tar.gz: f751e2301827f3f4b5a027689eb78e62b6adf821d3930688d6ad28a705bb43905a045d8d9cf971af603f5a93b7a3bf44bdb2c91eebf2a04f2f8a5389210ed762
6
+ metadata.gz: 47a69221db20d63363de18294e9132acf72bcef2a5a7fe25070f404a5461dab44f06ab2ada93bb6f6fbe082f80443ea3744404e259ffb2b42057c9a521702597
7
+ data.tar.gz: 71df4f5bf5bdc9e1c36c04862fad4911e164bb5904d5a449c8669bb9bd76cedc45e876102adcbd121ef6dc79d5b6e4494a70ee47de86c754727d47b885d297d8
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SorbetErb
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -30,31 +30,70 @@ module Tapioca
30
30
  def decorate
31
31
  root.create_path(constant) do |klass|
32
32
  T.unsafe(constant).registered_slots.each do |name, config|
33
- renderable_type = config[:renderable]
34
- renderable = T.let(
35
- case renderable_type
36
- when String
37
- renderable_type
38
- when Class
39
- T.must(renderable_type.name)
40
- else
41
- 'T.untyped'
42
- end,
43
- String
44
- )
45
-
46
33
  is_many = T.let(config[:collection], T::Boolean)
47
- return_type = renderable
48
34
 
49
35
  module_name = 'ViewComponentSlotablesMethodsModule'
50
36
  klass.create_module(module_name) do |mod|
51
- generate_instance_methods(mod, name.to_s, return_type, is_many)
37
+ if config[:renderable_hash]
38
+ generate_polymorphic_instance_methods(mod, name.to_s, config[:renderable_hash], is_many)
39
+ else
40
+ return_type = renderable_to_type_name(config[:renderable])
41
+
42
+ generate_instance_methods(mod, name.to_s, return_type, is_many)
43
+ end
52
44
  end
53
45
  klass.create_include(module_name)
54
46
  end
55
47
  end
56
48
  end
57
49
 
50
+ sig { params(input: T.untyped).returns(String) }
51
+ def renderable_to_type_name(input)
52
+ case input
53
+ when String
54
+ input
55
+ when Class
56
+ T.must(input.name)
57
+ else
58
+ 'T.untyped'
59
+ end
60
+ end
61
+
62
+ sig do
63
+ params(
64
+ klass: RBI::Scope,
65
+ slot_name: String,
66
+ underlying_types: T::Hash[Symbol, T.untyped],
67
+ is_many: T::Boolean
68
+ ).void
69
+ end
70
+ def generate_polymorphic_instance_methods(klass, slot_name, underlying_types, is_many)
71
+ # We want to signularize the slot name since it's used as the namespace
72
+ singular_slot_name =
73
+ if is_many
74
+ ActiveSupport::Inflector.singularize(slot_name)
75
+ else
76
+ slot_name
77
+ end
78
+
79
+ klass.create_method(slot_name, return_type: 'T.untyped') # TODO: should this be T.any of underlying types?
80
+ klass.create_method("#{slot_name}?", return_type: 'T::Boolean')
81
+
82
+ underlying_types.each do |name, config|
83
+ namespaced_name = "#{singular_slot_name}_#{name}"
84
+ return_type = renderable_to_type_name(config[:renderable])
85
+
86
+ klass.create_method(
87
+ "with_#{namespaced_name}",
88
+ parameters: [
89
+ create_rest_param('args', type: 'T.untyped'),
90
+ create_block_param('block', type: 'T.untyped')
91
+ ],
92
+ return_type: return_type
93
+ )
94
+ end
95
+ end
96
+
58
97
  sig { params(klass: RBI::Scope, name: String, return_type: String, is_many: T::Boolean).void }
59
98
  def generate_instance_methods(klass, name, return_type, is_many)
60
99
  return_type_maybe_plural =
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorbet_erb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franklin Hu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-16 00:00:00.000000000 Z
11
+ date: 2024-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: better_html