decanter 4.0.2 → 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: f2c8921ba27d831a863fd3220d2df2a538549b7bd2b12ba6cfac022abdc7f0fd
4
- data.tar.gz: 22afd46a49a2e3b1ca797b84b9c145317fc61cf759f6b46988a079a965578635
3
+ metadata.gz: 855c0c38fda4543f1542a7519ff4234544d696a910f39fe195cf99f50ad6a780
4
+ data.tar.gz: 28b8bb87ee97e7a0c371124cbb8a04319b35df6c2ee642f75290d822a2015186
5
5
  SHA512:
6
- metadata.gz: cef98a3a32c715d298c65c08bfaa5d5e9093d15be4c21bdf152093117444153dcf74327be75dbbb3f1981b7727d3b230b1369b8e9d459fbb3ab615a2bee8b9d3
7
- data.tar.gz: 5d679309905d5a66b62b00ccdb1132738d462f8594c6c50b18a82caa13ba8f9ddcb62df2f92e2a6f3cf36a67e9c85305dc0eb1ad3f6689ab36e8584ae58fa701
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.2)
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
@@ -137,11 +171,19 @@ input :ids, :array, parse_each: :integer
137
171
 
138
172
  ### Parser options
139
173
 
140
- Parsers can receive options that modify their behavior. These options are passed in as named arguments to `input`:
174
+ Some parsers can receive options that modify their behavior. These options are passed in as named arguments to `input`:
175
+
176
+ **Example:**
141
177
 
142
178
  ```ruby
143
179
  input :start_date, :date, parse_format: '%Y-%m-%d'
144
180
  ```
181
+ **Available Options:**
182
+ | Parser | Option | Default | Notes
183
+ | ----------- | ----------- | -----------| -----------
184
+ | `ArrayParser` | `parse_each`| N/A | Accepts a parser type, then uses that parser to parse each element in the array. If this option is not defined, each element is simply returned.
185
+ | `DateParser`| `parse_format` | `'%m/%d/%Y'`| Accepts any format string accepted by Ruby's `strftime` method
186
+ | `DateTimeParser` | `parse_format` | `'%m/%d/%Y %I:%M:%S %p'` | Accepts any format string accepted by Ruby's `strftime` method
145
187
 
146
188
  ### Exceptions
147
189
 
@@ -176,8 +218,8 @@ You can also disable strict mode globally using a [global configuration](#global
176
218
  To add a custom parser, first create a parser class:
177
219
 
178
220
  ```rb
179
- # app/parsers/truncate_string_parser.rb
180
- class TruncateStringParser < Decanter::Parser::ValueParser
221
+ # app/parsers/truncated_string_parser.rb
222
+ class TruncatedStringParser < Decanter::Parser::ValueParser
181
223
 
182
224
  parser do |value, options|
183
225
  length = options.fetch(:length, 100)
@@ -189,7 +231,7 @@ end
189
231
  Then, use the appropriate key to look up the parser:
190
232
 
191
233
  ```ruby
192
- input :name, :truncate_string #=> TruncateStringParser
234
+ input :name, :truncated_string #=> TruncatedStringParser
193
235
  ```
194
236
 
195
237
  #### Custom parser methods
@@ -1,3 +1,3 @@
1
1
  module Decanter
2
- VERSION = '4.0.2'.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.2
4
+ version: 4.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Francis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-10-19 00:00:00.000000000 Z
12
+ date: 2024-01-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack