rack-reducer 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +170 -104
- data/lib/rack/reducer/middleware.rb +24 -0
- data/lib/rack/reducer/reduction.rb +5 -17
- data/lib/rack/reducer.rb +7 -7
- data/spec/_hanami_example/apps/web/application.rb +326 -0
- data/spec/_hanami_example/apps/web/config/routes.rb +4 -0
- data/spec/_hanami_example/apps/web/controllers/artists/index.rb +12 -0
- data/spec/_hanami_example/apps/web/views/application_layout.rb +7 -0
- data/spec/_hanami_example/config/boot.rb +2 -0
- data/spec/_hanami_example/config/environment.rb +29 -0
- data/spec/_hanami_example/lib/hanami_example/entities/artist.rb +2 -0
- data/spec/_hanami_example/lib/hanami_example/repositories/artist_repository.rb +9 -0
- data/spec/_hanami_example/lib/hanami_example.rb +5 -0
- data/spec/{rails_example → _rails_example}/app/channels/application_cable/channel.rb +0 -0
- data/spec/{rails_example → _rails_example}/app/channels/application_cable/connection.rb +0 -0
- data/spec/{rails_example → _rails_example}/app/controllers/application_controller.rb +0 -0
- data/spec/_rails_example/app/controllers/artists_controller.rb +8 -0
- data/spec/{rails_example → _rails_example}/app/jobs/application_job.rb +0 -0
- data/spec/{rails_example → _rails_example}/app/mailers/application_mailer.rb +0 -0
- data/spec/{rails_example → _rails_example}/app/models/application_record.rb +0 -0
- data/spec/_rails_example/app/models/rails_example/artist.rb +20 -0
- data/spec/{rails_example → _rails_example}/config/application.rb +0 -0
- data/spec/{rails_example → _rails_example}/config/boot.rb +0 -0
- data/spec/{rails_example → _rails_example}/config/environment.rb +0 -0
- data/spec/{rails_example → _rails_example}/config/environments/development.rb +0 -0
- data/spec/{rails_example → _rails_example}/config/environments/production.rb +0 -0
- data/spec/{rails_example → _rails_example}/config/environments/test.rb +0 -0
- data/spec/{rails_example → _rails_example}/config/initializers/application_controller_renderer.rb +0 -0
- data/spec/{rails_example → _rails_example}/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/{rails_example → _rails_example}/config/initializers/cors.rb +0 -0
- data/spec/{rails_example → _rails_example}/config/initializers/filter_parameter_logging.rb +0 -0
- data/spec/{rails_example → _rails_example}/config/initializers/inflections.rb +0 -0
- data/spec/{rails_example → _rails_example}/config/initializers/mime_types.rb +0 -0
- data/spec/{rails_example → _rails_example}/config/initializers/wrap_parameters.rb +0 -0
- data/spec/{rails_example → _rails_example}/config/puma.rb +0 -0
- data/spec/{rails_example → _rails_example}/config/routes.rb +0 -0
- data/spec/{rails_example → _rails_example}/db/seeds.rb +0 -0
- data/spec/behavior.rb +2 -2
- data/spec/hanami_spec.rb +6 -0
- data/spec/middleware_spec.rb +16 -8
- data/spec/rails_spec.rb +1 -2
- data/spec/roda_spec.rb +15 -0
- data/spec/sinatra_functional_spec.rb +3 -9
- data/spec/sinatra_mixin_spec.rb +0 -2
- data/spec/spec_helper.rb +12 -1
- metadata +121 -62
- data/spec/fixtures.rb +0 -19
- data/spec/rails_example/app/controllers/artists_controller.rb +0 -53
- data/spec/rails_example/app/models/artist.rb +0 -18
- data/spec/rails_example/config/initializers/schema.rb +0 -13
- data/spec/rails_example/test/test_helper.rb +0 -10
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-reducer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hanami
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: hanami-model
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: rack-test
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +122,20 @@ dependencies:
|
|
94
122
|
- - "~>"
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '12'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: roda
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3'
|
97
139
|
- !ruby/object:Gem::Dependency
|
98
140
|
name: rspec
|
99
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +156,14 @@ dependencies:
|
|
114
156
|
requirements:
|
115
157
|
- - "~>"
|
116
158
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
159
|
+
version: '4'
|
118
160
|
type: :development
|
119
161
|
prerelease: false
|
120
162
|
version_requirements: !ruby/object:Gem::Requirement
|
121
163
|
requirements:
|
122
164
|
- - "~>"
|
123
165
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
166
|
+
version: '4'
|
125
167
|
- !ruby/object:Gem::Dependency
|
126
168
|
name: sinatra
|
127
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,8 +212,8 @@ dependencies:
|
|
170
212
|
- - "<"
|
171
213
|
- !ruby/object:Gem::Version
|
172
214
|
version: '3'
|
173
|
-
description:
|
174
|
-
|
215
|
+
description: Dynamically filter, sort, and paginate data via URL params, in any Rack
|
216
|
+
app.
|
175
217
|
email:
|
176
218
|
- chris.frank@thefutureproject.org
|
177
219
|
executables: []
|
@@ -180,40 +222,49 @@ extra_rdoc_files: []
|
|
180
222
|
files:
|
181
223
|
- README.md
|
182
224
|
- lib/rack/reducer.rb
|
225
|
+
- lib/rack/reducer/middleware.rb
|
183
226
|
- lib/rack/reducer/parser.rb
|
184
227
|
- lib/rack/reducer/reduction.rb
|
185
228
|
- lib/rack/reducer/refinements.rb
|
229
|
+
- spec/_hanami_example/apps/web/application.rb
|
230
|
+
- spec/_hanami_example/apps/web/config/routes.rb
|
231
|
+
- spec/_hanami_example/apps/web/controllers/artists/index.rb
|
232
|
+
- spec/_hanami_example/apps/web/views/application_layout.rb
|
233
|
+
- spec/_hanami_example/config/boot.rb
|
234
|
+
- spec/_hanami_example/config/environment.rb
|
235
|
+
- spec/_hanami_example/lib/hanami_example.rb
|
236
|
+
- spec/_hanami_example/lib/hanami_example/entities/artist.rb
|
237
|
+
- spec/_hanami_example/lib/hanami_example/repositories/artist_repository.rb
|
238
|
+
- spec/_rails_example/app/channels/application_cable/channel.rb
|
239
|
+
- spec/_rails_example/app/channels/application_cable/connection.rb
|
240
|
+
- spec/_rails_example/app/controllers/application_controller.rb
|
241
|
+
- spec/_rails_example/app/controllers/artists_controller.rb
|
242
|
+
- spec/_rails_example/app/jobs/application_job.rb
|
243
|
+
- spec/_rails_example/app/mailers/application_mailer.rb
|
244
|
+
- spec/_rails_example/app/models/application_record.rb
|
245
|
+
- spec/_rails_example/app/models/rails_example/artist.rb
|
246
|
+
- spec/_rails_example/config/application.rb
|
247
|
+
- spec/_rails_example/config/boot.rb
|
248
|
+
- spec/_rails_example/config/environment.rb
|
249
|
+
- spec/_rails_example/config/environments/development.rb
|
250
|
+
- spec/_rails_example/config/environments/production.rb
|
251
|
+
- spec/_rails_example/config/environments/test.rb
|
252
|
+
- spec/_rails_example/config/initializers/application_controller_renderer.rb
|
253
|
+
- spec/_rails_example/config/initializers/backtrace_silencers.rb
|
254
|
+
- spec/_rails_example/config/initializers/cors.rb
|
255
|
+
- spec/_rails_example/config/initializers/filter_parameter_logging.rb
|
256
|
+
- spec/_rails_example/config/initializers/inflections.rb
|
257
|
+
- spec/_rails_example/config/initializers/mime_types.rb
|
258
|
+
- spec/_rails_example/config/initializers/wrap_parameters.rb
|
259
|
+
- spec/_rails_example/config/puma.rb
|
260
|
+
- spec/_rails_example/config/routes.rb
|
261
|
+
- spec/_rails_example/db/seeds.rb
|
186
262
|
- spec/behavior.rb
|
187
263
|
- spec/benchmarks.rb
|
188
|
-
- spec/
|
264
|
+
- spec/hanami_spec.rb
|
189
265
|
- spec/middleware_spec.rb
|
190
|
-
- spec/rails_example/app/channels/application_cable/channel.rb
|
191
|
-
- spec/rails_example/app/channels/application_cable/connection.rb
|
192
|
-
- spec/rails_example/app/controllers/application_controller.rb
|
193
|
-
- spec/rails_example/app/controllers/artists_controller.rb
|
194
|
-
- spec/rails_example/app/jobs/application_job.rb
|
195
|
-
- spec/rails_example/app/mailers/application_mailer.rb
|
196
|
-
- spec/rails_example/app/models/application_record.rb
|
197
|
-
- spec/rails_example/app/models/artist.rb
|
198
|
-
- spec/rails_example/config/application.rb
|
199
|
-
- spec/rails_example/config/boot.rb
|
200
|
-
- spec/rails_example/config/environment.rb
|
201
|
-
- spec/rails_example/config/environments/development.rb
|
202
|
-
- spec/rails_example/config/environments/production.rb
|
203
|
-
- spec/rails_example/config/environments/test.rb
|
204
|
-
- spec/rails_example/config/initializers/application_controller_renderer.rb
|
205
|
-
- spec/rails_example/config/initializers/backtrace_silencers.rb
|
206
|
-
- spec/rails_example/config/initializers/cors.rb
|
207
|
-
- spec/rails_example/config/initializers/filter_parameter_logging.rb
|
208
|
-
- spec/rails_example/config/initializers/inflections.rb
|
209
|
-
- spec/rails_example/config/initializers/mime_types.rb
|
210
|
-
- spec/rails_example/config/initializers/schema.rb
|
211
|
-
- spec/rails_example/config/initializers/wrap_parameters.rb
|
212
|
-
- spec/rails_example/config/puma.rb
|
213
|
-
- spec/rails_example/config/routes.rb
|
214
|
-
- spec/rails_example/db/seeds.rb
|
215
|
-
- spec/rails_example/test/test_helper.rb
|
216
266
|
- spec/rails_spec.rb
|
267
|
+
- spec/roda_spec.rb
|
217
268
|
- spec/sinatra_functional_spec.rb
|
218
269
|
- spec/sinatra_mixin_spec.rb
|
219
270
|
- spec/spec_helper.rb
|
@@ -229,7 +280,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
229
280
|
requirements:
|
230
281
|
- - ">="
|
231
282
|
- !ruby/object:Gem::Version
|
232
|
-
version: '2.
|
283
|
+
version: '2.2'
|
233
284
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
234
285
|
requirements:
|
235
286
|
- - ">="
|
@@ -240,39 +291,47 @@ rubyforge_project:
|
|
240
291
|
rubygems_version: 2.7.3
|
241
292
|
signing_key:
|
242
293
|
specification_version: 4
|
243
|
-
summary:
|
294
|
+
summary: Dynamically filter data via URL params, in any Rack app.
|
244
295
|
test_files:
|
245
296
|
- spec/spec_helper.rb
|
246
297
|
- spec/benchmarks.rb
|
247
|
-
- spec/fixtures.rb
|
248
298
|
- spec/sinatra_mixin_spec.rb
|
249
|
-
- spec/
|
250
|
-
- spec/
|
251
|
-
- spec/
|
252
|
-
- spec/
|
253
|
-
- spec/
|
254
|
-
- spec/
|
255
|
-
- spec/
|
256
|
-
- spec/
|
257
|
-
- spec/
|
258
|
-
- spec/
|
259
|
-
- spec/
|
260
|
-
- spec/
|
261
|
-
- spec/
|
262
|
-
- spec/
|
263
|
-
- spec/
|
264
|
-
- spec/
|
265
|
-
- spec/
|
266
|
-
- spec/
|
267
|
-
- spec/
|
268
|
-
- spec/
|
269
|
-
- spec/
|
270
|
-
- spec/
|
271
|
-
- spec/
|
272
|
-
- spec/
|
273
|
-
- spec/
|
274
|
-
- spec/
|
299
|
+
- spec/_rails_example/app/mailers/application_mailer.rb
|
300
|
+
- spec/_rails_example/app/models/rails_example/artist.rb
|
301
|
+
- spec/_rails_example/app/models/application_record.rb
|
302
|
+
- spec/_rails_example/app/jobs/application_job.rb
|
303
|
+
- spec/_rails_example/app/controllers/application_controller.rb
|
304
|
+
- spec/_rails_example/app/controllers/artists_controller.rb
|
305
|
+
- spec/_rails_example/app/channels/application_cable/connection.rb
|
306
|
+
- spec/_rails_example/app/channels/application_cable/channel.rb
|
307
|
+
- spec/_rails_example/config/routes.rb
|
308
|
+
- spec/_rails_example/config/environments/production.rb
|
309
|
+
- spec/_rails_example/config/environments/development.rb
|
310
|
+
- spec/_rails_example/config/environments/test.rb
|
311
|
+
- spec/_rails_example/config/environment.rb
|
312
|
+
- spec/_rails_example/config/application.rb
|
313
|
+
- spec/_rails_example/config/puma.rb
|
314
|
+
- spec/_rails_example/config/boot.rb
|
315
|
+
- spec/_rails_example/config/initializers/application_controller_renderer.rb
|
316
|
+
- spec/_rails_example/config/initializers/backtrace_silencers.rb
|
317
|
+
- spec/_rails_example/config/initializers/mime_types.rb
|
318
|
+
- spec/_rails_example/config/initializers/filter_parameter_logging.rb
|
319
|
+
- spec/_rails_example/config/initializers/wrap_parameters.rb
|
320
|
+
- spec/_rails_example/config/initializers/inflections.rb
|
321
|
+
- spec/_rails_example/config/initializers/cors.rb
|
322
|
+
- spec/_rails_example/db/seeds.rb
|
323
|
+
- spec/_hanami_example/config/environment.rb
|
324
|
+
- spec/_hanami_example/config/boot.rb
|
325
|
+
- spec/_hanami_example/lib/hanami_example/repositories/artist_repository.rb
|
326
|
+
- spec/_hanami_example/lib/hanami_example/entities/artist.rb
|
327
|
+
- spec/_hanami_example/lib/hanami_example.rb
|
328
|
+
- spec/_hanami_example/apps/web/config/routes.rb
|
329
|
+
- spec/_hanami_example/apps/web/application.rb
|
330
|
+
- spec/_hanami_example/apps/web/controllers/artists/index.rb
|
331
|
+
- spec/_hanami_example/apps/web/views/application_layout.rb
|
275
332
|
- spec/sinatra_functional_spec.rb
|
276
333
|
- spec/middleware_spec.rb
|
334
|
+
- spec/roda_spec.rb
|
335
|
+
- spec/hanami_spec.rb
|
277
336
|
- spec/behavior.rb
|
278
337
|
- spec/rails_spec.rb
|
data/spec/fixtures.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# hash fixture data
|
2
|
-
ARTISTS = [
|
3
|
-
{ name: 'Blake Mills', genre: 'alternative' },
|
4
|
-
{ name: 'Björk', genre: 'electronic' },
|
5
|
-
{ name: 'James Blake', genre: 'electronic' },
|
6
|
-
{ name: 'Janelle Monae', genre: 'alt-soul' },
|
7
|
-
{ name: 'SZA', genre: 'alt-soul' },
|
8
|
-
].freeze
|
9
|
-
|
10
|
-
require 'sequel'
|
11
|
-
DB = Sequel.sqlite
|
12
|
-
|
13
|
-
DB.create_table :artists do
|
14
|
-
String :name
|
15
|
-
String :genre
|
16
|
-
end
|
17
|
-
|
18
|
-
# put the hash fixtures into an in-memory SQLite database
|
19
|
-
ARTISTS.each { |artist| DB[:artists].insert(artist) }
|
@@ -1,53 +0,0 @@
|
|
1
|
-
class ArtistsController < ApplicationController
|
2
|
-
before_action :set_artist, only: [:show, :update, :destroy]
|
3
|
-
|
4
|
-
# GET /artists
|
5
|
-
def index
|
6
|
-
@artists = Artist.reduce(params)
|
7
|
-
|
8
|
-
render json: @artists
|
9
|
-
end
|
10
|
-
|
11
|
-
# GET /artists/1
|
12
|
-
def show
|
13
|
-
render json: @artist
|
14
|
-
end
|
15
|
-
|
16
|
-
# POST /artists
|
17
|
-
def create
|
18
|
-
@artist = Artist.new(artist_params)
|
19
|
-
|
20
|
-
if @artist.save
|
21
|
-
render json: @artist, status: :created, location: @artist
|
22
|
-
else
|
23
|
-
render json: @artist.errors, status: :unprocessable_entity
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
# PATCH/PUT /artists/1
|
28
|
-
def update
|
29
|
-
if @artist.update(artist_params)
|
30
|
-
render json: @artist
|
31
|
-
else
|
32
|
-
render json: @artist.errors, status: :unprocessable_entity
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# DELETE /artists/1
|
37
|
-
def destroy
|
38
|
-
@artist.destroy
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
# Use callbacks to share common setup or constraints between actions.
|
43
|
-
def set_artist
|
44
|
-
@artist = Artist.find(params[:id])
|
45
|
-
end
|
46
|
-
|
47
|
-
# Only allow a trusted parameter "white list" through.
|
48
|
-
def artist_params
|
49
|
-
params.require(:artist).permit(:name, :genre, :last_release)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
#filters: [:search_genre, :search_name].map { |m| method(m).to_proc },
|
53
|
-
|
@@ -1,18 +0,0 @@
|
|
1
|
-
class Artist < ApplicationRecord
|
2
|
-
scope :by_name, lambda { |name|
|
3
|
-
where('lower(name) like ?', "%#{name.downcase}%")
|
4
|
-
}
|
5
|
-
def self.search_genre(genre)
|
6
|
-
where('lower(genre) like ?', "%#{genre.downcase}%")
|
7
|
-
end
|
8
|
-
|
9
|
-
extend Rack::Reducer
|
10
|
-
reduces all, filters: [
|
11
|
-
# filters can call class methods...
|
12
|
-
->(genre:) { search_genre(genre) },
|
13
|
-
# or scopes...
|
14
|
-
->(name:) { by_name(name) },
|
15
|
-
# or inline ActiveRecord queries
|
16
|
-
->(order:) { order(order.to_sym) }
|
17
|
-
]
|
18
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
ActiveRecord::Schema.define do
|
2
|
-
|
3
|
-
create_table "artists" do |t|
|
4
|
-
t.string "name"
|
5
|
-
t.string "genre"
|
6
|
-
t.date "last_release"
|
7
|
-
t.datetime "created_at", null: false
|
8
|
-
t.datetime "updated_at", null: false
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
ARTISTS.each { |artist| Artist.create(artist) }
|
@@ -1,10 +0,0 @@
|
|
1
|
-
ENV['RAILS_ENV'] ||= 'test'
|
2
|
-
require File.expand_path('../../config/environment', __FILE__)
|
3
|
-
require 'rails/test_help'
|
4
|
-
|
5
|
-
class ActiveSupport::TestCase
|
6
|
-
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
7
|
-
fixtures :all
|
8
|
-
|
9
|
-
# Add more helper methods to be used by all tests here...
|
10
|
-
end
|