tapioca 0.13.1 → 0.13.2

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: d49ca562ccbe7a00137e647a6e96499d6699b3c4c0d7d29f513a19d32fd17cd1
4
- data.tar.gz: a7761368e37e779e7478892d81701bbc8096522103de6cd948b845e69d52d6d4
3
+ metadata.gz: 160e94dc5b5280b1b9e1cb84813fbc8f5f137c56ac2f0222693e35beaa647b2e
4
+ data.tar.gz: ca8e98b7e4685f71fdb8b104a55df21e4d9c0bc2001eb6490508f22661a430d7
5
5
  SHA512:
6
- metadata.gz: 5ba58ce9b4be09cd647255a82ecac17049c946ba0d55dffc86160a69514f2e3c802b6f3b1627ddbbe92aba96e53a0d574191c1dfcb0a5af604e1294cebe6c9d4
7
- data.tar.gz: c011df4fac4986b9cf33707059de3c86adbad54d26adcab75f949293f2a116bd5b1da5a1f5698ee70ecf497bdefe0fe7cfb03dc99b607eb78b4cd2f46aeffb60
6
+ metadata.gz: d61c8c74b3d7f05818a43814c3d876df6a849ebecb6cd86f853a14b2bc19ec34186eb7f9185ca4cab43baf88bdac90191923fbc5b59577b1548659ee618c336a
7
+ data.tar.gz: b474f48b7e0e427919d154a9da43877c0a9de1ef1e5ec9284299cbcb0b26a9178b9225eb264f1e55dcbea2cbd909c17d4161a3f23b02b7cedf36dbb467c91cb3
data/README.md CHANGED
@@ -52,6 +52,7 @@ Tapioca makes it easy to work with [Sorbet](https://sorbet.org) in your codebase
52
52
  * [RBI files for missing constants and methods](#rbi-files-for-missing-constants-and-methods)
53
53
  * [Configuration](#configuration)
54
54
  * [Contributing](#contributing)
55
+ * [DSL compilers](#dsl-compilers)
55
56
  * [License](#license)
56
57
  <!-- END_TOC -->
57
58
 
@@ -973,6 +974,10 @@ annotations:
973
974
 
974
975
  Bug reports and pull requests are welcome on GitHub at https://github.com/Shopify/tapioca. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://github.com/Shopify/tapioca/blob/main/CODE_OF_CONDUCT.md) code of conduct.
975
976
 
977
+ ### DSL compilers
978
+
979
+ Contributions to existing DSL compilers are welcome. However, new compilers that support DSLs for gems other than Rails should live outside of Tapioca. Please refer to [writing custom dsl compilers](https://github.com/Shopify/tapioca?tab=readme-ov-file#writing-custom-dsl-compilers) for more information.
980
+
976
981
  ## License
977
982
 
978
983
  The gem is available as open source under the terms of the [MIT License](https://github.com/Shopify/tapioca/blob/main/LICENSE.txt).
@@ -667,18 +667,25 @@ module Tapioca
667
667
  end
668
668
  sigs = [
669
669
  common_relation_methods_module.create_sig(
670
- parameters: [create_param("args", type: id_types)],
670
+ parameters: { args: id_types },
671
671
  return_type: constant_name,
672
672
  ),
673
673
  common_relation_methods_module.create_sig(
674
- parameters: [create_param("args", type: array_type)],
674
+ parameters: { args: array_type },
675
675
  return_type: "T::Enumerable[#{constant_name}]",
676
676
  ),
677
+ common_relation_methods_module.create_sig(
678
+ parameters: {
679
+ args: "NilClass",
680
+ block: "T.proc.params(object: #{constant_name}).void)",
681
+ },
682
+ return_type: as_nilable_type(constant_name),
683
+ ),
677
684
  ]
678
685
  common_relation_methods_module.create_method_with_sigs(
679
686
  "find",
680
687
  sigs: sigs,
681
- parameters: [RBI::ReqParam.new("args")],
688
+ parameters: [RBI::OptParam.new("args", "nil"), RBI::BlockParam.new("block")],
682
689
  )
683
690
  when :find_by
684
691
  create_common_method(
@@ -714,11 +721,11 @@ module Tapioca
714
721
  when :first, :last, :take
715
722
  sigs = [
716
723
  common_relation_methods_module.create_sig(
717
- parameters: [create_opt_param("limit", type: "NilClass", default: "nil")],
724
+ parameters: { limit: "NilClass" },
718
725
  return_type: as_nilable_type(constant_name),
719
726
  ),
720
727
  common_relation_methods_module.create_sig(
721
- parameters: [create_param("limit", type: "Integer")],
728
+ parameters: { limit: "Integer" },
722
729
  return_type: "T::Array[#{constant_name}]",
723
730
  ),
724
731
  ]
@@ -786,12 +793,23 @@ module Tapioca
786
793
  return_type: "Numeric",
787
794
  )
788
795
  when :count
789
- create_common_method(
796
+ sigs = [
797
+ common_relation_methods_module.create_sig(
798
+ parameters: { column_name: "T.nilable(T.any(String, Symbol))" },
799
+ return_type: "Integer",
800
+ ),
801
+ common_relation_methods_module.create_sig(
802
+ parameters: { column_name: "NilClass", block: "T.proc.params(object: #{constant_name}).void" },
803
+ return_type: "Integer",
804
+ ),
805
+ ]
806
+ common_relation_methods_module.create_method_with_sigs(
790
807
  "count",
808
+ sigs: sigs,
791
809
  parameters: [
792
- create_opt_param("column_name", type: "T.untyped", default: "nil"),
810
+ RBI::OptParam.new("column_name", "nil"),
811
+ RBI::BlockParam.new("block"),
793
812
  ],
794
- return_type: "Integer",
795
813
  )
796
814
  when :ids
797
815
  create_common_method("ids", return_type: "Array")
@@ -819,26 +837,20 @@ module Tapioca
819
837
  case method_name
820
838
  when :find_each
821
839
  order = ActiveRecord::Batches.instance_method(:find_each).parameters.include?([:key, :order])
840
+ parameters = {
841
+ start: "T.untyped",
842
+ finish: "T.untyped",
843
+ batch_size: "Integer",
844
+ error_on_ignore: "T.untyped",
845
+ order: ("Symbol" if order),
846
+ }.compact
822
847
  sigs = [
823
848
  common_relation_methods_module.create_sig(
824
- parameters: [
825
- create_kw_opt_param("start", type: "T.untyped", default: "nil"),
826
- create_kw_opt_param("finish", type: "T.untyped", default: "nil"),
827
- create_kw_opt_param("batch_size", type: "Integer", default: "1000"),
828
- create_kw_opt_param("error_on_ignore", type: "T.untyped", default: "nil"),
829
- *(create_kw_opt_param("order", type: "Symbol", default: ":asc") if order),
830
- create_block_param("block", type: "T.proc.params(object: #{constant_name}).void"),
831
- ],
849
+ parameters: parameters.merge(block: "T.proc.params(object: #{constant_name}).void"),
832
850
  return_type: "void",
833
851
  ),
834
852
  common_relation_methods_module.create_sig(
835
- parameters: [
836
- create_kw_opt_param("start", type: "T.untyped", default: "nil"),
837
- create_kw_opt_param("finish", type: "T.untyped", default: "nil"),
838
- create_kw_opt_param("batch_size", type: "Integer", default: "1000"),
839
- create_kw_opt_param("error_on_ignore", type: "T.untyped", default: "nil"),
840
- *(create_kw_opt_param("order", type: "Symbol", default: ":asc") if order),
841
- ],
853
+ parameters: parameters,
842
854
  return_type: "T::Enumerator[#{constant_name}]",
843
855
  ),
844
856
  ]
@@ -856,26 +868,20 @@ module Tapioca
856
868
  )
857
869
  when :find_in_batches
858
870
  order = ActiveRecord::Batches.instance_method(:find_in_batches).parameters.include?([:key, :order])
871
+ parameters = {
872
+ start: "T.untyped",
873
+ finish: "T.untyped",
874
+ batch_size: "Integer",
875
+ error_on_ignore: "T.untyped",
876
+ order: ("Symbol" if order),
877
+ }.compact
859
878
  sigs = [
860
879
  common_relation_methods_module.create_sig(
861
- parameters: [
862
- create_kw_opt_param("start", type: "T.untyped", default: "nil"),
863
- create_kw_opt_param("finish", type: "T.untyped", default: "nil"),
864
- create_kw_opt_param("batch_size", type: "Integer", default: "1000"),
865
- create_kw_opt_param("error_on_ignore", type: "T.untyped", default: "nil"),
866
- *(create_kw_opt_param("order", type: "Symbol", default: ":asc") if order),
867
- create_block_param("block", type: "T.proc.params(object: T::Array[#{constant_name}]).void"),
868
- ],
880
+ parameters: parameters.merge(block: "T.proc.params(object: T::Array[#{constant_name}]).void"),
869
881
  return_type: "void",
870
882
  ),
871
883
  common_relation_methods_module.create_sig(
872
- parameters: [
873
- create_kw_opt_param("start", type: "T.untyped", default: "nil"),
874
- create_kw_opt_param("finish", type: "T.untyped", default: "nil"),
875
- create_kw_opt_param("batch_size", type: "Integer", default: "1000"),
876
- create_kw_opt_param("error_on_ignore", type: "T.untyped", default: "nil"),
877
- *(create_kw_opt_param("order", type: "Symbol", default: ":asc") if order),
878
- ],
884
+ parameters: parameters,
879
885
  return_type: "T::Enumerator[T::Enumerator[#{constant_name}]]",
880
886
  ),
881
887
  ]
@@ -894,30 +900,22 @@ module Tapioca
894
900
  when :in_batches
895
901
  order = ActiveRecord::Batches.instance_method(:in_batches).parameters.include?([:key, :order])
896
902
  use_ranges = ActiveRecord::Batches.instance_method(:in_batches).parameters.include?([:key, :use_ranges])
903
+ parameters = {
904
+ of: "Integer",
905
+ start: "T.untyped",
906
+ finish: "T.untyped",
907
+ load: "T.untyped",
908
+ error_on_ignore: "T.untyped",
909
+ order: ("Symbol" if order),
910
+ use_ranges: ("T.untyped" if use_ranges),
911
+ }.compact
897
912
  sigs = [
898
913
  common_relation_methods_module.create_sig(
899
- parameters: [
900
- create_kw_opt_param("of", type: "Integer", default: "1000"),
901
- create_kw_opt_param("start", type: "T.untyped", default: "nil"),
902
- create_kw_opt_param("finish", type: "T.untyped", default: "nil"),
903
- create_kw_opt_param("load", type: "T.untyped", default: "false"),
904
- create_kw_opt_param("error_on_ignore", type: "T.untyped", default: "nil"),
905
- *(create_kw_opt_param("order", type: "Symbol", default: ":asc") if order),
906
- *(create_kw_opt_param("use_ranges", type: "T.untyped", default: "nil") if use_ranges),
907
- create_block_param("block", type: "T.proc.params(object: #{RelationClassName}).void"),
908
- ],
914
+ parameters: parameters.merge(block: "T.proc.params(object: #{RelationClassName}).void"),
909
915
  return_type: "void",
910
916
  ),
911
917
  common_relation_methods_module.create_sig(
912
- parameters: [
913
- create_kw_opt_param("of", type: "Integer", default: "1000"),
914
- create_kw_opt_param("start", type: "T.untyped", default: "nil"),
915
- create_kw_opt_param("finish", type: "T.untyped", default: "nil"),
916
- create_kw_opt_param("load", type: "T.untyped", default: "false"),
917
- create_kw_opt_param("error_on_ignore", type: "T.untyped", default: "nil"),
918
- *(create_kw_opt_param("order", type: "Symbol", default: ":asc") if order),
919
- *(create_kw_opt_param("use_ranges", type: "T.untyped", default: "nil") if use_ranges),
920
- ],
918
+ parameters: parameters,
921
919
  return_type: "::ActiveRecord::Batches::BatchEnumerator",
922
920
  ),
923
921
  ]
@@ -63,6 +63,10 @@ module Tapioca
63
63
  def load_dsl_compilers
64
64
  say("Loading DSL compiler classes... ")
65
65
 
66
+ ::Gem.find_files("tapioca/dsl/compilers/*.rb").each do |compiler|
67
+ require File.expand_path(compiler)
68
+ end
69
+
66
70
  Dir.glob([
67
71
  "#{@tapioca_path}/generators/**/*.rb", # TODO: Here for backcompat, remove later
68
72
  "#{@tapioca_path}/compilers/**/*.rb",
@@ -70,10 +74,6 @@ module Tapioca
70
74
  require File.expand_path(compiler)
71
75
  end
72
76
 
73
- ::Gem.find_files("tapioca/dsl/compilers/*.rb").each do |compiler|
74
- require File.expand_path(compiler)
75
- end
76
-
77
77
  say("Done", :green)
78
78
  end
79
79
 
@@ -88,7 +88,8 @@ module RBI
88
88
  end
89
89
  def create_method(name, parameters: [], return_type: "T.untyped", class_method: false, visibility: RBI::Public.new,
90
90
  comments: [])
91
- sig = create_sig(parameters: parameters, return_type: return_type)
91
+ sig_params = parameters.to_h { |param| [param.param.name, param.type] }
92
+ sig = create_sig(parameters: sig_params, return_type: return_type)
92
93
  create_method_with_sigs(
93
94
  name,
94
95
  sigs: [sig],
@@ -126,13 +127,13 @@ module RBI
126
127
 
127
128
  sig do
128
129
  params(
129
- parameters: T::Array[RBI::TypedParam],
130
+ parameters: T::Hash[T.any(String, Symbol), String],
130
131
  return_type: String,
131
132
  ).returns(RBI::Sig)
132
133
  end
133
- def create_sig(parameters: [], return_type: "T.untyped")
134
- params = parameters.map do |param|
135
- RBI::SigParam.new(param.param.name, param.type)
134
+ def create_sig(parameters:, return_type: "T.untyped")
135
+ params = parameters.map do |name, type|
136
+ RBI::SigParam.new(name.to_s, type)
136
137
  end
137
138
  RBI::Sig.new(params: params, return_type: return_type)
138
139
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.13.1"
5
+ VERSION = "0.13.2"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapioca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2024-03-27 00:00:00.000000000 Z
14
+ date: 2024-04-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -288,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
288
  - !ruby/object:Gem::Version
289
289
  version: '0'
290
290
  requirements: []
291
- rubygems_version: 3.5.7
291
+ rubygems_version: 3.5.9
292
292
  signing_key:
293
293
  specification_version: 4
294
294
  summary: A Ruby Interface file generator for gems, core types and the Ruby standard