boba 0.0.17 → 0.1.2
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 +4 -4
- data/lib/boba/version.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_associations_persisted.rb +3 -1
- data/lib/tapioca/dsl/compilers/active_record_columns_persisted.rb +19 -8
- data/lib/tapioca/dsl/compilers/flag_shih_tzu.rb +118 -0
- data/lib/tapioca/dsl/compilers/money_rails.rb +12 -3
- data/lib/tapioca/dsl/compilers/paperclip.rb +6 -3
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02c51cd1ca87d911eed9a565f7beed6325dc924e15f79612796c8c3f1f11d878
|
4
|
+
data.tar.gz: 4b3f1eaa35df95336956512c7ba438478a1e8b22d82e3e632a60995205d84ad4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d51bdb39c3570923ae521c1c58e542b5ac2093e8d54b9bb7b0c1be66e597530a02357b16406bb80114a62a9b3e6bcf5d359a32eb92777be19e1ec06c52080787
|
7
|
+
data.tar.gz: c4855eb16dec55e7770d6b78c31a2925fb7f35aea9ee852283a0301c427e6d0b2249e8ac175dbe72db6ca7d2d387a25fefbec4dfa893aea2aae2dcfa01de32ce
|
data/lib/boba/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require "tapioca/dsl/compilers/active_record_associations"
|
@@ -54,6 +54,8 @@ module Tapioca
|
|
54
54
|
class ActiveRecordAssociationsPersisted < ::Tapioca::Dsl::Compilers::ActiveRecordAssociations
|
55
55
|
extend T::Sig
|
56
56
|
|
57
|
+
ConstantType = type_member { { fixed: T.class_of(ActiveRecord::Base) } }
|
58
|
+
|
57
59
|
private
|
58
60
|
|
59
61
|
sig { returns(Boba::Options::AssociationTypeOption) }
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require "tapioca/dsl/compilers/active_record_columns"
|
@@ -128,8 +128,11 @@ module Tapioca
|
|
128
128
|
class ActiveRecordColumnsPersisted < ::Tapioca::Dsl::Compilers::ActiveRecordColumns
|
129
129
|
extend T::Sig
|
130
130
|
|
131
|
+
ConstantType = type_member { { fixed: T.class_of(ActiveRecord::Base) } }
|
132
|
+
|
131
133
|
private
|
132
134
|
|
135
|
+
sig { returns(::Tapioca::Dsl::Helpers::ActiveRecordColumnTypeHelper) }
|
133
136
|
def column_type_helper
|
134
137
|
::Tapioca::Dsl::Helpers::ActiveRecordColumnTypeHelper.new(
|
135
138
|
constant,
|
@@ -153,9 +156,9 @@ module Tapioca
|
|
153
156
|
def column_type_for(column_name)
|
154
157
|
return ["T.untyped", "T.untyped"] if column_type_option.untyped?
|
155
158
|
|
156
|
-
nilable_column = Boba::ActiveRecord::AttributeService.nilable_attribute?(
|
159
|
+
nilable_column = Boba::ActiveRecord::AttributeService.nilable_attribute?(constant, column_name)
|
157
160
|
|
158
|
-
column_type =
|
161
|
+
column_type = constant.attribute_types[column_name]
|
159
162
|
getter_type = column_type_helper.send(
|
160
163
|
:type_for_activerecord_value,
|
161
164
|
column_type,
|
@@ -169,7 +172,7 @@ module Tapioca
|
|
169
172
|
getter_type
|
170
173
|
end
|
171
174
|
|
172
|
-
virtual_attribute = Boba::ActiveRecord::AttributeService.virtual_attribute?(
|
175
|
+
virtual_attribute = Boba::ActiveRecord::AttributeService.virtual_attribute?(constant, column_name)
|
173
176
|
if column_type_option.persisted? && (virtual_attribute || !nilable_column)
|
174
177
|
[getter_type, setter_type]
|
175
178
|
else
|
@@ -251,12 +254,20 @@ module Tapioca
|
|
251
254
|
"saved_change_to_#{attribute_name}?",
|
252
255
|
methods_to_add,
|
253
256
|
return_type: "T::Boolean",
|
257
|
+
parameters: [
|
258
|
+
create_kw_opt_param("from", type: "T.untyped", default: "T.unsafe(nil)"),
|
259
|
+
create_kw_opt_param("to", type: "T.untyped", default: "T.unsafe(nil)"),
|
260
|
+
],
|
254
261
|
)
|
255
262
|
add_method(
|
256
263
|
klass,
|
257
264
|
"will_save_change_to_#{attribute_name}?",
|
258
265
|
methods_to_add,
|
259
266
|
return_type: "T::Boolean",
|
267
|
+
parameters: [
|
268
|
+
create_kw_opt_param("from", type: "T.untyped", default: "T.unsafe(nil)"),
|
269
|
+
create_kw_opt_param("to", type: "T.untyped", default: "T.unsafe(nil)"),
|
270
|
+
],
|
260
271
|
)
|
261
272
|
|
262
273
|
# Added by ActiveModel::Dirty
|
@@ -273,8 +284,8 @@ module Tapioca
|
|
273
284
|
methods_to_add,
|
274
285
|
return_type: "T::Boolean",
|
275
286
|
parameters: [
|
276
|
-
create_kw_opt_param("from", type:
|
277
|
-
create_kw_opt_param("to", type:
|
287
|
+
create_kw_opt_param("from", type: "T.untyped", default: "T.unsafe(nil)"),
|
288
|
+
create_kw_opt_param("to", type: "T.untyped", default: "T.unsafe(nil)"),
|
278
289
|
],
|
279
290
|
)
|
280
291
|
add_method(
|
@@ -300,8 +311,8 @@ module Tapioca
|
|
300
311
|
methods_to_add,
|
301
312
|
return_type: "T::Boolean",
|
302
313
|
parameters: [
|
303
|
-
create_kw_opt_param("from", type:
|
304
|
-
create_kw_opt_param("to", type:
|
314
|
+
create_kw_opt_param("from", type: "T.untyped", default: "T.unsafe(nil)"),
|
315
|
+
create_kw_opt_param("to", type: "T.untyped", default: "T.unsafe(nil)"),
|
305
316
|
],
|
306
317
|
)
|
307
318
|
add_method(
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
return unless defined?(FlagShihTzu)
|
5
|
+
|
6
|
+
module Tapioca
|
7
|
+
module Dsl
|
8
|
+
module Compilers
|
9
|
+
# `Tapioca::Dsl::Compilers::FlagShihTzu` decorates RBI files for models
|
10
|
+
# using FlagShihTzu.
|
11
|
+
#
|
12
|
+
# For example, with FlagShihTzu installed and the following `ActiveRecord::Base` subclass:
|
13
|
+
#
|
14
|
+
# ~~~rb
|
15
|
+
# class Post < ApplicationRecord
|
16
|
+
# has_flags(
|
17
|
+
# 1 => :published,
|
18
|
+
# 2 => :deleted,
|
19
|
+
# )
|
20
|
+
# end
|
21
|
+
# ~~~
|
22
|
+
#
|
23
|
+
# This compiler will produce the RBI file `post.rbi` with the following content:
|
24
|
+
#
|
25
|
+
# ~~~rbi
|
26
|
+
# # post.rbi
|
27
|
+
# # typed: true
|
28
|
+
# class Post
|
29
|
+
# include FlagShihTzu
|
30
|
+
# include FlagShihTzuGeneratedMethods
|
31
|
+
#
|
32
|
+
# module FlagShihTzuGeneratedMethods
|
33
|
+
# sig { returns(T::Boolean) }
|
34
|
+
# def published; end
|
35
|
+
# sig { params(value: T::Boolean).returns(T::Boolean) }
|
36
|
+
# def published=(value); end
|
37
|
+
# sig { returns(T::Boolean) }
|
38
|
+
# def published?; end
|
39
|
+
#
|
40
|
+
# sig { returns(T::Boolean) }
|
41
|
+
# def deleted; end
|
42
|
+
# sig { params(value: T::Boolean).returns(T::Boolean) }
|
43
|
+
# def deleted=(value); end
|
44
|
+
# sig { returns(T::Boolean) }
|
45
|
+
# def deleted?; end
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
# ~~~
|
49
|
+
class FlagShihTzu < Tapioca::Dsl::Compiler
|
50
|
+
extend T::Sig
|
51
|
+
|
52
|
+
ConstantType = type_member { { fixed: T.all(T.class_of(::FlagShihTzu), ::FlagShihTzu::GeneratedClassMethods) } }
|
53
|
+
|
54
|
+
InstanceMethodsModuleName = "FlagShihTzuGeneratedMethods"
|
55
|
+
ClassMethodsModuleName = "::FlagShihTzu"
|
56
|
+
|
57
|
+
class << self
|
58
|
+
extend T::Sig
|
59
|
+
|
60
|
+
sig { override.returns(T::Enumerable[Module]) }
|
61
|
+
def gather_constants
|
62
|
+
all_classes.select { |c| c < ::FlagShihTzu }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
sig { override.void }
|
67
|
+
def decorate
|
68
|
+
return if constant.flag_mapping.blank?
|
69
|
+
|
70
|
+
root.create_path(constant) do |klass|
|
71
|
+
instance_module = RBI::Module.new(InstanceMethodsModuleName)
|
72
|
+
|
73
|
+
# has_flags(
|
74
|
+
# 1 => :warpdrive,
|
75
|
+
# 2 => shields,
|
76
|
+
# column: 'features',
|
77
|
+
# )
|
78
|
+
constant.flag_mapping.each do |_, flags|
|
79
|
+
# column: 'features', flags: { warpdrive: ..., shields: ... }
|
80
|
+
flags.each do |flag_key, _|
|
81
|
+
# .warpdrive
|
82
|
+
# .warpdrive=
|
83
|
+
# .warpdrive?
|
84
|
+
# .warpdrive_changed?
|
85
|
+
instance_module.create_method(flag_key.to_s, return_type: "T::Boolean")
|
86
|
+
instance_module.create_method(
|
87
|
+
"#{flag_key}=",
|
88
|
+
parameters: [create_param("value", type: "T::Boolean")],
|
89
|
+
return_type: "T::Boolean",
|
90
|
+
)
|
91
|
+
instance_module.create_method("#{flag_key}?", return_type: "T::Boolean")
|
92
|
+
instance_module.create_method("#{flag_key}_changed?", return_type: "T::Boolean")
|
93
|
+
|
94
|
+
# .not_warpdrive
|
95
|
+
# .not_warpdrive=
|
96
|
+
# .not_warpdrive?
|
97
|
+
instance_module.create_method("not_#{flag_key}", return_type: "T::Boolean")
|
98
|
+
instance_module.create_method("not_#{flag_key}?", return_type: "T::Boolean")
|
99
|
+
instance_module.create_method(
|
100
|
+
"not_#{flag_key}=",
|
101
|
+
parameters: [create_param("value", type: "T::Boolean")],
|
102
|
+
return_type: "T::Boolean",
|
103
|
+
)
|
104
|
+
|
105
|
+
# .has_warpdrive?
|
106
|
+
instance_module.create_method("has_#{flag_key}?", return_type: "T::Boolean")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
klass << instance_module
|
111
|
+
klass.create_include(ClassMethodsModuleName)
|
112
|
+
klass.create_include(InstanceMethodsModuleName)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -14,6 +14,12 @@ module Tapioca
|
|
14
14
|
# by the `money-rails` gem.
|
15
15
|
# https://github.com/RubyMoney/money-rails
|
16
16
|
#
|
17
|
+
# In order to use this compiler, you will need to add
|
18
|
+
# `require "money-rails/active_record/monetizable"`
|
19
|
+
# to your `sorbet/tapioca/require.rb` file, since it relies on the module
|
20
|
+
# `MoneyRails::ActiveRecord::Monetizable::ClassMethods` having been detected and sigs generated for it in the gem
|
21
|
+
# rbis.
|
22
|
+
#
|
17
23
|
# For example, with the following ActiveRecord model:
|
18
24
|
# ~~~rb
|
19
25
|
# class Product < ActiveRecord::Base
|
@@ -48,6 +54,9 @@ module Tapioca
|
|
48
54
|
}
|
49
55
|
end
|
50
56
|
|
57
|
+
ClassMethodModuleName = "MoneyRails::ActiveRecord::Monetizable::ClassMethods"
|
58
|
+
InstanceModuleName = "MoneyRailsGeneratedMethods"
|
59
|
+
|
51
60
|
class << self
|
52
61
|
extend T::Sig
|
53
62
|
|
@@ -77,8 +86,7 @@ module Tapioca
|
|
77
86
|
return if constant.monetized_attributes.empty?
|
78
87
|
|
79
88
|
root.create_path(constant) do |klass|
|
80
|
-
|
81
|
-
instance_module = RBI::Module.new(instance_module_name)
|
89
|
+
instance_module = RBI::Module.new(InstanceModuleName)
|
82
90
|
|
83
91
|
constant.monetized_attributes.each do |attribute_name, column_name|
|
84
92
|
if column_type_option.untyped?
|
@@ -111,7 +119,8 @@ module Tapioca
|
|
111
119
|
end
|
112
120
|
|
113
121
|
klass << instance_module
|
114
|
-
klass.create_include(
|
122
|
+
klass.create_include(InstanceModuleName)
|
123
|
+
klass.create_extend(ClassMethodModuleName)
|
115
124
|
end
|
116
125
|
end
|
117
126
|
end
|
@@ -35,7 +35,9 @@ module Tapioca
|
|
35
35
|
extend T::Sig
|
36
36
|
include RBIHelper
|
37
37
|
|
38
|
-
|
38
|
+
ClassMethodsModuleName = "::Paperclip::Glue"
|
39
|
+
InstanceMethodModuleName = "PaperclipGeneratedMethods"
|
40
|
+
|
39
41
|
ConstantType = type_member { { fixed: T.class_of(::Paperclip::Glue) } }
|
40
42
|
|
41
43
|
class << self
|
@@ -55,7 +57,7 @@ module Tapioca
|
|
55
57
|
return if attachments.empty?
|
56
58
|
|
57
59
|
root.create_path(constant) do |klass|
|
58
|
-
instance_module = RBI::Module.new(
|
60
|
+
instance_module = RBI::Module.new(InstanceMethodModuleName)
|
59
61
|
|
60
62
|
attachments.each do |attachment_name|
|
61
63
|
# Model: has_attached_file(:marketing_image)
|
@@ -70,7 +72,8 @@ module Tapioca
|
|
70
72
|
end
|
71
73
|
|
72
74
|
klass << instance_module
|
73
|
-
klass.create_include(
|
75
|
+
klass.create_include(ClassMethodsModuleName)
|
76
|
+
klass.create_include(InstanceMethodModuleName)
|
74
77
|
end
|
75
78
|
end
|
76
79
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angellist
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-06-12 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: sorbet-static-and-runtime
|
@@ -29,14 +29,14 @@ dependencies:
|
|
29
29
|
requirements:
|
30
30
|
- - "<="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.
|
32
|
+
version: 0.17.2
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "<="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.
|
39
|
+
version: 0.17.2
|
40
40
|
email:
|
41
41
|
- alex.stathis@angellist.com
|
42
42
|
executables: []
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/tapioca/dsl/compilers/active_record_columns_persisted.rb
|
56
56
|
- lib/tapioca/dsl/compilers/active_record_relation_types.rb
|
57
57
|
- lib/tapioca/dsl/compilers/attr_json.rb
|
58
|
+
- lib/tapioca/dsl/compilers/flag_shih_tzu.rb
|
58
59
|
- lib/tapioca/dsl/compilers/kaminari.rb
|
59
60
|
- lib/tapioca/dsl/compilers/money_rails.rb
|
60
61
|
- lib/tapioca/dsl/compilers/paperclip.rb
|
@@ -64,9 +65,9 @@ licenses:
|
|
64
65
|
- MIT
|
65
66
|
metadata:
|
66
67
|
bug_tracker_uri: https://github.com/angellist/boba/issues
|
67
|
-
changelog_uri: https://github.com/angellist/boba/blob/0.
|
68
|
+
changelog_uri: https://github.com/angellist/boba/blob/0.1.2/History.md
|
68
69
|
homepage_uri: https://github.com/angellist/boba
|
69
|
-
source_code_uri: https://github.com/angellist/boba/tree/0.
|
70
|
+
source_code_uri: https://github.com/angellist/boba/tree/0.1.2
|
70
71
|
rubygems_mfa_required: 'true'
|
71
72
|
rdoc_options: []
|
72
73
|
require_paths:
|