• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ruby-grape / grape / 25875362278 / 4
97%
master: 97%

Build:
Build:
LAST BUILD BRANCH: robust_mounted_app_comparison
DEFAULT BRANCH: master
Ran 14 May 2026 05:38PM UTC
Files 161
Run time 11s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

14 May 2026 05:36PM UTC coverage: 95.723%. First build
25875362278.4

push

github

ericproulx
[DRAFT] Generalize middleware options to per-class Data value objects

Demonstration / discussion PR. Right now every middleware that wants
typed accessors over its options has to hand-write the same boilerplate:

  DEFAULT_OPTIONS = { foo: nil, bar: nil, ... }.freeze
  attr_reader :foo, :bar, ...
  def initialize(app, **options)
    super
    @foo = @options[:foo]
    @bar = @options[:bar]
    ...
  end

Since `@options` was already frozen by design (Middleware::Base#initialize
post-PR #2696), the natural next step is to replace the Hash with a
per-subclass `Options = Data.define(...)` and let `Forwardable` cover the
accessor wiring.

Mechanism added in this draft:

- `Grape::Middleware::OptionsCompat` — a small mixin Options classes
  include to keep the legacy `options[:key]` idiom working (notably for
  `Middleware::Base#content_types` and `#content_type`). Unknown keys
  return `nil` to match Hash semantics.
- `Middleware::Base#initialize` detects `self.class::Options` and routes
  kwargs through `Options.new(**options)`. Subclasses that still rely on
  `DEFAULT_OPTIONS` Hash + deep_merge keep working unchanged.

Demonstrated on `Middleware::Formatter`:

- Replaces 5-line DEFAULT_OPTIONS Hash + 4-line `attr_reader` list +
  6-line initialize body with:

    Options = Data.define(:content_types, :default_format, :format,
                          :formatters, :parsers) do
      include Grape::Middleware::OptionsCompat
      def initialize(content_types: nil, default_format: :txt, format: nil,
                     formatters: nil, parsers: nil)
        super
      end
    end

    def_delegators :options, :default_format, :format, :formatters, :parsers

- Defaults move from the freeze'd Hash to `#initialize` signature.
- Immutability is implicit (Data instances).

Behaviour change: passing an unknown kwarg to a middleware whose `Options`
class doesn't declare it now raises `ArgumentError` instead of being
silently swallowed by `**options`. One form... (continued)

1062 of 1171 branches covered (90.69%)

Branch coverage included in aggregate %.

3459 of 3552 relevant lines covered (97.38%)

1002.38 hits per line

Source Files on job run-3.3-gemfiles/rails_8_0.gemfile - 25875362278.4
  • Tree
  • List 161
  • Changed 0
  • Source Changed 0
  • Coverage Changed 0
Coverage ∆ File Lines Relevant Covered Missed Hits/Line Branch Hits Branch Misses
  • Back to Build 25875362278
  • ba9b2e78 on github
  • Next Job for on draft/middleware-options-data (#25878904332.10)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc