decanter 4.0.3 → 4.0.4
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +38 -4
- data/lib/decanter/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 855c0c38fda4543f1542a7519ff4234544d696a910f39fe195cf99f50ad6a780
|
4
|
+
data.tar.gz: 28b8bb87ee97e7a0c371124cbb8a04319b35df6c2ee642f75290d822a2015186
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 523f731eb6580679bc32699b6ae473220dabf8840124657bd0bfbfbbfd2c892affdcf44ba33c9435f51366c83bb8d86ebe467f7b2a98ae0da32211b525d062ca
|
7
|
+
data.tar.gz: 9923cf90108899c59990687ace8b0e23bad06dfb01b52d8c28594ba1f657a687007f33c4aacad4981dd2391106114df3098121a74e845ee967cccb52a94405c2
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -61,14 +61,48 @@ Then, transform incoming params in your controller using `Decanter#decant`:
|
|
61
61
|
|
62
62
|
### Generators
|
63
63
|
|
64
|
-
Decanter comes with generators for creating `Decanter` and `Parser` files:
|
64
|
+
Decanter comes with custom generators for creating `Decanter` and `Parser` files:
|
65
|
+
|
66
|
+
#### Decanters
|
65
67
|
|
66
68
|
```
|
67
69
|
rails g decanter Trip name:string start_date:date end_date:date
|
70
|
+
|
71
|
+
# Creates app/decanters/trip_decanter.rb:
|
72
|
+
class TripDecanter < Decanter::Base
|
73
|
+
input :name, :string
|
74
|
+
input :start_date, :date
|
75
|
+
input :end_date, :date
|
76
|
+
end
|
68
77
|
```
|
69
78
|
|
79
|
+
#### Parsers
|
70
80
|
```
|
71
81
|
rails g parser TruncatedString
|
82
|
+
|
83
|
+
# Creates lib/decanter/parsers/truncated_string_parser.rb:
|
84
|
+
class TruncatedStringParser < Decanter::Parser::ValueParser
|
85
|
+
parser do |value, options|
|
86
|
+
value
|
87
|
+
end
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
[Learn more about using custom parsers](#custom-parsers)
|
92
|
+
|
93
|
+
#### Resources
|
94
|
+
|
95
|
+
When using the Rails resource generator in a project that includes Decanter, a decanter will be automatically created for the new resource:
|
96
|
+
|
97
|
+
```
|
98
|
+
rails g resource Trip name:string start_date:date end_date:date
|
99
|
+
|
100
|
+
# Creates app/decanters/trip_decanter.rb:
|
101
|
+
class TripDecanter < Decanter::Base
|
102
|
+
input :name, :string
|
103
|
+
input :start_date, :date
|
104
|
+
input :end_date, :date
|
105
|
+
end
|
72
106
|
```
|
73
107
|
|
74
108
|
### Decanting Collections
|
@@ -184,8 +218,8 @@ You can also disable strict mode globally using a [global configuration](#global
|
|
184
218
|
To add a custom parser, first create a parser class:
|
185
219
|
|
186
220
|
```rb
|
187
|
-
# app/parsers/
|
188
|
-
class
|
221
|
+
# app/parsers/truncated_string_parser.rb
|
222
|
+
class TruncatedStringParser < Decanter::Parser::ValueParser
|
189
223
|
|
190
224
|
parser do |value, options|
|
191
225
|
length = options.fetch(:length, 100)
|
@@ -197,7 +231,7 @@ end
|
|
197
231
|
Then, use the appropriate key to look up the parser:
|
198
232
|
|
199
233
|
```ruby
|
200
|
-
input :name, :
|
234
|
+
input :name, :truncated_string #=> TruncatedStringParser
|
201
235
|
```
|
202
236
|
|
203
237
|
#### Custom parser methods
|
data/lib/decanter/version.rb
CHANGED