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

Update active record relations DSL count to accept a block argument #2154

Open
wants to merge 1 commit into
base: main
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
1 change: 1 addition & 0 deletions lib/tapioca/dsl/compilers/active_record_relations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def create_group_chain_methods(klass)
"count",
parameters: [
create_opt_param("column_name", type: "T.untyped", default: "nil"),
create_block_param("block", type: "T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why groupchain count is different than regular count definition. I think it'll be good to take a closer look and be consistent if appropriate. Regular one uses overloaded sigs instead

sig.add_param("column_name", "T.nilable(T.any(String, Symbol))")
.

],
return_type: "T::Hash[T.untyped, Integer]",
)
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 @@ -648,8 +648,8 @@ def average(column_name); end
sig { params(operation: Symbol, column_name: T.any(String, Symbol)).returns(T::Hash[T.untyped, T.any(Integer, Float, BigDecimal)]) }
def calculate(operation, column_name); end

sig { params(column_name: T.untyped).returns(T::Hash[T.untyped, Integer]) }
def count(column_name = nil); end
sig { params(column_name: T.untyped, block: T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))).returns(T::Hash[T.untyped, Integer]) }
def count(column_name = nil, &block); end

sig { params(args: T.untyped, blk: T.untyped).returns(T.self_type) }
def having(*args, &blk); end
Expand Down Expand Up @@ -753,8 +753,8 @@ def average(column_name); end
sig { params(operation: Symbol, column_name: T.any(String, Symbol)).returns(T::Hash[T.untyped, T.any(Integer, Float, BigDecimal)]) }
def calculate(operation, column_name); end

sig { params(column_name: T.untyped).returns(T::Hash[T.untyped, Integer]) }
def count(column_name = nil); end
sig { params(column_name: T.untyped, block: T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))).returns(T::Hash[T.untyped, Integer]) }
def count(column_name = nil, &block); end

sig { params(args: T.untyped, blk: T.untyped).returns(T.self_type) }
def having(*args, &blk); end
Expand Down Expand Up @@ -1374,8 +1374,8 @@ def average(column_name); end
sig { params(operation: Symbol, column_name: T.any(String, Symbol)).returns(T::Hash[T.untyped, T.any(Integer, Float, BigDecimal)]) }
def calculate(operation, column_name); end

sig { params(column_name: T.untyped).returns(T::Hash[T.untyped, Integer]) }
def count(column_name = nil); end
sig { params(column_name: T.untyped, block: T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))).returns(T::Hash[T.untyped, Integer]) }
def count(column_name = nil, &block); end

sig { params(args: T.untyped, blk: T.untyped).returns(T.self_type) }
def having(*args, &blk); end
Expand Down Expand Up @@ -1479,8 +1479,8 @@ def average(column_name); end
sig { params(operation: Symbol, column_name: T.any(String, Symbol)).returns(T::Hash[T.untyped, T.any(Integer, Float, BigDecimal)]) }
def calculate(operation, column_name); end

sig { params(column_name: T.untyped).returns(T::Hash[T.untyped, Integer]) }
def count(column_name = nil); end
sig { params(column_name: T.untyped, block: T.nilable(T.proc.params(record: T.untyped).returns(T.untyped))).returns(T::Hash[T.untyped, Integer]) }
def count(column_name = nil, &block); end

sig { params(args: T.untyped, blk: T.untyped).returns(T.self_type) }
def having(*args, &blk); end
Expand Down
Loading