Skip to content

Commit

Permalink
Reduce mixin signatures
Browse files Browse the repository at this point in the history
Due to the large number of mixins, convenience is significantly reduced due to performance degradation rather than comprehensiveness.
The default is to give priority to performance.
  • Loading branch information
ksss committed Feb 4, 2025
1 parent 095dab2 commit f95e173
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
13 changes: 8 additions & 5 deletions lib/orthoses/active_record/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
module Orthoses
module ActiveRecord
class Relation
def initialize(loader)
def initialize(loader, strict: false)
@loader = loader
@strict = strict
end

def call
Expand All @@ -24,10 +25,12 @@ def call
klass.singleton_methods(false).each do |singleton_method|
c << "def #{singleton_method}: (*untyped, **untyped) -> untyped"
end
(klass.singleton_class.included_modules - ::ActiveRecord::Relation.included_modules).each do |mod|
mname = Utils.module_name(mod) or next
store[mname].header = "module #{mname}"
c << "include #{mname}"
if @strict
(klass.singleton_class.included_modules - ::ActiveRecord::Relation.included_modules).each do |mod|
mname = Utils.module_name(mod) or next
store[mname].header = "module #{mname}"
c << "include #{mname}"
end
end
end

Expand Down
13 changes: 7 additions & 6 deletions lib/orthoses/active_record/relation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ class RelationTest::User < ::ActiveRecord::Base
t.error("expect=\n```rbs\n#{expect}```\n, but got \n```rbs\n#{actual}```\n")
end

expect = [
'def singleton!:',
'include ActiveRecord::Core::ClassMethods'
]
actual = store["RelationTest::User::GeneratedRelationMethods"].to_rbs
unless expect.all? { |e| actual.include?(e) }
t.error("expect has #{expect}, but got \n```rbs\n#{actual}```\n")
expect = <<~RBS
module RelationTest::User::GeneratedRelationMethods
def singleton!: (*untyped, **untyped) -> untyped
end
RBS
unless expect == actual
t.error("expect=\n```rbs\n#{expect}```\n, but got \n```rbs\n#{actual}```\n")
end
end
end

0 comments on commit f95e173

Please sign in to comment.