Skip to content

Commit

Permalink
activerecord: Add types for create_with to singleton that inherited a…
Browse files Browse the repository at this point in the history
  • Loading branch information
dak2 committed Dec 26, 2024
1 parent ccbd2bb commit 599024e
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gems/activerecord/6.0/_test/activerecord-generated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Article < ActiveRecord::Base
User.in_order_of(:id, [1, 5, 3])
User.offset(5).limit(10)
User.count
User.create_with(name: 'name', age: 1)
User.create_with(nil)

t = User.arel_table
User.limit(10).select(:id, "name", t[:age].as("years"), t[:email])
6 changes: 6 additions & 0 deletions gems/activerecord/6.0/activerecord-6.0.rbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
module ActiveRecord
class Base
module ClassMethods[Model, Relation, PrimaryKey]
def create_with: (nil | Hash[untyped, untyped]) -> Relation
end
end

module Enum
def enum: (Hash[Symbol, untyped] definitions) -> void
end
Expand Down
2 changes: 2 additions & 0 deletions gems/activerecord/6.1/_test/activerecord-6.1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
User.strict_loading(false)
user.strict_loading!
user.strict_loading?
User.create_with(secret: 'secret', key: 'key')
User.create_with(nil)
1 change: 1 addition & 0 deletions gems/activerecord/6.1/activerecord-6.1.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module ActiveRecord

module ClassMethods[Model, Relation, PrimaryKey]
def strict_loading: (?bool value) -> Relation
def create_with: (nil | Hash[untyped, untyped]) -> Relation
end
end

Expand Down
2 changes: 2 additions & 0 deletions gems/activerecord/7.0/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Article < ActiveRecord::Base
User.upsert_all([{ id: 1, name: 'James' }], returning: %i[id name], unique_by: :id, record_timestamps: true)
User.strict_loading
User.strict_loading(false)
User.create_with(name: 'name', age: 1)
User.create_with(nil)
user = User.new(secret: 'dummy', key: 'dummy', token: 'dummy', phrase: 'dummy')
user.encrypt
user.encrypted_attribute?(:secret)
Expand Down
1 change: 1 addition & 0 deletions gems/activerecord/7.0/activerecord-7.0.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module ActiveRecord

module ClassMethods[Model, Relation, PrimaryKey]
def strict_loading: (?bool value) -> Relation
def create_with: (nil | Hash[untyped, untyped]) -> Relation
end
end

Expand Down
2 changes: 2 additions & 0 deletions gems/activerecord/7.1/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Article < ActiveRecord::Base
User.with(admin_users: User.where(role: 0))
User.strict_loading
User.strict_loading(false)
User.create_with(name: 'name', age: 1)
User.create_with(nil)
user = User.new(secret: 'dummy', key: 'dummy', token: 'dummy', phrase: 'dummy')
user.encrypt
user.encrypted_attribute?(:secret)
Expand Down
1 change: 1 addition & 0 deletions gems/activerecord/7.1/activerecord-7.1.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module ActiveRecord

module ClassMethods[Model, Relation, PrimaryKey]
def strict_loading: (?bool value) -> Relation
def create_with: (nil | Hash[untyped, untyped]) -> Relation
end
end

Expand Down
2 changes: 2 additions & 0 deletions gems/activerecord/7.2/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Article < ApplicationRecord
User.with(admin_users: User.where(role: 0))
User.strict_loading
User.strict_loading(false)
User.create_with(name: 'name', age: 1)
User.create_with(nil)
user = User.new(secret: 'dummy', key: 'dummy', token: 'dummy', phrase: 'dummy')
user.encrypt
user.encrypted_attribute?(:secret)
Expand Down
1 change: 1 addition & 0 deletions gems/activerecord/7.2/activerecord-7.2.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module ActiveRecord

module ClassMethods[Model, Relation, PrimaryKey]
def strict_loading: (?bool value) -> Relation
def create_with: (nil | Hash[untyped, untyped]) -> Relation
end
end

Expand Down

0 comments on commit 599024e

Please sign in to comment.