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

Fix signature of GroupChain#size method #2153

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
11 changes: 8 additions & 3 deletions lib/tapioca/dsl/compilers/active_record_relations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,12 @@ def create_group_chain_methods(klass)
return_type: "T.self_type",
)

(CALCULATION_METHODS + [:size]).each do |method_name|
klass.create_method(
"size",
return_type: "Integer",
)

CALCULATION_METHODS.each do |method_name|
case method_name
when :average, :maximum, :minimum
klass.create_method(
Expand Down Expand Up @@ -400,9 +405,9 @@ def create_group_chain_methods(klass)
],
return_type: "T::Hash[T.untyped, Integer]",
)
when :sum, :size
when :sum
klass.create_method(
method_name.to_s,
"sum",
parameters: [
create_opt_param("column_name", type: "T.nilable(T.any(String, Symbol))", default: "nil"),
create_block_param("block", type: "T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))"),
Expand Down
16 changes: 8 additions & 8 deletions spec/tapioca/dsl/compilers/active_record_relations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,8 @@ def maximum(column_name); end
sig { params(column_name: T.any(String, Symbol)).returns(T::Hash[T.untyped, T.untyped]) }
def minimum(column_name); end

sig { params(column_name: T.nilable(T.any(String, Symbol)), block: T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))).returns(T::Hash[T.untyped, T.any(Integer, Float, BigDecimal)]) }
def size(column_name = nil, &block); end
sig { returns(Integer) }
def size; end

sig { params(column_name: T.nilable(T.any(String, Symbol)), block: T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))).returns(T::Hash[T.untyped, T.any(Integer, Float, BigDecimal)]) }
def sum(column_name = nil, &block); end
Expand Down Expand Up @@ -765,8 +765,8 @@ def maximum(column_name); end
sig { params(column_name: T.any(String, Symbol)).returns(T::Hash[T.untyped, T.untyped]) }
def minimum(column_name); end

sig { params(column_name: T.nilable(T.any(String, Symbol)), block: T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))).returns(T::Hash[T.untyped, T.any(Integer, Float, BigDecimal)]) }
def size(column_name = nil, &block); end
sig { returns(Integer) }
def size; end

sig { params(column_name: T.nilable(T.any(String, Symbol)), block: T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))).returns(T::Hash[T.untyped, T.any(Integer, Float, BigDecimal)]) }
def sum(column_name = nil, &block); end
Expand Down Expand Up @@ -1386,8 +1386,8 @@ def maximum(column_name); end
sig { params(column_name: T.any(String, Symbol)).returns(T::Hash[T.untyped, T.untyped]) }
def minimum(column_name); end

sig { params(column_name: T.nilable(T.any(String, Symbol)), block: T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))).returns(T::Hash[T.untyped, T.any(Integer, Float, BigDecimal)]) }
def size(column_name = nil, &block); end
sig { returns(Integer) }
def size; end

sig { params(column_name: T.nilable(T.any(String, Symbol)), block: T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))).returns(T::Hash[T.untyped, T.any(Integer, Float, BigDecimal)]) }
def sum(column_name = nil, &block); end
Expand Down Expand Up @@ -1491,8 +1491,8 @@ def maximum(column_name); end
sig { params(column_name: T.any(String, Symbol)).returns(T::Hash[T.untyped, T.untyped]) }
def minimum(column_name); end

sig { params(column_name: T.nilable(T.any(String, Symbol)), block: T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))).returns(T::Hash[T.untyped, T.any(Integer, Float, BigDecimal)]) }
def size(column_name = nil, &block); end
sig { returns(Integer) }
def size; end

sig { params(column_name: T.nilable(T.any(String, Symbol)), block: T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))).returns(T::Hash[T.untyped, T.any(Integer, Float, BigDecimal)]) }
def sum(column_name = nil, &block); end
Expand Down
Loading