boba 0.0.17 → 0.1.1
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 +7 -4
- 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: 5abeb65f84cb5a0b5e063917a97521d572164c7cfb6c3616fae19a4063a5c61a
|
4
|
+
data.tar.gz: fd93b2552cdb7b45c311dbeea100ada0668a4ad503e83f860a225ace64f0d48d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8385e5e86f442d1cd185a3fe99325e7c7dfb211a3d05cbbd870e76c6fbca975a0c68cd77bcd213bcd298ba889e91a4777595db68be04fdf7cc74ab1522fdedf4
|
7
|
+
data.tar.gz: 7a62642e4a38a57967c885dae2ab7b64537eb7fbccfd918aa1eb51dc9a13f2a230f8ac046669ceb13fb5793489b4156e2356104a1697fb699711f05e61af9887
|
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
|
@@ -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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angellist
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-04-25 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.16.
|
32
|
+
version: 0.16.11
|
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.16.
|
39
|
+
version: 0.16.11
|
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.1/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.1
|
70
71
|
rubygems_mfa_required: 'true'
|
71
72
|
rdoc_options: []
|
72
73
|
require_paths:
|