rubanok 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b5cdbefb98c951e26be6bfcd8029250f8b314c9b7bb86e5d5d778bc340b4d40
4
- data.tar.gz: abd725823622bdf1ff062cc1496dfd121522e6b866ec01ce2bc9ea421a56785e
3
+ metadata.gz: 76b1edc5c67f7a783dc3db022fee6aba015af2745a877d0b05089ce2c2ca2df7
4
+ data.tar.gz: d3e055c5453c793e17d0c6efea3b0bd6bcb3c8b16ada1461544b28431058a3a1
5
5
  SHA512:
6
- metadata.gz: aeec1ebbf07db8ec31046cf1442ffac9e6cae698e979768e8560d189f7ab23bfc13d9ef2979dbd45fd00490a5101e3f3b3900d4ff2425b2112880915e8446ba6
7
- data.tar.gz: e66af487b2f7b82626d790bc0746559102de30ec0220e5d12de1ce0f29c79c98ed0bad6744ab90df5c5a931b421d90d1b4b4d082e70d15f714efb49fb56b2418
6
+ metadata.gz: ab19e7909a899d1831f246164888e76c29c1dfd6f9d3864a801b69fd3caba8cc754402a3e3e11ae6a0185bb87cec76711dadcfd8762e32eb4923cf24d3e16bae
7
+ data.tar.gz: 91c17c4695b0ccc7ff6ab0b75cace311c61b9ca3edf29a43bbd2c747dbb5995bc6f2af45ca6966117dc45304c8cf1ca2f58401bd7329d966a180d8c2942b24dc
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ cache: bundler
3
4
  rvm:
4
5
  - 2.6.0
5
6
 
@@ -15,6 +16,8 @@ matrix:
15
16
  include:
16
17
  - rvm: ruby-head
17
18
  gemfile: gemfiles/railsmaster.gemfile
19
+ - rvm: 2.6.1
20
+ gemfile: gemfiles/rails6.gemfile
18
21
  - rvm: 2.6.0
19
22
  gemfile: gemfiles/rails52.gemfile
20
23
  - rvm: 2.5.1
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.1.3 (2019-03-05)
6
+
7
+ - Fix using `activate_always: true` with `default` matching clause. ([@palkan][])
8
+
5
9
  ## 0.1.1 (2019-01-16)
6
10
 
7
11
  - Fix RSpec matcher to call original implementation instead of returning `nil`. ([@palkan][])
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  Rubanok provides a DSL to build parameters-based data transformers.
6
6
 
7
+ 📖 Read the introduction post: ["Carve your controllers like Papa Carlo"](https://dev.to/evilmartians/carve-your-controllers-like-papa-carlo-32m6)
8
+
7
9
  The typical usage is to describe all the possible collection manipulation for REST `index` action, e.g. filtering, sorting, searching, pagination, etc..
8
10
 
9
11
  So, instead of:
@@ -58,11 +60,17 @@ Requirements:
58
60
 
59
61
  ## Installation
60
62
 
61
- **This gem hasn't been released (and even built) yet.**
63
+ Add to your `Gemfile`:
64
+
65
+ ```ruby
66
+ gem "rubanok"
67
+ ```
68
+
69
+ And run `bundle install`.
62
70
 
63
71
  ## Usage
64
72
 
65
- The core concept of this library is a _plane_ (or _hand plane_, or "рубанок" in Russian). Plane is responsible for mapping parameters to transformrations.
73
+ The core concept of this library is a _plane_ (or _hand plane_, or "рубанок" in Russian). Plane is responsible for mapping parameters to transformations.
66
74
 
67
75
  From the example above:
68
76
 
@@ -127,13 +135,13 @@ class CourseSessionsPlane < Rubanok::Plane
127
135
  end
128
136
  ```
129
137
 
130
- **NOTE:** matching only match the exact values; more complex matching could be added in the future.
138
+ **NOTE:** Rubanok only matches exact values; more complex matching could be added in the future.
131
139
 
132
140
  ### Rule activation
133
141
 
134
142
  Rubanok _activates_ a rule by checking whether the corresponding keys are present in the params object. All the fields must be present to apply the rule.
135
143
 
136
- Sometimes you might want to make some fields optional (or event all of them). You can use `activate_on` and `activate_always` options for that:
144
+ Some fields may be optional, or perhaps even all of them. You can use `activate_on` and `activate_always` options to mark something as an optional key instead of a required one:
137
145
 
138
146
  ```ruby
139
147
  # Always apply the rule; use default values for keyword args
@@ -147,13 +155,13 @@ match :sort_by, :sort, activate_on: :sort_by do
147
155
  end
148
156
  ```
149
157
 
150
- By default, Rubanok ignores empty param values (using `#empty?` under the hood) and do not activate the matching rules (i.e. `{ q: "" }` or `{ q: nil }` won't activate the `map :q` rule).
158
+ By default, Rubanok ignores empty param values (using `#empty?` under the hood) and will not run matching rules on those values. For example: `{ q: "" }` and `{ q: nil }` won't activate the `map :q` rule.
151
159
 
152
160
  You can change this behaviour by setting: `Rubanok.ignore_empty_values = false`.
153
161
 
154
162
  ### Testing
155
163
 
156
- One of the benefits of having all the modification logic in its own class is the ability to test it in isolation:
164
+ One of the benefits of having modification logic contained in its own class is the ability to test modifications in isolation:
157
165
 
158
166
  ```ruby
159
167
  # For example, with RSpec
@@ -194,10 +202,50 @@ require "rubanok/rspec"
194
202
 
195
203
  ### Rails vs. non-Rails
196
204
 
197
- Rubanok is a Rails-free library but has some useful Rails extensions, such as `planish` helper for controllers (included automatically into `ActionController::Base` and `ActionController::API`).
205
+ Rubanok does not require Rails, but it has some useful Rails extensions such as `planish` helper for controllers (included automatically into `ActionController::Base` and `ActionController::API`).
198
206
 
199
207
  If you use `ActionController::Metal` you must include the `Rubanok::Controller` module yourself.
200
208
 
209
+ ## Questions & Answers
210
+
211
+ - **🧐"Planish"? Is there a word?**
212
+
213
+ Yes, [it is](https://en.wiktionary.org/wiki/planish).
214
+
215
+ - **Where to put my _plane_ classes?**
216
+
217
+ I put mine under `app/planes` (as `<resources>_plane.rb`) in my Rails app.
218
+
219
+ - **I don't like the naming ("planes" ✈️?), can I still use the library?**
220
+
221
+ First, feel free to [propose your variant](https://github.com/palkan/rubanok/issues). We would be glad to discuss it.
222
+
223
+ Secondly, you can easily avoid it by adding a few lines to your `ApplicationController`:
224
+
225
+ ```ruby
226
+ class ApplicationController < ActionController::Smth
227
+ # add `planish` alias
228
+ alias transform_scope planish
229
+
230
+ # override the `implicit_plane_class` method
231
+ def implicit_plane_class
232
+ "#{controller_path.classify.pluralize}Scoper".safe_constantize
233
+ end
234
+ end
235
+ ```
236
+
237
+ Now you can use it like this:
238
+
239
+ ```ruby
240
+ class CourseSessionsController < ApplicationController
241
+ def index
242
+ @sessions = transform_scope(CourseSession.all, params)
243
+ # which equals to
244
+ @sessions = CourseSessionsScoper.call(CourseSession.all, params.to_unsafe_h)
245
+ end
246
+ end
247
+ ```
248
+
201
249
  ## Contributing
202
250
 
203
251
  Bug reports and pull requests are welcome on GitHub at https://github.com/palkan/rubanok.
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "actionpack", "6.0.0.beta1"
4
+ gem "actionview", "6.0.0.beta1"
5
+
6
+ gemspec path: ".."
@@ -69,7 +69,7 @@ module Rubanok
69
69
 
70
70
  rule.instance_eval(&block)
71
71
 
72
- define_method(rule.to_method_name) do |params|
72
+ define_method(rule.to_method_name) do |params = {}|
73
73
  clause = rule.matching_clause(params)
74
74
  next raw unless clause
75
75
 
@@ -8,6 +8,12 @@ module Rubanok # :nodoc:
8
8
 
9
9
  ActionController::Base.include Rubanok::Controller
10
10
  end
11
+
12
+ ActiveSupport.on_load(:action_controller_api) do
13
+ require "rubanok/rails/controller"
14
+
15
+ ActionController::API.include Rubanok::Controller
16
+ end
11
17
  end
12
18
  end
13
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubanok
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
data/rubanok.gemspec CHANGED
@@ -31,5 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "rspec", "~> 3.0"
32
32
  spec.add_development_dependency "rspec-rails"
33
33
  spec.add_development_dependency "rubocop-rspec"
34
- spec.add_development_dependency "standard"
34
+ spec.add_development_dependency "standard", "~> 0.0.36"
35
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubanok
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-17 00:00:00.000000000 Z
11
+ date: 2019-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -112,16 +112,16 @@ dependencies:
112
112
  name: standard
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: 0.0.36
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: 0.0.36
125
125
  description: Parameters-based transformation DSL
126
126
  email:
127
127
  - dementiev.vm@gmail.com
@@ -143,6 +143,7 @@ files:
143
143
  - bin/setup
144
144
  - gemfiles/rails42.gemfile
145
145
  - gemfiles/rails52.gemfile
146
+ - gemfiles/rails6.gemfile
146
147
  - gemfiles/railsmaster.gemfile
147
148
  - lib/rubanok.rb
148
149
  - lib/rubanok/dsl/mapping.rb
@@ -174,8 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
175
  - !ruby/object:Gem::Version
175
176
  version: '0'
176
177
  requirements: []
177
- rubyforge_project:
178
- rubygems_version: 2.7.6
178
+ rubygems_version: 3.0.2
179
179
  signing_key:
180
180
  specification_version: 4
181
181
  summary: Parameters-based transformation DSL