racer-rb 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ module Racer
2
+ class Railtie < Rails::Railtie
3
+ initializer "racer.extend_active_support_test_case" do
4
+ ActiveSupport.on_load(:active_support_test_case) do
5
+ if defined?(Racer::MinitestPlugin)
6
+ parallelize_teardown do
7
+ Racer.flush
8
+ end
9
+
10
+ at_exit do
11
+ Racer.flush
12
+ end
13
+
14
+ setup do
15
+ Racer.start(path_regex: %r(\A#{Rails.root.to_s}/(app|lib|test|spec)/), max_generic_depth: 3)
16
+ end
17
+
18
+ teardown do
19
+ Racer.stop
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ config.before_initialize do
26
+ if defined?(Racer::MinitestPlugin) || defined?(Racer::RSpecPlugin)
27
+ Racer.start(path_regex: %r(\A#{Rails.root.to_s}/(app|lib|test|spec)/), max_generic_depth: 3)
28
+ end
29
+ end
30
+
31
+ config.after_initialize do
32
+ if defined?(Racer::MinitestPlugin) || defined?(Racer::RSpecPlugin)
33
+ Racer.stop
34
+ Racer.flush
35
+ end
36
+ end
37
+ end
38
+ end
data/lib/racer/rb.rb ADDED
@@ -0,0 +1,2 @@
1
+ # Entrypoint required by bundler because the gem is called "racer-rb"
2
+ require "racer"
@@ -0,0 +1,19 @@
1
+ # This ensures that racer can inject it's railtie even if rails was not fully required yet
2
+ #
3
+ # This happens if running a test with a path argument because the test:prepare task is not being executed and rails did not fully initialize
4
+ # when requiring racer/minitest.
5
+ #
6
+ # If no path argument was passed the rails:prepare rake task is being executed. In this case racer is being required during the rails boot process
7
+ # and installs the railtie accordingly.
8
+ begin
9
+ require "rails"
10
+ rescue LoadError
11
+ # no-op rails not available
12
+ end
13
+
14
+ require "racer"
15
+ require_relative "rspec_plugin"
16
+
17
+ Racer::RSpecPlugin.agent_pid = Racer.start_agent(stop_at_exit: false, collectors: [Racer::Collectors::RBSCollector.new(libraries: ["json", "minitest", "tempfile", "base64", "pathname", "logger", "uri", "erb", "date", "ipaddr", "securerandom"])])
18
+
19
+ puts "Agent started with pid #{Racer::RSpecPlugin.agent_pid}"
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Racer
4
+ class RSpecPlugin
5
+ class << self
6
+ attr_accessor :agent_pid
7
+
8
+ def configure(config)
9
+ at_exit do
10
+ Racer.flush
11
+ end
12
+
13
+ config.before do
14
+ Racer.start(path_regex: %r(\A#{Rails.root.to_s}/(app|lib|test|spec)/), max_generic_depth: 3)
15
+ end
16
+
17
+ config.after do
18
+ Racer.stop
19
+ end
20
+
21
+ config.after(:suite) do
22
+ Racer.flush
23
+ Racer.stop_agent(Racer::RSpecPlugin.agent_pid)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,121 @@
1
+ class Racer::Trace
2
+ attr_reader :method_owner, :method_callee, :method_name, :method_kind, :method_visibility, :return_type, :params, :block_param, :constant_updates
3
+
4
+ KINDS = [
5
+ :instance,
6
+ :singleton
7
+ ].freeze
8
+
9
+ VISIBILITIES = [
10
+ :public,
11
+ :private,
12
+ :protected
13
+ ].freeze
14
+
15
+ def initialize(method_owner:, method_callee:, method_name:, method_kind:, method_visibility:, return_type:, params:, constant_updates: [], block_param: nil)
16
+ @method_owner = method_owner
17
+ @method_callee = method_callee
18
+ @method_name = method_name
19
+ @method_kind = method_kind
20
+ @method_visibility = method_visibility
21
+ @return_type = return_type
22
+ @params = params
23
+ @block_param = block_param
24
+ @constant_updates = constant_updates
25
+ end
26
+
27
+ class Constant
28
+ attr_reader :name, :anonymous, :type, :superclass, :included_modules, :prepended_modules, :extended_modules
29
+
30
+ TYPES = [
31
+ :module,
32
+ :class
33
+ ].freeze
34
+
35
+ def initialize(name:, anonymous:, type:, superclass: nil, included_modules: [], prepended_modules: [], extended_modules: [])
36
+ @name = name
37
+ @anonymous = anonymous
38
+ @type = type
39
+ @superclass = superclass
40
+ @included_modules = included_modules
41
+ @prepended_modules = prepended_modules
42
+ @extended_modules = extended_modules
43
+ end
44
+ end
45
+
46
+ class ConstantInstance
47
+ attr_reader :name, :singleton, :generic_arguments
48
+
49
+ def initialize(name:, singleton:, generic_arguments:)
50
+ @name = name
51
+ @singleton = singleton
52
+ @generic_arguments = generic_arguments
53
+ end
54
+
55
+ def ==(other)
56
+ other.name == name && generic_arguments == other.generic_arguments && singleton == other.singleton
57
+ end
58
+ alias eql? ==
59
+
60
+ def hash
61
+ [name, singleton, generic_arguments].hash
62
+ end
63
+ end
64
+
65
+ class Param
66
+ attr_reader :name, :type_name, :type
67
+
68
+ TYPES = [
69
+ :required,
70
+ :optional,
71
+ :rest,
72
+ :keyword_required,
73
+ :keyword_optional,
74
+ :keyword_rest
75
+ ].freeze
76
+
77
+
78
+ def initialize(name:, type_name:, type:)
79
+ @name = name
80
+ @type_name = type_name
81
+ @type = type
82
+ end
83
+
84
+ def ==(other)
85
+ other.name == name && other.type_name == type_name && other.type == type
86
+ end
87
+ alias eql? ==
88
+
89
+ def hash
90
+ [name, type_name, type].hash
91
+ end
92
+ end
93
+
94
+ class BlockParam
95
+ attr_reader :name, :traces
96
+
97
+ def initialize(name:, traces:)
98
+ @name = name
99
+ @traces = traces
100
+ end
101
+
102
+ def ==(other)
103
+ other.is_a?(BlockParam) && name == other.name && traces == other.traces
104
+ end
105
+ end
106
+
107
+ class BlockTrace
108
+ attr_reader :self_type, :return_type, :params, :block_param
109
+
110
+ def initialize(return_type:, params:, self_type: nil, block_param: nil)
111
+ @return_type = return_type
112
+ @params = params
113
+ @block_param = block_param
114
+ @self_type = self_type
115
+ end
116
+
117
+ def ==(other)
118
+ return_type == other.return_type && params == other.params && block_param == other.block_param && self_type == other.self_type
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Racer
4
+ VERSION = "0.1.0"
5
+ end
data/lib/racer.rb ADDED
@@ -0,0 +1,40 @@
1
+ require "racer/racer"
2
+ require "racer/trace"
3
+ require "racer/collectors/rbs_collector"
4
+ require "racer/agent"
5
+
6
+ require "racer/rails/railtie" if defined?(Rails::Railtie)
7
+
8
+ require "socket"
9
+
10
+ module Racer
11
+ SERVER_PATH = "/tmp/racer.sock"
12
+
13
+ def self.start_agent(collectors: [Racer::Collectors::RBSCollector.new], stop_at_exit: true)
14
+ pid = fork(&Racer::Agent.new(SERVER_PATH, collectors).method(:start))
15
+
16
+ until File.exist?(SERVER_PATH)
17
+ sleep 0.1
18
+ end
19
+
20
+ at_exit do
21
+ flush
22
+ if stop_at_exit
23
+ stop_agent(pid)
24
+ end
25
+ end
26
+
27
+ pid
28
+ end
29
+
30
+ def self.stop_agent(pid)
31
+ Process.kill("HUP", pid)
32
+ Process.wait(pid)
33
+ rescue Errno::ESRCH
34
+ # Agent already stopped
35
+ end
36
+
37
+ def self.start(path_regex: nil, max_generic_depth: 2)
38
+ __c_start(path_regex, max_generic_depth)
39
+ end
40
+ end
data/sig/racer.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Racer
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: racer-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Richard Böhme
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rbs
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ description: Runtime type tracer for ruby
27
+ email:
28
+ - richard.boehme1999@gmail.com
29
+ executables: []
30
+ extensions:
31
+ - ext/racer/extconf.rb
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rubocop.yml"
35
+ - ".tool-versions"
36
+ - CHANGELOG.md
37
+ - CODE_OF_CONDUCT.md
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - ext/racer/extconf.rb
42
+ - ext/racer/racer.cc
43
+ - ext/racer/racer.hh
44
+ - ext/racer/tiny_queue.cc
45
+ - ext/racer/tiny_queue.hh
46
+ - ext/racer/traces.cc
47
+ - ext/racer/traces.hh
48
+ - ext/racer/worker.cc
49
+ - ext/racer/worker.hh
50
+ - lib/racer.rb
51
+ - lib/racer/agent.rb
52
+ - lib/racer/collectors/rbs_collector.rb
53
+ - lib/racer/minitest.rb
54
+ - lib/racer/minitest_plugin.rb
55
+ - lib/racer/rails/railtie.rb
56
+ - lib/racer/rb.rb
57
+ - lib/racer/rspec.rb
58
+ - lib/racer/rspec_plugin.rb
59
+ - lib/racer/trace.rb
60
+ - lib/racer/version.rb
61
+ - sig/racer.rbs
62
+ homepage: https://github.com/richardboehme/racer-rb
63
+ licenses:
64
+ - MIT
65
+ metadata:
66
+ allowed_push_host: https://rubygems.org
67
+ homepage_uri: https://github.com/richardboehme/racer-rb
68
+ source_code_uri: https://github.com/richardboehme/racer-rb
69
+ changelog_uri: https://github.com/richardboehme/racer-rb/blob/main/CHANGELOG.md
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 4.0.0
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 4.0.3
85
+ specification_version: 4
86
+ summary: Runtime type tracer for ruby
87
+ test_files: []