orthoses 0.7.0 → 0.8.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: 894390a9b9736bc6c773da2d8522b76a47a4f345f1eb48c847b4dc2cf691cfe4
4
- data.tar.gz: 9189fdd9d19a953227093f99cd04e8a20f258e231e40b40ed5e7582cd5ac107c
3
+ metadata.gz: 2941ebbe45d7ab2dc9ad009628db52419a6a3b18a1fd1ad870164ab017bbb5e1
4
+ data.tar.gz: 5a33b4b63f62b820f4642d56661cebd393c3381363a8f727655f123568b2784b
5
5
  SHA512:
6
- metadata.gz: 90d06b917b9fb9aa88a18bae14bd792fe85520a8d8cf9f75c8d422f080cfe992036f3b1d2b9e115f1a6ff315478899a2b275d6ae99bdd6c5598bdcc21e3ddf56
7
- data.tar.gz: 4d134a532af9973901e87fa48d1e96d9ca1469b46fa266d548476d252f8651dce94b40ee3de799dd7aa10f5d961e06d330048b5c833af88eee536965779dd131
6
+ metadata.gz: bd9a27c8a8f6752fc73c2c65b8dbb0edcb9885425667a8a067a6d56cc2bb32473db565ea41089ad0f8b26c598275afa83e2fb3bbde6f668fc095c942bb75af01
7
+ data.tar.gz: 4b6c157a129e1e3dfab42737ba1a4ba0f9c1c5ffe25defb693de3bce39f63fdcc746b155d030e273162e550ada315281553d921475bd4a333bf362a46e5a58bd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- orthoses (0.7.0)
4
+ orthoses (0.8.0)
5
5
  rbs (~> 2.0)
6
6
 
7
7
  GEM
@@ -23,17 +23,17 @@ module Orthoses
23
23
  end
24
24
 
25
25
  def call
26
- Module.prepend(Hook)
26
+ ::Module.prepend(Hook)
27
27
 
28
28
  attr = CallTracer.new
29
29
  attr_accessor = CallTracer.new
30
30
  attr_reader = CallTracer.new
31
31
  attr_writer = CallTracer.new
32
32
 
33
- store = attr.trace(Hook.method(:attr)) do
34
- attr_accessor.trace(Hook.method(:attr_accessor)) do
35
- attr_reader.trace(Hook.method(:attr_reader)) do
36
- attr_writer.trace(Hook.method(:attr_writer)) do
33
+ store = attr.trace(Hook.instance_method(:attr)) do
34
+ attr_accessor.trace(Hook.instance_method(:attr_accessor)) do
35
+ attr_reader.trace(Hook.instance_method(:attr_reader)) do
36
+ attr_writer.trace(Hook.instance_method(:attr_writer)) do
37
37
  @loader.call
38
38
  end
39
39
  end
@@ -42,22 +42,23 @@ module Orthoses
42
42
 
43
43
  store["Module"].body.delete("prepend Orthoses::Attribute::Hook")
44
44
 
45
- attr.result.each do |method, argument|
46
- m = method.receiver.to_s.match(/#<Class:([\w:]+)>/)
45
+ attr.captures.each do |capture|
46
+ m = capture.method.receiver.to_s.match(/#<Class:([\w:]+)>/)
47
47
  if m && m[1]
48
48
  receiver_name = m[1]
49
49
  prefix = "self."
50
50
  else
51
- receiver_name = Utils.module_name(method.receiver) or next
51
+ receiver_name = Utils.module_name(capture.method.receiver) or next
52
52
  prefix = nil
53
53
  end
54
54
  content = store[receiver_name]
55
- if argument[:names][1].equal?(true)
56
- content << "attr_accessor #{prefix}#{argument[:names][0]}: untyped"
57
- elsif argument[:names][1].equal?(false)
58
- content << "attr_reader #{prefix}#{argument[:names][0]}: untyped"
55
+ names = capture.argument[:names]
56
+ if names[1].equal?(true)
57
+ content << "attr_accessor #{prefix}#{names[0]}: untyped"
58
+ elsif names[1].equal?(false)
59
+ content << "attr_reader #{prefix}#{names[0]}: untyped"
59
60
  else
60
- argument[:names].each do |name|
61
+ names.each do |name|
61
62
  content << "attr_reader #{prefix}#{name}: untyped"
62
63
  end
63
64
  end
@@ -79,16 +80,17 @@ module Orthoses
79
80
  private
80
81
 
81
82
  def each_definition(call_tracer)
82
- call_tracer.result.each do |method, argument|
83
- m = method.receiver.to_s.match(/#<Class:([\w:]+)>/)
83
+ call_tracer.captures.each do |capture|
84
+ m = capture.method.receiver.to_s.match(/#<Class:([\w:]+)>/)
85
+ names = capture.argument[:names]
84
86
  if m && m[1]
85
87
  receiver_name = m[1]
86
- argument[:names].each do |name|
88
+ names.each do |name|
87
89
  yield [receiver_name, "self.#{name}"]
88
90
  end
89
91
  else
90
- receiver_name = Utils.module_name(method.receiver) or next
91
- argument[:names].each do |name|
92
+ receiver_name = Utils.module_name(capture.method.receiver) or next
93
+ names.each do |name|
92
94
  yield [receiver_name, name]
93
95
  end
94
96
  end
@@ -7,16 +7,19 @@ module Orthoses
7
7
  # scope.trace(ActiveRecord::Base.method(:scope)) do
8
8
  # @loader.call
9
9
  # end
10
- # scope.result.each do |method, argument|
11
- # argument[:name]
12
- # argument[:body]
13
- # argument[:block]
10
+ # scope.captures.each do |capture|
11
+ # capture.argument[:name]
12
+ # capture.argument[:body]
13
+ # capture.argument[:block]
14
14
  # end
15
15
  class CallTracer
16
- attr_accessor :result
16
+ class Capture < Struct.new(:method, :argument, keyword_init: true)
17
+ end
18
+
19
+ attr_accessor :captures
17
20
 
18
21
  def initialize
19
- @result = []
22
+ @captures = []
20
23
  end
21
24
 
22
25
  def trace(target, &block)
@@ -46,7 +49,11 @@ module Orthoses
46
49
  end
47
50
  end
48
51
  end
49
- @result << [called_method, argument]
52
+
53
+ @captures << Capture.new(
54
+ method: called_method,
55
+ argument: argument,
56
+ )
50
57
  end
51
58
  t.enable(target: target, &block)
52
59
  end
@@ -86,15 +86,29 @@ module Orthoses
86
86
  writer = RBS::Writer.new(out: out)
87
87
  decls.each do |decl|
88
88
  next unless decl.respond_to?(:members)
89
+ last_visibility = :public
89
90
  decl.members.each do |member|
90
91
  next if member.respond_to?(:members)
91
92
  case member
92
93
  when RBS::AST::Declarations::Constant
93
94
  next unless @constant_filter.nil? || @constant_filter.call(member)
95
+ when RBS::AST::Members::MethodDefinition
96
+ if last_visibility == :private && member.kind != :singleton_instance
97
+ member.instance_variable_set(:@visibility, :private)
98
+ end
94
99
  when RBS::AST::Members::Mixin
95
100
  next unless @mixin_filter.nil? || @mixin_filter.call(member)
96
101
  when RBS::AST::Members::Attribute
97
102
  next unless @attribute_filter.nil? || @attribute_filter.call(member)
103
+ if last_visibility == :private
104
+ member.instance_variable_set(:@visibility, :private)
105
+ end
106
+ when RBS::AST::Members::Public
107
+ last_visibility = :public
108
+ next
109
+ when RBS::AST::Members::Private
110
+ last_visibility = :private
111
+ next
98
112
  end
99
113
  writer.write_member(member)
100
114
  end
@@ -2,31 +2,44 @@
2
2
 
3
3
  module Orthoses
4
4
  class DelegateClass
5
+ module Hook
6
+ def inherited(subclass)
7
+ super
8
+ end
9
+ end
10
+
5
11
  def initialize(loader)
6
12
  @loader = loader
7
13
  end
8
14
 
9
15
  def call
10
16
  require 'delegate'
11
- classes = []
12
- Class.class_eval do
13
- define_method(:inherited) do |subclass|
14
- classes << [subclass, self]
15
- end
16
- end
17
+ ::Class.prepend(Hook)
18
+
19
+ inherited = CallTracer.new
20
+
17
21
  delegate_class_super_map = {}
18
22
  delegate_class_tracer = TracePoint.new(:return) do |tp|
19
23
  return_value = tp.return_value
20
24
  superclass = tp.binding.local_variable_get(:superclass)
21
25
  delegate_class_super_map[return_value] = superclass
22
26
  end
27
+
23
28
  store = delegate_class_tracer.enable(target: method(:DelegateClass)) do
24
- @loader.call
29
+ inherited.trace(Hook.instance_method(:inherited)) do
30
+ @loader.call
31
+ end
25
32
  end
26
- classes.each do |subclass, superclass|
33
+
34
+ store["Class"].body.delete("prepend Orthoses::DelegateClass::Hook")
35
+
36
+ inherited.captures.each do |capture|
37
+ superclass = capture.method.receiver
27
38
  if delegate_to_class = delegate_class_super_map[superclass]
39
+ subclass = capture.argument[:subclass]
28
40
  subclass_name = Utils.module_name(subclass)
29
41
  next unless subclass_name
42
+
30
43
  delegate_to_class_name = Utils.module_name(delegate_to_class)
31
44
  next unless delegate_to_class_name
32
45
 
@@ -34,6 +47,7 @@ module Orthoses
34
47
  store[subclass_name].header = header
35
48
  end
36
49
  end
50
+
37
51
  store
38
52
  end
39
53
 
@@ -2,49 +2,71 @@
2
2
 
3
3
  module Orthoses
4
4
  class Mixin
5
+ module Hook
6
+ def include(*modules)
7
+ super
8
+ end
9
+ def extend(*modules)
10
+ super
11
+ end
12
+ def prepend(*modules)
13
+ super
14
+ end
15
+ end
16
+
5
17
  def initialize(loader, if: nil)
6
18
  @loader = loader
7
19
  @if = binding.local_variable_get(:if)
8
20
  end
9
21
 
10
22
  def call
11
- modules = Hash.new { |h, k| h[k] = [] }
12
- ::Module.module_eval do
13
- define_method(:included) do |mod|
14
- modules[mod] << [:include, self]
15
- end
23
+ ::Module.prepend(Hook)
16
24
 
17
- define_method(:extended) do |mod|
18
- modules[mod] << [:extend, self]
19
- end
25
+ include = CallTracer.new
26
+ extend = CallTracer.new
27
+ prepend = CallTracer.new
20
28
 
21
- define_method(:prepended) do |mod|
22
- modules[mod] << [:prepend, self]
29
+ store = include.trace(Hook.instance_method(:include)) do
30
+ extend.trace(Hook.instance_method(:extend)) do
31
+ prepend.trace(Hook.instance_method(:prepend)) do
32
+ @loader.call
33
+ end
23
34
  end
24
35
  end
25
36
 
26
- store = @loader.call
37
+ store["Module"].body.delete("prepend Orthoses::Mixin::Hook")
38
+
39
+ collect_definitions(store, include, :include)
40
+ collect_definitions(store, extend, :extend)
41
+ collect_definitions(store, prepend, :prepend)
42
+
43
+ store
44
+ end
45
+
46
+ private
27
47
 
28
- modules.each do |base_mod, how_mods|
48
+ def collect_definitions(store, call_tracer, how)
49
+ call_tracer.captures.each do |capture|
50
+ base_mod = capture.method.receiver
29
51
  next unless base_mod.kind_of?(Module)
52
+
30
53
  base_mod_name = Utils.module_name(base_mod)
31
54
  next unless base_mod_name
32
55
 
33
- lines = how_mods.filter.map do |how, mod|
56
+ content = store[base_mod_name]
57
+ capture.argument[:modules].each do |mod|
34
58
  mod_name = Utils.module_name(mod)
35
59
  next unless mod_name
60
+
36
61
  known_type_params = Utils.known_type_params(mod)
37
62
  next unless known_type_params.nil? || known_type_params.empty?
63
+
38
64
  next unless @if.nil? || @if.call(base_mod, how, mod)
39
65
 
40
66
  store[mod_name]
41
-
42
- "#{how} #{mod_name}"
67
+ content << "#{how} #{mod_name}"
43
68
  end
44
- store[base_mod_name].concat(lines)
45
69
  end
46
-
47
- store
48
70
  end
49
71
  end
50
72
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Orthoses
4
- VERSION = "0.7.0"
4
+ VERSION = "0.8.0"
5
5
  end
@@ -3,7 +3,6 @@
3
3
  class Orthoses::Attribute
4
4
  def initialize: (Orthoses::_Call loader) -> void
5
5
  def call: () -> Orthoses::store
6
- private
7
- def each_definition: (untyped call_tracer) { (untyped) -> untyped } -> untyped
6
+ private def each_definition: (untyped call_tracer) { (untyped) -> untyped } -> untyped
8
7
  @loader: Orthoses::_Call
9
8
  end
@@ -1,8 +1,8 @@
1
1
  # THIS IS GENERATED CODE from `$ rake generate_self_sig`
2
2
 
3
3
  class Orthoses::Builder
4
- def initialize: () { () -> untyped } -> void
5
- def use: (untyped middleware, *untyped args, **untyped key) { () -> untyped } -> untyped
4
+ def initialize: () ?{ () -> untyped } -> void
5
+ def use: (untyped middleware, *untyped args, **untyped key) ?{ () -> untyped } -> untyped
6
6
  def run: (untyped loader) -> untyped
7
7
  def to_loader: () -> untyped
8
8
 
@@ -0,0 +1,6 @@
1
+ # THIS IS GENERATED CODE from `$ rake generate_self_sig`
2
+
3
+ class Orthoses::CallTracer::Capture < ::Struct[untyped]
4
+ def method: () -> Method
5
+ def argument: () -> Hash[Symbol, untyped]
6
+ end
@@ -4,5 +4,5 @@ class Orthoses::CallTracer
4
4
  def initialize: () -> void
5
5
 
6
6
  def trace: [T] (Method | UnboundMethod) ?{ () -> T } -> T
7
- attr_accessor result: Array[[ Method, Hash[Symbol, untyped] ]]
7
+ attr_accessor captures: Array[Capture]
8
8
  end
@@ -3,8 +3,7 @@
3
3
  class Orthoses::Content::DuplicationChecker
4
4
  def initialize: (untyped decl) -> void
5
5
  def update_decl: () -> untyped
6
- private
7
- def drop_known_method_definition: (untyped uniq_map) -> untyped
8
- def member_to_s: (untyped member) -> untyped
9
- def member_key: (untyped member) -> untyped
6
+ private def drop_known_method_definition: (untyped uniq_map) -> untyped
7
+ private def member_to_s: (untyped member) -> untyped
8
+ private def member_key: (untyped member) -> untyped
10
9
  end
@@ -7,12 +7,11 @@ class Orthoses::Content::Environment
7
7
  def <<: (RBS::AST::Declarations::t decl) -> RBS::Environment
8
8
  def write_to: (store: Orthoses::store) -> void
9
9
  def each: () { (Orthoses::Content) -> void } -> void
10
- private
11
10
  # Avoid `RBS::GenericParameterMismatchError` from like rbs_prototype_rb
12
11
  # class Array # <= RBS::GenericParameterMismatchError
13
12
  # end
14
- def avoid_generic_parameter_mismatch_error: () -> untyped
15
- def decls_to_lines: (untyped decls) -> untyped
13
+ private def avoid_generic_parameter_mismatch_error: () -> untyped
14
+ private def decls_to_lines: (untyped decls) -> untyped
16
15
  type constant_filter = ^(RBS::AST::Declarations::Constant) -> boolish
17
16
  type mixin_filter = ^(RBS::AST::Members::Mixin) -> boolish
18
17
  type attribute_filter = ^(RBS::AST::Members::Attribute) -> boolish
@@ -3,11 +3,10 @@
3
3
  class Orthoses::Content::HeaderBuilder
4
4
  def initialize: (env: untyped) -> void
5
5
  def build: (entry: untyped, ?name_hint: untyped?) -> untyped
6
- private
7
- def build_module: (entry: untyped, ?name_hint: untyped?) -> ::String
8
- def build_class: (entry: untyped, ?name_hint: untyped?) -> ::String
9
- def build_super_class: (untyped primary) -> (nil | untyped)
10
- def build_interface: (entry: untyped, ?name_hint: untyped?) -> ::String
11
- def name_and_params: (untyped name, untyped params) -> ::String
12
- def name_and_args: (untyped name, untyped args) -> (::String | nil)
6
+ private def build_module: (entry: untyped, ?name_hint: untyped?) -> ::String
7
+ private def build_class: (entry: untyped, ?name_hint: untyped?) -> ::String
8
+ private def build_super_class: (untyped primary) -> (nil | untyped)
9
+ private def build_interface: (entry: untyped, ?name_hint: untyped?) -> ::String
10
+ private def name_and_params: (untyped name, untyped params) -> ::String
11
+ private def name_and_args: (untyped name, untyped args) -> (::String | nil)
13
12
  end
@@ -6,15 +6,13 @@ class Orthoses::Content
6
6
  def concat: (Array[String]) -> void
7
7
  def to_rbs: () -> String
8
8
  def to_decl: () -> untyped
9
+ private def original_rbs: () -> ::String
9
10
 
10
- private
11
- def original_rbs: () -> ::String
12
-
13
- def uniqed_body_string: () -> String
14
- def uniqed_body_decl: () -> RBS::AST::Declarations::t
15
- def auto_header: () -> (nil | untyped)
16
- def temporary_type_params: (untyped name) -> untyped
17
- def type_params: (untyped name) -> untyped
11
+ private def uniqed_body_string: () -> String
12
+ private def uniqed_body_decl: () -> RBS::AST::Declarations::t
13
+ private def auto_header: () -> (nil | untyped)
14
+ private def temporary_type_params: (untyped name) -> untyped
15
+ private def type_params: (untyped name) -> untyped
18
16
  attr_reader name: String
19
17
  attr_reader body: Array[String]
20
18
  attr_accessor header: String?
@@ -0,0 +1,5 @@
1
+ # THIS IS GENERATED CODE from `$ rake generate_self_sig`
2
+
3
+ module Orthoses::DelegateClass::Hook
4
+ def inherited: (untyped subclass) -> untyped
5
+ end
@@ -0,0 +1,9 @@
1
+ # THIS IS GENERATED CODE from `$ rake generate_self_sig`
2
+
3
+ module Orthoses::Mixin::Hook
4
+ def include: (*untyped modules) -> untyped
5
+
6
+ def extend: (*untyped modules) -> untyped
7
+
8
+ def prepend: (*untyped modules) -> untyped
9
+ end
@@ -1,6 +1,8 @@
1
1
  # THIS IS GENERATED CODE from `$ rake generate_self_sig`
2
2
 
3
3
  class Orthoses::Mixin
4
- def initialize: (untyped loader, ?if: untyped?) -> void
5
- def call: () -> untyped
4
+ def initialize: (Orthoses::_Call loader) -> void
5
+ def call: () -> Orthoses::store
6
+ private def collect_definitions: (Orthoses::store store, Orthoses::CallTracer call_tracer, :include | :extend | :prepend how) -> void
7
+ @loader: Orthoses::_Call
6
8
  end
@@ -19,7 +19,7 @@ module Orthoses::Utils
19
19
 
20
20
  def self.module_to_type_name: (Module) -> RBS::TypeName?
21
21
 
22
- def self.known_type_params: (Module | String) -> Array[RBS::AST::TypeParam]
22
+ def self.known_type_params: (Module | String) -> Array[RBS::AST::TypeParam]?
23
23
 
24
24
  def self.new_store: () -> Orthoses::store
25
25
 
data/sig/orthoses.rbs CHANGED
@@ -1,7 +1,7 @@
1
1
  # THIS IS GENERATED CODE from `$ rake generate_self_sig`
2
2
 
3
3
  module Orthoses
4
- VERSION: "0.7.0"
4
+ VERSION: "0.8.0"
5
5
 
6
6
  attr_accessor self.logger: ::Logger
7
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orthoses
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.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: rbs
@@ -73,6 +73,7 @@ files:
73
73
  - sig/orthoses/builder.rbs
74
74
  - sig/orthoses/builder/call_logable.rbs
75
75
  - sig/orthoses/call_tracer.rbs
76
+ - sig/orthoses/call_tracer/capture.rbs
76
77
  - sig/orthoses/const_load_error.rbs
77
78
  - sig/orthoses/constant.rbs
78
79
  - sig/orthoses/content.rbs
@@ -81,9 +82,11 @@ files:
81
82
  - sig/orthoses/content/header_builder.rbs
82
83
  - sig/orthoses/create_file_by_name.rbs
83
84
  - sig/orthoses/delegate_class.rbs
85
+ - sig/orthoses/delegate_class/hook.rbs
84
86
  - sig/orthoses/filter.rbs
85
87
  - sig/orthoses/load_rbs.rbs
86
88
  - sig/orthoses/mixin.rbs
89
+ - sig/orthoses/mixin/hook.rbs
87
90
  - sig/orthoses/name_space_error.rbs
88
91
  - sig/orthoses/object_space_all.rbs
89
92
  - sig/orthoses/pp.rbs