boba 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -8
- data/lib/boba/relations_railtie.rb +26 -0
- data/lib/boba/version.rb +1 -1
- data/lib/boba.rb +7 -0
- data/lib/tapioca/dsl/compilers/state_machines_extended.rb +37 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e16935e2db06568259ab419c305c0ed064d4fba98c58d4a1f20dab74dd7daa26
|
4
|
+
data.tar.gz: 96a1a1e8220ce8dc7a3e9a7c2a7a9b0c675fbfcf4e0c5544b033889265c3c1e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 246e8b2873276f8e87909aae71dc14143e5635f201246a0b1c9a91a8aa60cec73dfa6e1871672a6e050099f217e646777c0c08a5e9bf5d2ff56cfd71a15de90a
|
7
|
+
data.tar.gz: 9eb1b1c15ba3939c3aec1e76ed83258940d3f3c2afa1f6f054d6189edcbcd65a2f4f853c81a925c2245ed2dd512563eeb689febf7d12fd756f368c2487c20478
|
data/README.md
CHANGED
@@ -4,9 +4,7 @@
|
|
4
4
|
|
5
5
|
Boba is a collection of compilers for Sorbet & Tapioca.
|
6
6
|
|
7
|
-
Tapioca is very opinionated about what types of compilers or changes are accepted into the repository. See
|
8
|
-
[here](https://github.com/Shopify/tapioca?tab=readme-ov-file#dsl-compilers). Boba come in all
|
9
|
-
different shapes, sizes, consistencies, etc, and is much less opinionated about what is or is not accepted. Boba is a collection of optional compilers that you can pick and choose from.
|
7
|
+
Tapioca is very opinionated about what types of compilers or changes are accepted into the repository. See [here](https://github.com/Shopify/tapioca?tab=readme-ov-file#dsl-compilers). Boba come in all different shapes, sizes, consistencies, etc, and is much less opinionated about what is or is not accepted. Boba is a collection of optional compilers that you can pick and choose from.
|
10
8
|
|
11
9
|
### Available Compilers
|
12
10
|
|
@@ -21,8 +19,7 @@ group :development do
|
|
21
19
|
end
|
22
20
|
```
|
23
21
|
|
24
|
-
We recommend you also use the `only` configuration option in your Tapioca config (typically `sorbet/tapioca/config.yml`)
|
25
|
-
to specify only the Tapioca compilers you wish to use.
|
22
|
+
We recommend you also use the `only` configuration option in your Tapioca config (typically `sorbet/tapioca/config.yml`) to specify only the Tapioca compilers you wish to use.
|
26
23
|
```yml
|
27
24
|
dsl:
|
28
25
|
only:
|
@@ -31,6 +28,36 @@ dsl:
|
|
31
28
|
```
|
32
29
|
This makes it easy to selectively enable only the compilers you want to use in your project.
|
33
30
|
|
31
|
+
### Typing Relations
|
32
|
+
|
33
|
+
If you'd like to use relation types in your sigs that are less broad than `ActiveRecord::Relation`, such as those specific to a model, Boba provides a railtie to initialize these constants for each class. Move Boba in your gemfile out of the development group:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
gem 'boba'
|
37
|
+
```
|
38
|
+
|
39
|
+
The railtie will automatically define the `PrivateRelation` constant on each model that inherits from `ActiveRecord::Base`. It can then be used in typing, like thus:
|
40
|
+
```ruby
|
41
|
+
class Post < ::ActiveRecord::Base
|
42
|
+
scope :recent -> { where('created_at > ?', Date.current) }
|
43
|
+
|
44
|
+
belongs_to :author
|
45
|
+
has_many :comments
|
46
|
+
end
|
47
|
+
|
48
|
+
sig { params(author: Author).returns(Post::PrivateRelation) }
|
49
|
+
def posts_from_author(author); end
|
50
|
+
```
|
51
|
+
|
52
|
+
and the following should not raise an error:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
sig { params(author: Author).returns(Post::PrivateRelation) }
|
56
|
+
def recent_posts_from_author(author)
|
57
|
+
posts_from_author(author).recent
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
34
61
|
## Contributing
|
35
62
|
|
36
63
|
Bugs and feature requests are welcome and should be [filed as issues on github](https://github.com/angellist/boba/issues).
|
@@ -39,9 +66,7 @@ Bugs and feature requests are welcome and should be [filed as issues on github](
|
|
39
66
|
|
40
67
|
Compilers for any commonly used Ruby or Rails gems are welcome to be contributed. See the [Writing New Compilers section of the Tapioca docs](https://github.com/Shopify/tapioca?tab=readme-ov-file#writing-custom-dsl-compilers) for an introduction to writing compilers.
|
41
68
|
|
42
|
-
Since Boba is intended to be used alongside Tapioca and the compilers provided by Boba are intended to be fully optional,
|
43
|
-
we will not accept compilers which overwrite the Tapioca default compilers. See the [Tapioca Manual](https://github.com/Shopify/tapioca/blob/main/manual/compilers.md) for a list of these
|
44
|
-
compilers. Instead, compilers which extend or overwrite the default Tapioca compilers should be given unique names.
|
69
|
+
Since Boba is intended to be used alongside Tapioca and the compilers provided by Boba are intended to be fully optional, we will not accept compilers which overwrite the Tapioca default compilers. See the [Tapioca Manual](https://github.com/Shopify/tapioca/blob/main/manual/compilers.md) for a list of these compilers. Instead, compilers which extend or overwrite the default Tapioca compilers should be given unique names.
|
45
70
|
|
46
71
|
Contributed compilers should be well documented, and named after and include a link or reference to the Gem, DSL, or other module they implement RBIs for.
|
47
72
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "rails/railtie"
|
5
|
+
|
6
|
+
class Boba::RelationsRailtie < Rails::Railtie
|
7
|
+
railtie_name(:boba)
|
8
|
+
|
9
|
+
initializer("boba.add_private_relation_constant") do
|
10
|
+
ActiveSupport.on_load(:active_record) do
|
11
|
+
module AciveRecordInheritDefineRelationTypes
|
12
|
+
def inherited(child)
|
13
|
+
super(child)
|
14
|
+
|
15
|
+
child.const_set("PrivateRelation", Object)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class ::ActiveRecord::Base
|
20
|
+
class << self
|
21
|
+
prepend AciveRecordInheritDefineRelationTypes
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/boba/version.rb
CHANGED
data/lib/boba.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# typed: ignore
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
return unless defined?(Tapioca)
|
5
|
+
|
6
|
+
require "tapioca/dsl/compilers/state_machines"
|
7
|
+
|
8
|
+
module Tapioca
|
9
|
+
module Dsl
|
10
|
+
module Compilers
|
11
|
+
# `Tapioca::Dsl::Compilers::StateMachinesExtended` extends the default state machines compiler provided by Tapioca
|
12
|
+
# to allow for calling `with_state` and `without_state` on all Active Record relations. This is a temporary fix
|
13
|
+
# until a more durable solution can be found for this type of issue.
|
14
|
+
# See https://github.com/Shopify/tapioca/pull/1994#issuecomment-2302624697.
|
15
|
+
class StateMachinesExtended < ::Tapioca::Dsl::Compilers::StateMachines
|
16
|
+
ACTIVE_RECORD_RELATION_MODULE_NAMES = [
|
17
|
+
"GeneratedRelationMethods",
|
18
|
+
"GeneratedAssociationRelationMethods",
|
19
|
+
].freeze
|
20
|
+
|
21
|
+
def decorate
|
22
|
+
return if constant.state_machines.empty?
|
23
|
+
|
24
|
+
super()
|
25
|
+
|
26
|
+
root.create_path(T.unsafe(constant)) do |klass|
|
27
|
+
class_module_name = "StateMachineClassHelperModule"
|
28
|
+
|
29
|
+
ACTIVE_RECORD_RELATION_MODULE_NAMES.each do |module_name|
|
30
|
+
klass.create_module(module_name).create_include(class_module_name)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angellist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sorbet-static-and-runtime
|
@@ -47,18 +47,21 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- LICENSE
|
49
49
|
- README.md
|
50
|
+
- lib/boba.rb
|
51
|
+
- lib/boba/relations_railtie.rb
|
50
52
|
- lib/boba/version.rb
|
51
53
|
- lib/tapioca/dsl/compilers/active_record_associations_persisted.rb
|
52
54
|
- lib/tapioca/dsl/compilers/active_record_columns_persisted.rb
|
53
55
|
- lib/tapioca/dsl/compilers/money_rails.rb
|
56
|
+
- lib/tapioca/dsl/compilers/state_machines_extended.rb
|
54
57
|
homepage: https://github.com/angellist/boba
|
55
58
|
licenses:
|
56
59
|
- MIT
|
57
60
|
metadata:
|
58
61
|
bug_tracker_uri: https://github.com/angellist/boba/issues
|
59
|
-
changelog_uri: https://github.com/angellist/boba/blob/0.0.
|
62
|
+
changelog_uri: https://github.com/angellist/boba/blob/0.0.5/History.md
|
60
63
|
homepage_uri: https://github.com/angellist/boba
|
61
|
-
source_code_uri: https://github.com/angellist/boba/tree/0.0.
|
64
|
+
source_code_uri: https://github.com/angellist/boba/tree/0.0.5
|
62
65
|
rubygems_mfa_required: 'true'
|
63
66
|
post_install_message:
|
64
67
|
rdoc_options: []
|