Skip to content

fix: return milliseconds from Ruflet.duration - #36

Merged
AdamMusa merged 1 commit into
mainfrom
fix/ruflet-duration-helper
Nov 2, 2026
Merged

AdamMusa merged 1 commit into
mainfrom
fix/ruflet-duration-helper

Conversation

@AdamMusa

Copy link
Copy Markdown
Owner

Summary

Ruflet.duration(seconds: 2) returned a generic Ruflet::Control of type "Duration" ({"_c" => "Duration", "seconds" => 2}) instead of 2000. Ruflet::DSL.duration, Ruflet::UI.duration and the top-level duration(...) were already correct.

Cause: the Ruflet module forwards helpers to control_delegate, which is a WidgetBuilder. WidgetBuilder had no duration method, so the call went to method_missing and built a control. Passing that into a property put a nested control on the wire. For example, dismissible(movement_duration: Ruflet.duration(milliseconds: 750)) sent {"_c":"Duration",...} instead of 750.

Fix

WidgetBuilder#duration(**parts) now delegates to DSL.duration, the same way DSL::App#duration already does. This is a one-method change, with no new syntax and nothing mruby-specific.

Usage

Ruflet.duration(seconds: 2)                           # => 2000
Ruflet.duration(minutes: 1, seconds: 30, milliseconds: 500) # => 90500
Ruflet.dismissible(Ruflet.text("Swipe"), movement_duration: Ruflet.duration(milliseconds: 750))

Tests

New packages/ruflet_core/test/duration_helper_test.rb (4 tests). Three failed before the fix.

  • Ruflet.duration returns milliseconds, and an empty call returns 0.
  • Ruflet, Ruflet::UI and WidgetBuilder#duration all agree with Ruflet::DSL.duration.
  • A duration call inside a builder block returns an integer and does not add a child control. This passed before the fix too; it guards against a regression.
  • Ruflet.duration used as a control property serializes as an integer.

verify_pr.sh (ruflet_core): PASS, 146/146 files, 622 runs. ruflet_server: 11/11.

Note: packages/ruflet run_command_test.rb#test_handle_reload_command_big_r_requests_full_restart is flaky under machine load. It fails 3 of 6 runs on unmodified origin/main, and it is unrelated to this change, which only touches ruflet_core.

Engine: no change needed. Durations are already plain integers on the wire.

@AdamMusa
AdamMusa merged commit 4dc6e04 into main Nov 2, 2026
12 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.

1 participant