decanter 4.0.3 → 4.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e9d0d0e614da38a16d45d56bee4977a6e2092538d6909a373e705ca30a06860
4
- data.tar.gz: 1a468f81cedf900e10614d8328d486494d9b91ae0fbf9ee3876c3825377f4ebf
3
+ metadata.gz: 855c0c38fda4543f1542a7519ff4234544d696a910f39fe195cf99f50ad6a780
4
+ data.tar.gz: 28b8bb87ee97e7a0c371124cbb8a04319b35df6c2ee642f75290d822a2015186
5
5
  SHA512:
6
- metadata.gz: f7acb57f4a7c60c17c4fa175d735c619d0f5e3b0b9f5f5f0095d00c8f27e0cb2a80369cdea8ed1334007bf93c8094e2de1994b3258463d93e77c9c696f73d7a1
7
- data.tar.gz: 96195a3c43d867c73e4e6fb6a39d0d69248e66179c4756615e20cbc93c1b3d8056b654956459cb2daf4d29b16d28006a354cba2f2608a0d4c0271d057b37de85
6
+ metadata.gz: 523f731eb6580679bc32699b6ae473220dabf8840124657bd0bfbfbbfd2c892affdcf44ba33c9435f51366c83bb8d86ebe467f7b2a98ae0da32211b525d062ca
7
+ data.tar.gz: 9923cf90108899c59990687ace8b0e23bad06dfb01b52d8c28594ba1f657a687007f33c4aacad4981dd2391106114df3098121a74e845ee967cccb52a94405c2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- decanter (4.0.3)
4
+ decanter (4.0.4)
5
5
  actionpack (>= 4.2.10)
6
6
  activesupport
7
7
  rails-html-sanitizer (>= 1.0.4)
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/truncate_string_parser.rb
188
- class TruncateStringParser < Decanter::Parser::ValueParser
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, :truncate_string #=> TruncateStringParser
234
+ input :name, :truncated_string #=> TruncatedStringParser
201
235
  ```
202
236
 
203
237
  #### Custom parser methods
@@ -1,3 +1,3 @@
1
1
  module Decanter
2
- VERSION = '4.0.3'.freeze
2
+ VERSION = '4.0.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decanter
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.3
4
+ version: 4.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Francis