tapioca 0.2.6 → 0.2.7

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: 1a7c988252d754c4998199fe7dd9fabf6bbab76ef10ad61a5b12ca2e750a7c7c
4
- data.tar.gz: 8016c921c68a4d68cfab4d40f8580f165ef8fa991135509aeb3a29cad2947c9f
3
+ metadata.gz: 2a3d27cc18a2cc1afcfd1f9c9cb1e833078ea06b1c4a4900e76614b2b54478b7
4
+ data.tar.gz: 9b8e0b109fbdc3a7d6393a67df9f53031c8e29aa1479eb0a1fb644783998bc36
5
5
  SHA512:
6
- metadata.gz: 031c9feaadf13e2a667b8f8483419f71719788e7f043189032889fd799ae846b55bba0d827a654851ecec2bb2e0114ef7794312facb9eb8e97530e42f581240c
7
- data.tar.gz: d630b843d4cdeaba2c2ce34f2766c5be473a8edac4cbcc28b9d3724ac5a0a8d9392a108e2ebad79cd297756a6e010e44c5875410ee011e67210555ddaf121de0
6
+ metadata.gz: 5601255b31b7cec6eb03ec8553f03450148de320ef48ab3370f278797d7189c020d1a7a2c04b6ab5b2e509321df4df0fbb022dd9e0ae9477aceaca4a195b620a
7
+ data.tar.gz: 1b3fcf4e9c997f60199e60e9206d2113e3d1292334d38db0d670ba0e3d5f4f0e8f348c88e74b8c1f8df0524bc9f40c59c1f214273b76259db5d88246610ccc55
data/README.md CHANGED
@@ -85,8 +85,8 @@ This will sync the RBIs with the gems in the Gemfile and will add, update, and r
85
85
  - `--prerequire [file]`: A file to be required before `Bundler.require` is called.
86
86
  - `--postrequire [file]`: A file to be required after `Bundler.require` is called.
87
87
  - `--out [directory]`: The output directory for generated RBI files, default to `sorbet/rbi/gems`.
88
- - `--generate_command [command]`: The command to run to regenerate RBI files (used in header comment of the RBI files), defaults to the current command.
89
- - `--typed_overrides [gem:level]`: Overrides typed sigils for generated gem RBIs for gem `gem` to level `level` (`level` can be one of `ignore`, `false`, `true`, `strict`, or `strong`, see [the Sorbet docs](https://sorbet.org/docs/static#file-level-granularity-strictness-levels) for more details).
88
+ - `--generate-command [command]`: The command to run to regenerate RBI files (used in header comment of the RBI files), defaults to the current command.
89
+ - `--typed-overrides [gem:level]`: Overrides typed sigils for generated gem RBIs for gem `gem` to level `level` (`level` can be one of `ignore`, `false`, `true`, `strict`, or `strong`, see [the Sorbet docs](https://sorbet.org/docs/static#file-level-granularity-strictness-levels) for more details).
90
90
 
91
91
  ## Contributing
92
92
 
@@ -74,14 +74,18 @@ module Tapioca
74
74
  compile(symbol, constant)
75
75
  end
76
76
 
77
- sig { params(symbol: String).returns(BasicObject) }
77
+ sig { params(symbol: String).returns(BasicObject).checked(:never) }
78
78
  def resolve_constant(symbol)
79
79
  Object.const_get(symbol, false)
80
80
  rescue NameError, LoadError, RuntimeError, ArgumentError, TypeError
81
81
  nil
82
82
  end
83
83
 
84
- sig { params(name: T.nilable(String), constant: BasicObject).returns(T.nilable(String)) }
84
+ sig do
85
+ params(name: T.nilable(String), constant: BasicObject)
86
+ .returns(T.nilable(String))
87
+ .checked(:never)
88
+ end
85
89
  def compile(name, constant)
86
90
  return unless constant
87
91
  return unless name
@@ -96,7 +100,11 @@ module Tapioca
96
100
  compile_constant(name, constant)
97
101
  end
98
102
 
99
- sig { params(name: String, constant: BasicObject).returns(T.nilable(String)) }
103
+ sig do
104
+ params(name: String, constant: BasicObject)
105
+ .returns(T.nilable(String))
106
+ .checked(:never)
107
+ end
100
108
  def compile_constant(name, constant)
101
109
  case constant
102
110
  when Module
@@ -122,12 +130,17 @@ module Tapioca
122
130
  indented("#{name} = #{constant_name}")
123
131
  end
124
132
 
125
- sig { params(name: String, value: BasicObject).returns(T.nilable(String)) }
133
+ sig do
134
+ params(name: String, value: BasicObject)
135
+ .returns(T.nilable(String))
136
+ .checked(:never)
137
+ end
126
138
  def compile_object(name, value)
139
+ return if symbol_ignored?(name)
127
140
  indented("#{name} = T.let(T.unsafe(nil), #{type_name_of(value)})")
128
141
  end
129
142
 
130
- sig { params(value: BasicObject).returns(String) }
143
+ sig { params(value: BasicObject).returns(String).checked(:never) }
131
144
  def type_name_of(value)
132
145
  klass = class_of(value)
133
146
 
@@ -528,7 +541,7 @@ module Tapioca
528
541
  end
529
542
  end
530
543
 
531
- sig { params(constant: BasicObject).returns(Class) }
544
+ sig { params(constant: BasicObject).returns(Class).checked(:never) }
532
545
  def class_of(constant)
533
546
  Kernel.instance_method(:class).bind(constant).call
534
547
  end
@@ -543,7 +556,7 @@ module Tapioca
543
556
  Module.instance_method(:name).bind(constant).call
544
557
  end
545
558
 
546
- sig { params(constant: BasicObject).returns(Class) }
559
+ sig { params(constant: BasicObject).returns(Class).checked(:never) }
547
560
  def singleton_class_of(constant)
548
561
  Object.instance_method(:singleton_class).bind(constant).call
549
562
  end
@@ -578,8 +591,12 @@ module Tapioca
578
591
  def qualified_name_of(constant)
579
592
  name = name_of(constant)
580
593
  return if name.nil?
581
- name.prepend("::") unless name.start_with?("::")
582
- name
594
+
595
+ if name.start_with?("::")
596
+ name
597
+ else
598
+ "::#{name}"
599
+ end
583
600
  end
584
601
 
585
602
  sig { params(constant: Class).returns(T.nilable(Class)) }
@@ -587,7 +604,7 @@ module Tapioca
587
604
  Class.instance_method(:superclass).bind(constant).call
588
605
  end
589
606
 
590
- sig { params(constant: Module, other: BasicObject).returns(T::Boolean) }
607
+ sig { params(constant: Module, other: BasicObject).returns(T::Boolean).checked(:never) }
591
608
  def are_equal?(constant, other)
592
609
  BasicObject.instance_method(:equal?).bind(constant).call(other)
593
610
  end
@@ -21,6 +21,7 @@ module Tapioca
21
21
  end
22
22
 
23
23
  def ignore_symbol?(symbol)
24
+ symbol = symbol[2..-1] if symbol.start_with?("::")
24
25
  ignored_symbols.include?(symbol)
25
26
  end
26
27
 
@@ -7,7 +7,7 @@ module Tapioca
7
7
  class Gemfile
8
8
  extend(T::Sig)
9
9
 
10
- Spec = T.type_alias(
10
+ Spec = T.type_alias do
11
11
  T.any(
12
12
  T.all(
13
13
  ::Bundler::StubSpecification,
@@ -15,7 +15,7 @@ module Tapioca
15
15
  ),
16
16
  ::Gem::Specification
17
17
  )
18
- )
18
+ end
19
19
 
20
20
  sig { void }
21
21
  def initialize
@@ -33,8 +33,8 @@ module Tapioca
33
33
  definition
34
34
  .resolve
35
35
  .materialize(specs)
36
- .reject { |spec| ignore_gem_spec?(spec) }
37
36
  .map { |spec| Gem.new(spec) }
37
+ .reject { |gem| gem.ignore?(dir) }
38
38
  .uniq(&:rbi_file_name)
39
39
  .sort_by(&:rbi_file_name)
40
40
  end
@@ -70,32 +70,30 @@ module Tapioca
70
70
  @definition ||= Bundler::Dsl.evaluate(gemfile, lockfile, {})
71
71
  end
72
72
 
73
- IGNORED_GEMS = T.let(%w{
74
- sorbet sorbet-static sorbet-runtime tapioca
75
- }.freeze, T::Array[String])
76
-
77
- sig { params(spec: Spec).returns(T::Boolean) }
78
- def ignore_gem_spec?(spec)
79
- IGNORED_GEMS.include?(spec.name) ||
80
- spec.full_gem_path.start_with?(gemfile_dir)
81
- end
82
-
83
73
  sig { returns(String) }
84
- def gemfile_dir
74
+ def dir
85
75
  File.expand_path(gemfile.path + "/..")
86
76
  end
87
77
 
88
78
  class Gem
89
79
  extend(T::Sig)
90
80
 
81
+ IGNORED_GEMS = T.let(%w{
82
+ sorbet sorbet-static sorbet-runtime tapioca
83
+ }.freeze, T::Array[String])
84
+
85
+ sig { returns(String) }
86
+ attr_reader :full_gem_path
87
+
91
88
  sig { params(spec: Spec).void }
92
89
  def initialize(spec)
93
90
  @spec = T.let(spec, Tapioca::Gemfile::Spec)
91
+ @full_gem_path = T.let(@spec.full_gem_path.to_s, String)
94
92
  end
95
93
 
96
- sig { returns(String) }
97
- def full_gem_path
98
- @spec.full_gem_path.to_s
94
+ sig { params(gemfile_dir: String).returns(T::Boolean) }
95
+ def ignore?(gemfile_dir)
96
+ gem_ignored? || gem_in_app_dir?(gemfile_dir)
99
97
  end
100
98
 
101
99
  sig { returns(T::Array[Pathname]) }
@@ -119,6 +117,23 @@ module Tapioca
119
117
  def rbi_file_name
120
118
  "#{name}@#{version}.rbi"
121
119
  end
120
+
121
+ private
122
+
123
+ sig { returns(T::Boolean) }
124
+ def gem_ignored?
125
+ IGNORED_GEMS.include?(name)
126
+ end
127
+
128
+ sig { params(gemfile_dir: String).returns(T::Boolean) }
129
+ def gem_in_app_dir?(gemfile_dir)
130
+ !gem_in_bundle_path? && full_gem_path.start_with?(gemfile_dir)
131
+ end
132
+
133
+ sig { returns(T::Boolean) }
134
+ def gem_in_bundle_path?
135
+ full_gem_path.start_with?(Bundler.bundle_path.to_s)
136
+ end
122
137
  end
123
138
  end
124
139
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.2.6"
5
+ VERSION = "0.2.7"
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.2.6
4
+ version: 0.2.7
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: 2020-01-08 00:00:00.000000000 Z
14
+ date: 2020-02-13 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: pry