Skip to content

feat: callable defaults with instance context and dependency support#4

Merged
bharget merged 2 commits intomainfrom
ben/callable-defaults
Dec 18, 2025
Merged

feat: callable defaults with instance context and dependency support#4
bharget merged 2 commits intomainfrom
ben/callable-defaults

Conversation

@bharget
Copy link
Copy Markdown
Owner

@bharget bharget commented Oct 14, 2025

Summary

Enhances callable defaults so they can access other attributes and depend on each other.

Changes

  • Callable defaults (procs/lambdas) are evaluated with instance_exec, giving access to other attributes
  • Defaults are processed in definition order, allowing callable-to-callable dependencies
  • Explicit attributes are set first, so callables can reference them

Example

class GreetingService < ApplicationService
  argument :first_name, default: "John"
  argument :last_name, default: "Doe"
  argument :full_name, default: -> { "#{first_name} #{last_name}" }
  argument :greeting, default: -> { "Hello, #{full_name}!" }
end

GreetingService.call.greeting  #=> "Hello, John Doe!"
GreetingService.call(first_name: "Jane").greeting  #=> "Hello, Jane Doe!"

Tests

Added tests for:

  • Callables accessing other attributes
  • Callable-to-callable dependencies
  • Explicit attributes accessible to callables
  • Overriding callable defaults with explicit values

@bharget bharget self-assigned this Oct 14, 2025
@bharget bharget force-pushed the ben/callable-defaults branch from 13976e9 to 5dda286 Compare December 18, 2025 01:56
@bharget bharget changed the title feat: support callable default values feat: callable defaults with instance context and dependency support Dec 18, 2025
@bharget bharget merged commit 1c0c149 into main Dec 18, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants