lib/rack/reducer.rb in rack-reducer-0.1.0 vs lib/rack/reducer.rb in rack-reducer-0.1.1

- old
+ new

@@ -1,38 +1,38 @@ # frozen_string_literal: true require 'rack/request' require_relative 'reducer/reduction' +require_relative 'reducer/middleware' module Rack - # use request params to apply filters to a dataset + # Use request params to apply filters to a dataset module Reducer - # call Rack::Reducer as a function, instead of mounting it as middleware + # Call Rack::Reducer as a function def self.call(params, dataset:, filters:) Reduction.new( - nil, # first arg to Reduction is `app`, which is for middleware only params: params, filters: filters, - dataset: dataset, + dataset: dataset ).reduce end + # Mount Rack::Reducer as middleware def self.new(app, options = {}) - Reduction.new(app, options) + Middleware.new(app, options) end - # extend Rack::Reducer to get `reduce` and `reduces` as class-methods + # Extend Rack::Reducer to get `reduce` and `reduces` as class-methods # # class Artist < SomeORM::Model # extend Rack::Reducer # reduces self.all, filters: [ # lambda { |name:| where(name: name) }, # lambda { |genre:| where(genre: genre) }, # ] # end def reduce(params) Reduction.new( - nil, params: params, filters: @rack_reducer_filters, dataset: @rack_reducer_dataset ).reduce end