Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override types of CollectionProxy #289

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/rbs_rails/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ class #{relation_class_name(abs: false)} < ::ActiveRecord::Relation
class ActiveRecord_Associations_CollectionProxy < ::ActiveRecord::Associations::CollectionProxy
include #{generated_relation_methods_name}
include ::_ActiveRecord_Relation[#{klass_name}, #{pk_type}]

def build: (?ActiveRecord::Associations::CollectionProxy::_EachPair attributes) ?{ () -> untyped } -> #{klass_name}
| (Array[ActiveRecord::Associations::CollectionProxy::_EachPair] attributes) ?{ () -> untyped } -> Array[#{klass_name}]
def create: (?ActiveRecord::Associations::CollectionProxy::_EachPair attributes) ?{ () -> untyped } -> #{klass_name}
| (Array[ActiveRecord::Associations::CollectionProxy::_EachPair] attributes) ?{ () -> untyped } -> Array[#{klass_name}]
def create!: (?ActiveRecord::Associations::CollectionProxy::_EachPair attributes) ?{ () -> untyped } -> #{klass_name}
| (Array[ActiveRecord::Associations::CollectionProxy::_EachPair] attributes) ?{ () -> untyped } -> Array[#{klass_name}]
def reload: () -> Array[#{klass_name}]

def replace: (Array[#{klass_name}]) -> void
def delete: (*#{klass_name} | #{pk_type}) -> Array[#{klass_name}]
def destroy: (*#{klass_name} | #{pk_type}) -> Array[#{klass_name}]
def <<: (*#{klass_name} | Array[#{klass_name}]) -> self
def prepend: (*#{klass_name} | Array[#{klass_name}]) -> self
end
RBS
end
Expand Down
14 changes: 14 additions & 0 deletions test/expectations/user.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,19 @@ class User < ::ApplicationRecord
class ActiveRecord_Associations_CollectionProxy < ::ActiveRecord::Associations::CollectionProxy
include ::User::GeneratedRelationMethods
include ::_ActiveRecord_Relation[::User, ::Integer]

def build: (?ActiveRecord::Associations::CollectionProxy::_EachPair attributes) ?{ () -> untyped } -> ::User
| (Array[ActiveRecord::Associations::CollectionProxy::_EachPair] attributes) ?{ () -> untyped } -> Array[::User]
def create: (?ActiveRecord::Associations::CollectionProxy::_EachPair attributes) ?{ () -> untyped } -> ::User
| (Array[ActiveRecord::Associations::CollectionProxy::_EachPair] attributes) ?{ () -> untyped } -> Array[::User]
def create!: (?ActiveRecord::Associations::CollectionProxy::_EachPair attributes) ?{ () -> untyped } -> ::User
| (Array[ActiveRecord::Associations::CollectionProxy::_EachPair] attributes) ?{ () -> untyped } -> Array[::User]
def reload: () -> Array[::User]

def replace: (Array[::User]) -> void
def delete: (*::User | ::Integer) -> Array[::User]
def destroy: (*::User | ::Integer) -> Array[::User]
def <<: (*::User | Array[::User]) -> self
def prepend: (*::User | Array[::User]) -> self
end
end
Loading