Skip to content

Commit

Permalink
Add hash return type for relation groupchain size
Browse files Browse the repository at this point in the history
  • Loading branch information
marknuzz committed Oct 15, 2024
1 parent 3948457 commit f9a128f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/tapioca/dsl/compilers/active_record_relations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def create_group_chain_methods(klass)
return_type: "T.self_type",
)

CALCULATION_METHODS.each do |method_name|
(CALCULATION_METHODS + [:size]).each do |method_name|
case method_name
when :average, :maximum, :minimum
klass.create_method(
Expand Down Expand Up @@ -404,9 +404,9 @@ def create_group_chain_methods(klass)
],
return_type: "T::Hash[T.untyped, Integer]",
)
when :sum
when :sum, :size
klass.create_method(
"sum",
method_name.to_s,
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
12 changes: 12 additions & 0 deletions spec/tapioca/dsl/compilers/active_record_relations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ 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 { 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
end
Expand Down Expand Up @@ -758,6 +761,9 @@ 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 { 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
end
Expand Down Expand Up @@ -1372,6 +1378,9 @@ 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 { 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
end
Expand Down Expand Up @@ -1474,6 +1483,9 @@ 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 { 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
end
Expand Down

0 comments on commit f9a128f

Please sign in to comment.