boba 0.0.3 → 0.0.4

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: 76f99ba4fafb5f1a55c1abb60b0c099569f3f4153c4f0f0b43ced158e02fb59b
4
- data.tar.gz: 1de40e562d0dbeb3c0b2a987cd4e2898321a62550a239941cb129f5690da042d
3
+ metadata.gz: e6b2eb9c09c7bcd8a5050115892945fc23749ddc3b9f0376387c914c089c390b
4
+ data.tar.gz: b17a134072db6a900007bc4a74cba405ca69383039e710e86862de09c6daa93f
5
5
  SHA512:
6
- metadata.gz: fbc7d9e5ee8248a1175e499f891716d0397136cc20e1e6db65c22c6d61d777ea756c2c992e48694375358a748986bca2bd2c70393601c8185faf49e1ea7f9e39
7
- data.tar.gz: 23d4d817f6b1a14345599d027c5fbed2203a32709d1cd955568ee69b7475b4551e31308936c02d4e2c26c403af292070f301c9258eed40fdba0b17414ad346f4
6
+ metadata.gz: 6d1bd6b43cc6ad2104ad6bcb96f78a53eb7c70068ef948ba0ab172fb8821537963e3a4bf5fe2b810613f9a2e4e9c0a30364bca266e243af1b8cf2800f0d8772a
7
+ data.tar.gz: 38e5e55631671d0bf64c7c8f64b3d21d8d7c8dbd393b4ffc960f2e958766302bb67dea0c8aeef65ec606f2f395d1194ac1367551a795ae66c7f455ce412f287e
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
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Boba
5
- VERSION = "0.0.3"
5
+ VERSION = "0.0.4"
6
6
  end
data/lib/boba.rb ADDED
@@ -0,0 +1,7 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Boba
5
+ require "boba/version"
6
+ require "boba/relations_railtie" if defined?(Rails)
7
+ 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.3
4
+ version: 0.0.4
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-21 00:00:00.000000000 Z
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,6 +47,8 @@ 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
@@ -56,9 +58,9 @@ licenses:
56
58
  - MIT
57
59
  metadata:
58
60
  bug_tracker_uri: https://github.com/angellist/boba/issues
59
- changelog_uri: https://github.com/angellist/boba/blob/0.0.3/History.md
61
+ changelog_uri: https://github.com/angellist/boba/blob/0.0.4/History.md
60
62
  homepage_uri: https://github.com/angellist/boba
61
- source_code_uri: https://github.com/angellist/boba/tree/0.0.3
63
+ source_code_uri: https://github.com/angellist/boba/tree/0.0.4
62
64
  rubygems_mfa_required: 'true'
63
65
  post_install_message:
64
66
  rdoc_options: []