Skip to content

Commit

Permalink
Merge pull request #34 from ksss/typename
Browse files Browse the repository at this point in the history
Support rbs v3.8
  • Loading branch information
ksss authored Feb 3, 2025
2 parents 095dab2 + 46df1f2 commit b4ad998
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/orthoses/active_support/concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def call
def members_prototype_of(mod_name)
mod = Object.const_get(mod_name)
runtime = ::RBS::Prototype::Runtime.new(patterns: nil, env: nil, merge: false)
type_name = TypeName(mod_name)
type_name = ::RBS::TypeName.parse(mod_name)
[].tap do |members|
runtime.generate_methods(mod, type_name, members)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/orthoses/active_support/delegation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def initialize(store)
end

def find(mod_name, name, kind, argument)
typename = TypeName(mod_name).absolute!
typename = ::RBS::TypeName.parse(mod_name).absolute!

if definition_method = build_definition(typename, kind)&.methods&.[](name)
# found in env
Expand Down
12 changes: 6 additions & 6 deletions lib/orthoses/active_support/time_with_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def call
])

TIME_MODULES = Set.new([
TypeName("::Time"),
TypeName("::DateAndTime::Zones"),
TypeName("::DateAndTime::Calculations"),
TypeName("::DateAndTime::Compatibility")
::RBS::TypeName.parse("::Time"),
::RBS::TypeName.parse("::DateAndTime::Zones"),
::RBS::TypeName.parse("::DateAndTime::Calculations"),
::RBS::TypeName.parse("::DateAndTime::Compatibility")
])

NONEED_METHODS = Set.new(%i[
Expand Down Expand Up @@ -65,8 +65,8 @@ def add_signature(env, content)
end

def each_line_from_core_time_definition(store)
type_name_time = TypeName("::Time")
type_name_time_with_zone = TypeName("::ActiveSupport::TimeWithZone")
type_name_time = ::RBS::TypeName.parse("::Time")
type_name_time_with_zone = ::RBS::TypeName.parse("::ActiveSupport::TimeWithZone")
env = Utils.rbs_environment(collection: true, cache: false)

add_signature(env, store["Time"])
Expand Down
4 changes: 2 additions & 2 deletions lib/orthoses/active_support/time_with_zone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ class State

definetion_builder = RBS::DefinitionBuilder.new(env: env.resolve_type_names)
begin
unless definetion_builder.build_instance(TypeName("::Time")).methods[:defined_method].instance_of?(RBS::Definition::Method)
unless definetion_builder.build_instance(::RBS::TypeName.parse("::Time")).methods[:defined_method].instance_of?(RBS::Definition::Method)
t.error("#defined_method was dropped.")
end
rescue => err
t.error("\n```rbs\n#{store["Time"].to_rbs}```\n#{err.inspect}")
end
begin
definetion_builder.build_instance(TypeName("::ActiveSupport::TimeWithZone"))
definetion_builder.build_instance(::RBS::TypeName.parse("::ActiveSupport::TimeWithZone"))
rescue => err
t.error("\n```rbs\n#{store["ActiveSupport::TimeWithZone"].to_rbs}```\n#{err.inspect}")
end
Expand Down
1 change: 1 addition & 0 deletions lib/orthoses/rails.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'orthoses'
require_relative 'shims'

require_relative 'action_mailer'
require_relative 'active_model'
Expand Down
18 changes: 18 additions & 0 deletions lib/orthoses/shims.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# RBS 3.8
unless RBS::TypeName.singleton_class.method_defined?(:parse)
module RBS
class TypeName
def self.parse(string)
absolute = string.start_with?("::")

*path, name = string.delete_prefix("::").split("::").map(&:to_sym)
raise unless name

TypeName.new(
name: name,
namespace: RBS::Namespace.new(path: path, absolute: absolute)
)
end
end
end
end

0 comments on commit b4ad998

Please sign in to comment.