orthoses-rails 0.3.0 → 0.4.0

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: c109c955af37e4574528af34d8a3695450abf39f5359729625307c368b961259
4
- data.tar.gz: 29d4ad1bf3e9d4a8d18e3108899c83cd133221d3f2dc1b3f3a6cb2165684c830
3
+ metadata.gz: f98262e6c8d3c7f75039f41d1a14b991de17171702663d111b7dc6e9d8cac2bb
4
+ data.tar.gz: 28db8b6a6bdee762946bb2c7287233804543a1e5f7f735e56ac1c2d8875dc457
5
5
  SHA512:
6
- metadata.gz: f491dab5ce7ce402058fec79a42c1c776434bbb88adedd8928b70031f614ef57051d9501c279c628903269413e55db24e3c9493101e79c758cfb5a202ba41f37
7
- data.tar.gz: 701d609fb62bfa2d9ac0e226090844bc93d526328121516cc07cb3c8424c3f2992b4f365c3cb0680379c972238b68a3fdaa87d36a0c4849803732a5603b09f3f
6
+ metadata.gz: 13f1a9891b7a526aeed309854ed14bf6ee3e2b712ede4e7d0c63c33f8358f641061b6e81ad12773eff3e91043051f7ab16bb8aa349fb0c3ff38e4a7ce6b2654c
7
+ data.tar.gz: f3dd8dfea66c1b0477a9d17f736161e34b3a7a7c4fdaef3fc3948f84c60a6ac79fcfe1678392b8ca32746db4dc1b8f43a66e25b6d0dd4a6904440c1d0bc70cc0
@@ -39,7 +39,7 @@ def generate(out_dir, version)
39
39
  loader = -> () {
40
40
  # require "rails/all"
41
41
  require "rails/app_updater"
42
- require "active_support"
42
+ require "active_support/all"
43
43
  require "active_record"
44
44
  require "active_job"
45
45
  require "active_model"
@@ -88,6 +88,9 @@ def generate(out_dir, version)
88
88
  # FIXME: too hard
89
89
  return false if name.include?("::Generators")
90
90
 
91
+ # Ignore known sig
92
+ return false if Orthoses::Utils.rbs_defined_class?(name, collection: true) && content.body.empty?
93
+
91
94
  true
92
95
  }
93
96
  use Orthoses::Constant,
@@ -192,12 +195,12 @@ def generate(out_dir, version)
192
195
  # MigrationProxy cannot resolve name since class alias.
193
196
  store["ActiveRecord::NullMigration"].header = nil
194
197
  end
198
+ use Orthoses::DelegateClass
199
+ use Orthoses::Attribute
195
200
  use Orthoses::Mixin,
196
201
  if: -> (base_mod, how, mod) {
197
202
  mod != Enumerable # TODO
198
203
  }
199
- use Orthoses::DelegateClass
200
- use Orthoses::Attribute
201
204
  use Orthoses::RBSPrototypeRB,
202
205
  paths: Dir.glob('src/{railties,action{cable,mailbox,mailer,pack,text,view},active{job,model,record,storage,support}}/lib/**/*.rb'),
203
206
  constant_filter: -> (member) { false },
@@ -205,40 +208,166 @@ def generate(out_dir, version)
205
208
  run loader
206
209
  end.call
207
210
 
208
- sh "rbs --collection ../../rbs_collection.yaml -I #{out_dir}/#{version}/ validate --silent"
209
211
  # $ cat out/7.0/**/*.rbs | wc
210
- # 72210 332252 2551928
212
+ # 68367 333370 2555378
211
213
  end
212
214
 
213
- namespace :generate do
214
- task :v60 do
215
- switch_branch("6-0-stable")
216
- run_child_process { generate("out", "6.0") }
217
- end
215
+ versions = %w[
216
+ 6.0
217
+ 6.1
218
+ 7.0
219
+ ]
218
220
 
219
- task :v61 do
220
- switch_branch("6-1-stable")
221
- run_child_process { generate("out", "6.1") }
222
- end
221
+ task :clean do
222
+ FileUtils.rm_rf("out")
223
+ FileUtils.rm_rf("export")
224
+ end
223
225
 
224
- task :v70 do
225
- switch_branch("7-0-stable")
226
- run_child_process { generate("out", "7.0") }
226
+ namespace :generate do
227
+ versions.each do |version|
228
+ task version do
229
+ switch_branch("#{version.tr('.', '-')}-stable")
230
+ run_child_process { generate("out", version) }
231
+ end
227
232
  end
228
- end
229
233
 
230
- task :clean do
231
- FileUtils.rm_rf("out")
234
+ desc "generate all library"
235
+ task :all => versions
232
236
  end
233
237
 
234
- task :test do
235
- sh "steep check"
238
+ namespace :export do
239
+ versions.each do |version|
240
+ task version do |t|
241
+ export = "export/activesupport/#{version}"
242
+
243
+ sh "rm -fr #{export}"
244
+ sh "mkdir -p #{export}"
245
+
246
+ # minimum
247
+ sh "cp -a out/#{version}/active_support.rbs #{export}"
248
+ sh "cp -a out/#{version}/active_support #{export}"
249
+ sh "rm #{export}/active_support/railtie.rbs"
250
+
251
+ # core_ext
252
+ %w[
253
+ array benchmark big_decimal class date date_and_time date_time digest
254
+ enumerable file hash integer kernel load_error marshal module name_error numeric
255
+ object pathname range regexp securerandom string symbol time uri
256
+ ].each do |lib|
257
+ out = "out/#{version}/#{lib}"
258
+ sh "cp -a #{out} #{export}" if File.exist?(out)
259
+ sh "cp -a #{out}.rbs #{export}" if File.exist?("#{out}.rbs")
260
+ end
261
+
262
+ Pathname(export).join("EXTERNAL_TODO.rbs").write(<<~RBS)
263
+ module Minitest
264
+ class Test
265
+ def name: () -> untyped
266
+ def assert_raises: () -> untyped
267
+ def refute_empty: () -> untyped
268
+ def refute_equal: () -> untyped
269
+ def refute_in_delta: () -> untyped
270
+ def refute_in_epsilon: () -> untyped
271
+ def refute_includes: () -> untyped
272
+ def refute_instance_of: () -> untyped
273
+ def refute_kind_of: () -> untyped
274
+ def refute_match: () -> untyped
275
+ def refute_nil: () -> untyped
276
+ def refute_operator: () -> untyped
277
+ def refute_predicate: () -> untyped
278
+ def refute_respond_to: () -> untyped
279
+ def refute_same: () -> untyped
280
+ end
281
+ end
282
+ module DRb
283
+ module DRbUndumped
284
+ end
285
+ end
286
+ module Concurrent
287
+ class Map
288
+ end
289
+ end
290
+ RBS
291
+
292
+ case version
293
+ when "6.0", "6.1"
294
+ sh "rm -fr #{export}/uri"
295
+ when "7.0"
296
+ # deprecated
297
+ sh "rm -fr #{export}/uri{,.rbs}"
298
+ end
299
+
300
+ Pathname(export).join('_scripts').tap(&:mkdir).join('test').write(<<~'RUBY')
301
+ #!/usr/bin/env bash
302
+
303
+ # set -eou => Exit command with non-zero status code, Output logs of every command executed, Treat unset variables as an error when substituting.
304
+ set -eou pipefail
305
+ # Internal Field Separator - Linux shell variable
306
+ IFS=$'\n\t'
307
+ # Print shell input lines
308
+ set -v
309
+
310
+ # Set RBS_DIR variable to change directory to execute type checks using `steep check`
311
+ RBS_DIR=$(cd $(dirname $0)/..; pwd)
312
+ # Set REPO_DIR variable to validate RBS files added to the corresponding folder
313
+ REPO_DIR=$(cd $(dirname $0)/../../..; pwd)
314
+ # Validate RBS files, using the bundler environment present
315
+ bundle exec rbs --repo=$REPO_DIR \
316
+ -r digest -r benchmark -r time -r monitor -r date -r singleton \
317
+ -r logger -r mutex_m -r pathname -r json \
318
+ -r nokogiri \
319
+ -r activesupport validate --silent
320
+
321
+ cd ${RBS_DIR}/_test
322
+ # Run type checks
323
+ bundle exec steep check
324
+ RUBY
325
+ sh "chmod +x #{Pathname(export).join('_scripts').join('test')}"
326
+ Pathname(export).join('_test').tap(&:mkdir).join('Steepfile').write(<<~RUBY)
327
+ D = Steep::Diagnostic
328
+
329
+ target :test do
330
+ signature "."
331
+ check "."
332
+
333
+ repo_path "../../../"
334
+
335
+ library "benchmark"
336
+ library "date"
337
+ library "digest"
338
+ library "json"
339
+ library "logger"
340
+ library "monitor"
341
+ library "mutex_m"
342
+ library "pathname"
343
+ library "singleton"
344
+ library "time"
345
+
346
+ library "nokogiri"
347
+
348
+ library "activesupport:#{version}"
349
+
350
+ configure_code_diagnostics(D::Ruby.all_error)
351
+ end
352
+ RUBY
353
+ Pathname(export).join('_test').join('test.rb').write(<<~'RUBY')
354
+ require 'active_support/all'
355
+
356
+ # Test ActiveSupport::NumericWithFormat
357
+ 42.to_s
358
+ 42.to_s(:phone)
359
+ RUBY
360
+
361
+ sh "rbs --collection ../../rbs_collection.yaml -I #{export} validate --silent"
362
+ end
363
+ end
364
+
365
+ desc "export all library"
366
+ task :all => versions
236
367
  end
237
368
 
238
369
  task default: [
239
370
  :clean,
240
-
241
- 'generate:v60',
242
- 'generate:v61',
243
- 'generate:v70',
371
+ 'generate:all',
372
+ 'export:all',
244
373
  ]
@@ -27,12 +27,12 @@ module Orthoses
27
27
  @loader.call
28
28
  end
29
29
 
30
- call_tracer.result.each do |method, argument|
31
- next unless method.receiver.kind_of?(Class)
32
- base_name = Utils.module_name(method.receiver)
30
+ call_tracer.captures.each do |capture|
31
+ next unless capture.method.receiver.kind_of?(Class)
32
+ base_name = Utils.module_name(capture.method.receiver)
33
33
  next unless base_name
34
34
 
35
- attribute = argument[:attribute] || :password
35
+ attribute = capture.argument[:attribute] || :password
36
36
  full_name = if ::ActiveModel::VERSION::MAJOR < 6
37
37
  "ActiveModel::SecurePassword::InstanceMethodsOnActivation"
38
38
  else
@@ -28,22 +28,22 @@ module Orthoses
28
28
  @loader.call
29
29
  end
30
30
 
31
- call_tracer.result.each do |method, argument|
32
- receiver_name = Orthoses::Utils.module_name(method.receiver)
31
+ call_tracer.captures.each do |capture|
32
+ receiver_name = Orthoses::Utils.module_name(capture.method.receiver)
33
33
  next unless receiver_name
34
34
 
35
35
  methods = []
36
36
  if ::ActiveSupport::VERSION::MAJOR < 6
37
- options = argument[:attrs].extract_options!
38
- argument[:instance_reader] = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true)
39
- argument[:instance_writer] = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true)
40
- argument[:instance_predicate] = options.fetch(:instance_predicate, true)
41
- argument[:default_value] = options.fetch(:default, nil)
37
+ options = capture.argument[:attrs].extract_options!
38
+ capture.argument[:instance_reader] = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true)
39
+ capture.argument[:instance_writer] = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true)
40
+ capture.argument[:instance_predicate] = options.fetch(:instance_predicate, true)
41
+ capture.argument[:default_value] = options.fetch(:default, nil)
42
42
  end
43
43
 
44
44
  content = store[receiver_name]
45
45
 
46
- argument[:attrs].each do |name|
46
+ capture.argument[:attrs].each do |name|
47
47
  next unless @if.nil? || @if.call(method, name)
48
48
 
49
49
  # skip internal attribute
@@ -52,11 +52,11 @@ module Orthoses
52
52
  next if name == :attributes_to_define_after_schema_loads
53
53
 
54
54
  methods << "def self.#{name}: () -> untyped"
55
- methods << "def self.#{name}?: () -> bool" if argument[:instance_predicate]
55
+ methods << "def self.#{name}?: () -> bool" if capture.argument[:instance_predicate]
56
56
  methods << "def self.#{name}=: (untyped value) -> untyped"
57
- methods << "def #{name}: () -> untyped" if argument[:instance_reader]
58
- methods << "def #{name}?: () -> bool" if argument[:instance_predicate] && argument[:instance_reader]
59
- methods << "def #{name}=: (untyped value) -> untyped" if argument[:instance_writer]
57
+ methods << "def #{name}: () -> untyped" if capture.argument[:instance_reader]
58
+ methods << "def #{name}?: () -> bool" if capture.argument[:instance_predicate] && capture.argument[:instance_reader]
59
+ methods << "def #{name}=: (untyped value) -> untyped" if capture.argument[:instance_writer]
60
60
  # In RBS, `foo=` and attr_writer :foo cannot live together.
61
61
  content.body.delete_if { |line| line.start_with?("attr_writer #{name}:") }
62
62
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Orthoses
4
+ module ActiveSupport
5
+ # <= 6.1
6
+ # def config_accessor(*names, instance_reader: true, instance_writer: true, instance_accessor: true)
7
+ # >= 7
8
+ # def config_accessor(*names, instance_reader: true, instance_writer: true, instance_accessor: true, default: nil)
9
+ class Configurable
10
+ def initialize(loader)
11
+ @loader = loader
12
+ end
13
+
14
+ def call
15
+ config_accessor = CallTracer.new
16
+ store = config_accessor.trace(::ActiveSupport::Configurable::ClassMethods.instance_method(:config_accessor)) do
17
+ @loader.call
18
+ end
19
+ config_accessor.captures.each do |capture|
20
+ mod_name = Utils.module_name(capture.method.receiver) or next
21
+ content = store[mod_name]
22
+ capture.argument[:names].each do |name|
23
+ content << "def self.#{name}: () -> untyped"
24
+ content << "def self.#{name}=: (untyped value) -> untyped"
25
+ if capture.argument[:instance_accessor]
26
+ content << "def #{name}: () -> untyped" if capture.argument[:instance_reader]
27
+ content << "def #{name}=: (untyped value) -> untyped" if capture.argument[:instance_writer]
28
+ end
29
+ end
30
+ end
31
+
32
+ store
33
+ end
34
+ end
35
+ end
36
+ end
@@ -24,13 +24,13 @@ module Orthoses
24
24
 
25
25
  resource = Resource.new(store)
26
26
 
27
- delegate.result.each do |method, argument|
28
- receiver_name = Utils.module_name(method.receiver) or next
27
+ delegate.captures.each do |capture|
28
+ receiver_name = Utils.module_name(capture.method.receiver) or next
29
29
  receiver_content = store[receiver_name]
30
- case argument[:to]
30
+ case capture.argument[:to]
31
31
  when Module
32
- to_module_name = Utils.module_name(argument[:to]) or next
33
- argument[:methods].each do |arg|
32
+ to_module_name = Utils.module_name(capture.argument[:to]) or next
33
+ capture.argument[:methods].each do |arg|
34
34
  if sig = resource.build_signature(to_module_name, arg, :singleton, false)
35
35
  receiver_content << "# defined by `delegate` to: #{to_module_name}"
36
36
  receiver_content << sig
@@ -39,21 +39,21 @@ module Orthoses
39
39
  end
40
40
  end
41
41
  else
42
- to_name = argument[:to].to_s.to_sym
42
+ to_name = capture.argument[:to].to_s.to_sym
43
43
  tag, to_return_type = resource.find(receiver_name, to_name, :instance, false)
44
44
  raise "bug" if tag == :multi
45
45
  if to_return_type.nil?
46
- Orthoses.logger.warn("[ActiveSupport::Delegation] Ignore #{argument.inspect}")
46
+ Orthoses.logger.warn("[ActiveSupport::Delegation] Ignore #{capture.argument.inspect}")
47
47
  next
48
48
  end
49
49
  if to_return_type.instance_of?(RBS::Types::Bases::Any)
50
- argument[:methods].each do |method|
50
+ capture.argument[:methods].each do |method|
51
51
  receiver_content << "# defined by `delegate` to: :#{to_name}(#{to_return_type})"
52
52
  receiver_content << "def #{method}: (*untyped, **untyped) -> untyped"
53
53
  end
54
54
  else
55
55
  to_typename = to_return_type.name.relative!.to_s
56
- argument[:methods].each do |method|
56
+ capture.argument[:methods].each do |method|
57
57
  if sig = resource.build_signature(to_typename, method, :instance, true)
58
58
  receiver_content << "# defined by `delegate` to: :#{to_name}(#{to_return_type})"
59
59
  receiver_content << sig
@@ -0,0 +1,7 @@
1
+ module ActiveSupport
2
+ module Multibyte
3
+ class Chars
4
+ attr_reader wrapped_string: ::String
5
+ end
6
+ end
7
+ end
@@ -22,14 +22,14 @@ module Orthoses
22
22
  end
23
23
  end
24
24
 
25
- mattr_reader.result.each do |method, argument|
26
- base = Orthoses::Utils.module_name(method.receiver) || next
25
+ mattr_reader.captures.each do |capture|
26
+ base = Orthoses::Utils.module_name(capture.method.receiver) || next
27
27
  methods = []
28
- argument[:syms].each do |sym|
28
+ capture.argument[:syms].each do |sym|
29
29
  next unless @if.nil? || @if.call(method, sym)
30
30
 
31
31
  methods << "def self.#{sym}: () -> untyped"
32
- if argument[:instance_reader] && argument[:instance_accessor]
32
+ if capture.argument[:instance_reader] && capture.argument[:instance_accessor]
33
33
  methods << "def #{sym}: () -> untyped"
34
34
  end
35
35
  end
@@ -38,14 +38,14 @@ module Orthoses
38
38
  store[base].concat(methods)
39
39
  end
40
40
 
41
- mattr_writer.result.each do |method, argument|
42
- base = Orthoses::Utils.module_name(method.receiver) || next
41
+ mattr_writer.captures.each do |capture|
42
+ base = Orthoses::Utils.module_name(capture.method.receiver) || next
43
43
  methods = []
44
- argument[:syms].each do |sym|
44
+ capture.argument[:syms].each do |sym|
45
45
  next unless @if.nil? || @if.call(method, sym)
46
46
 
47
47
  methods << "def self.#{sym}=: (untyped val) -> untyped"
48
- if argument[:instance_writer] && argument[:instance_accessor]
48
+ if capture.argument[:instance_writer] && capture.argument[:instance_accessor]
49
49
  methods << "def #{sym}=: (untyped val) -> untyped"
50
50
  end
51
51
  end
@@ -7,11 +7,6 @@ module Orthoses
7
7
  @loader = loader
8
8
  end
9
9
 
10
- LOAD_PATHS = [
11
- File.expand_path("known_sig/time.rbs", __dir__),
12
- File.expand_path("known_sig/active_support/time_with_zone.rbs", __dir__),
13
- ]
14
-
15
10
  # Time <= (known Time)
16
11
  # TimeWithZone <= (known TimeWithZone, known Time, core Time)
17
12
  def call
@@ -37,7 +32,7 @@ module Orthoses
37
32
 
38
33
  def each_line_from_core_time_definition(store)
39
34
  type_name_time = TypeName("::Time")
40
- env = Utils.rbs_environment(collection: true).dup
35
+ env = Utils.rbs_environment(collection: true, cache: false)
41
36
  env << store["Time"].to_decl
42
37
  env << store["DateAndTime"].to_decl
43
38
  env << store["DateAndTime::Zones"].to_decl
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'active_support/class_attribute'
4
- require_relative 'active_support/concern'
4
+ require_relative 'active_support/configurable'
5
5
  require_relative 'active_support/delegation'
6
6
  require_relative 'active_support/mattr_accessor'
7
7
  require_relative 'active_support/time_with_zone'
@@ -15,7 +15,6 @@ module Orthoses
15
15
  # end
16
16
  def self.each
17
17
  yield ClassAttribute
18
- yield Concern
19
18
  yield Delegation
20
19
  yield MattrAccessor
21
20
  yield TimeWithZone
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Orthoses
4
4
  module Rails
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
@@ -32,5 +32,5 @@ Gem::Specification.new do |spec|
32
32
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
33
  spec.require_paths = ["lib"]
34
34
 
35
- spec.add_dependency "orthoses"
35
+ spec.add_dependency "orthoses", ">= 0.8"
36
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orthoses-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-04 00:00:00.000000000 Z
11
+ date: 2022-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: orthoses
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.8'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.8'
27
27
  description: Orthoses middleware collection for Ruby on Rails
28
28
  email:
29
29
  - co000ri@gmail.com
@@ -123,11 +123,12 @@ files:
123
123
  - lib/orthoses/active_record/query_methods.rb
124
124
  - lib/orthoses/active_support.rb
125
125
  - lib/orthoses/active_support/class_attribute.rb
126
- - lib/orthoses/active_support/concern.rb
126
+ - lib/orthoses/active_support/configurable.rb
127
127
  - lib/orthoses/active_support/delegation.rb
128
128
  - lib/orthoses/active_support/known_sig.rb
129
129
  - lib/orthoses/active_support/known_sig/7.0/active_support/callbacks/callback_chain.rbs
130
130
  - lib/orthoses/active_support/known_sig/7.0/active_support/hash_with_indifferent_access.rbs
131
+ - lib/orthoses/active_support/known_sig/7.0/active_support/multibyte/chars.rbs
131
132
  - lib/orthoses/active_support/known_sig/7.0/hash_with_indifferent_access.rbs
132
133
  - lib/orthoses/active_support/known_sig/7.0/time.rbs
133
134
  - lib/orthoses/active_support/mattr_accessor.rb
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Orthoses
4
- module ActiveSupport
5
- class Concern
6
- def initialize(loader)
7
- @loader = loader
8
- end
9
-
10
- def call
11
- target_method = begin
12
- ::ActiveSupport::Concern.method(:extended)
13
- rescue NameError => err
14
- Orthoses.logger.warn("Run `require 'active_support/concern'` and retry because #{err}")
15
- require 'active_support/concern'
16
- retry
17
- end
18
-
19
- extended = CallTracer.new
20
- store = extended.trace(target_method) do
21
- @loader.call
22
- end
23
- extended.result.each do |method, argument|
24
- base_name = Orthoses::Utils.module_name(argument[:base])
25
- next unless base_name
26
- store[argument[:base].to_s] << "extend ActiveSupport::Concern"
27
- end
28
- store
29
- end
30
- end
31
- end
32
- end