You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The core concept of this library is a _plane_ (or _hand plane_, or "рубанок" in Russian). Plane is responsible for mapping parameters to transformations.
73
+
The core concept of this library is a processor (previously called _plane_or _hand plane_, or "рубанок" in Russian). Processor is responsible for mapping parameters to transformations.
74
74
75
75
From the example above:
76
76
77
77
```ruby
78
-
classCourseSessionsPlane < Rubanok::Plane
78
+
classCourseSessionsProcessor < Rubanok::Processor
79
79
# You can map keys
80
80
map :qdo |q:|
81
81
# `raw` is an accessor for input data
@@ -84,7 +84,7 @@ class CourseSessionsPlane < Rubanok::Plane
@@ -133,7 +133,7 @@ class CourseSessionsPlane < Rubanok::Plane
133
133
end
134
134
end
135
135
136
-
# strict matching; if Plane will not match parameter, it will raise Rubanok::UnexpectedInputError
136
+
# strict matching; if Processor will not match parameter, it will raise Rubanok::UnexpectedInputError
137
137
# You can handle it in controller, for example, with sending 422 Unprocessable Entity to client
138
138
match :filter, fail_when_no_matches:truedo
139
139
having "active"do
@@ -148,7 +148,7 @@ end
148
148
```
149
149
150
150
By default, Rubanok will not fail if no matches found in `match` rule. You can change it by setting: `Rubanok.fail_when_no_matches = true`.
151
-
If in example above you will call `CourseSessionsPlane.call(CourseSession, filter: 'acitve')`, you will get `Rubanok::UnexpectedInputError: Unexpected input: {:filter=>'acitve'}`.
151
+
If in example above you will call `CourseSessionsProcessor.call(CourseSession, filter: 'acitve')`, you will get `Rubanok::UnexpectedInputError: Unexpected input: {:filter=>'acitve'}`.
152
152
153
153
**NOTE:** Rubanok only matches exact values; more complex matching could be added in the future.
154
154
@@ -180,7 +180,7 @@ One of the benefits of having modification logic contained in its own class is t
180
180
181
181
```ruby
182
182
# For example, with RSpec
183
-
RSpec.describe CourseSessionsPlanedo
183
+
RSpec.describe CourseSessionsProcessordo
184
184
let(:input ) { CourseSession.all }
185
185
let(:params) { {} }
186
186
@@ -201,49 +201,36 @@ RSpec.describe CourseSessionController do
**NOTE**: input matching only checks for the class equality.
211
211
212
-
To use `have_planished` matcher you must add the following line to your `spec_helper.rb` / `rails_helper.rb` (it's added automatically if RSpec defined and `RAILS_ENV`/`RACK_ENV` is equal to `"test"`):
212
+
To use `have_rubanok_processed` matcher you must add the following line to your `spec_helper.rb` / `rails_helper.rb` (it's added automatically if RSpec defined and `RAILS_ENV`/`RACK_ENV` is equal to `"test"`):
213
213
214
214
```ruby
215
215
require"rubanok/rspec"
216
216
```
217
217
218
218
### Rails vs. non-Rails
219
219
220
-
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`).
220
+
Rubanok does not require Rails, but it has some useful Rails extensions such as `rubanok_process` helper for controllers (included automatically into `ActionController::Base` and `ActionController::API`).
221
221
222
222
If you use `ActionController::Metal` you must include the `Rubanok::Controller` module yourself.
I put mine under `app/planes` (as `<resources>_plane.rb`) in my Rails app.
233
-
234
-
-**I don't like the naming ("planes" ✈️?), can I still use the library?**
224
+
### Processor class inference in Rails controllers
235
225
236
-
First, feel free to [propose your variant](https://github.com/palkan/rubanok/issues). We would be glad to discuss it.
226
+
By default, `rubanok_process` uses the following algorithm to define a processor class: `"#{controller_path.classify.pluralize}Processor".safe_constantize`.
237
227
238
-
Secondly, you can easily avoid it by adding a few lines to your `ApplicationController`:
228
+
You can change this by overriding the `#implicit_rubanok_class` method:
**NOTE:** the `planish` method is still available and it uses `#{controller_path.classify.pluralize}Plane".safe_constantize` under the hood (via the `#implicit_plane_class` method).
252
+
253
+
## Questions & Answers
254
+
255
+
-**Where to put my processor/plane classes?**
256
+
257
+
I put mine under `app/planes` (as `<resources>_plane.rb`) in my Rails app.
258
+
259
+
-**I don't like the naming ("planes" ✈️?), can I still use the library?**
260
+
261
+
Good news—the default naming has been changed. "Planes" are still available if you prefer them (just like me 😉).
262
+
264
263
## Contributing
265
264
266
265
Bug reports and pull requests are welcome on GitHub at https://github.com/palkan/rubanok.
0 commit comments