Skip to content

Commit

Permalink
Merge pull request #2153 from Shopify/uk-relation-size-method
Browse files Browse the repository at this point in the history
Fix signature of `GroupChain#size` method
  • Loading branch information
paracycle authored Jan 14, 2025
2 parents 895fe10 + 451fd23 commit 7527f5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
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

0 comments on commit 7527f5b

Please sign in to comment.