Skip to content
This repository has been archived by the owner on Mar 18, 2019. It is now read-only.

Match with a proc #8

Open
lasseebert opened this issue Apr 23, 2016 · 0 comments
Open

Match with a proc #8

lasseebert opened this issue Apr 23, 2016 · 0 comments

Comments

@lasseebert
Copy link
Owner

It might be a good feature to be able to match with a proc.

Example matching a Rack response:

response = app.call(env)
kase response do
  on(proc { |status, _headers, _bodies| (200...300).include?(status) } ) do |_status, _headers, bodies|
    ok_response(bodies.first)
  end
  on(400) { |_headers, bodies| parse_error(bodies.first) }
  on(500) { |headers, bodies| log_error(headers, bodies) }
end

Or we could allow matching with === with match instead of on. The above would then be rewritten to:

response = app.call(env)
kase response do
  match(200...300) { |_status, _headers, bodies| ok_response(bodies.first) }
  on(400) { |_headers, bodies| parse_error(bodies.first) }
  on(500) { |headers, bodies| log_error(headers, bodies) }
end
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant