decanter 2.1.1 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +38 -0
- data/.github/ISSUE_TEMPLATE/BUG_REPORT.md +33 -0
- data/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md +18 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +8 -0
- data/.gitignore +5 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +10 -0
- data/CODE_OF_CONDUCT.md +76 -0
- data/CONTRIBUTING.md +36 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +102 -0
- data/LICENSE.txt +21 -0
- data/README.md +241 -0
- data/Rakefile +1 -0
- data/bin/console +3 -4
- data/decanter.gemspec +39 -0
- data/lib/decanter.rb +18 -10
- data/lib/decanter/base.rb +0 -2
- data/lib/decanter/configuration.rb +2 -3
- data/lib/decanter/core.rb +136 -126
- data/lib/decanter/exceptions.rb +4 -7
- data/lib/decanter/extensions.rb +11 -11
- data/lib/decanter/parser.rb +13 -5
- data/lib/decanter/parser/array_parser.rb +28 -0
- data/lib/decanter/parser/base.rb +1 -2
- data/lib/decanter/parser/boolean_parser.rb +4 -3
- data/lib/decanter/parser/compose_parser.rb +27 -0
- data/lib/decanter/parser/core.rb +8 -16
- data/lib/decanter/parser/date_parser.rb +6 -7
- data/lib/decanter/parser/datetime_parser.rb +15 -0
- data/lib/decanter/parser/float_parser.rb +7 -5
- data/lib/decanter/parser/hash_parser.rb +6 -9
- data/lib/decanter/parser/integer_parser.rb +8 -4
- data/lib/decanter/parser/pass_parser.rb +5 -3
- data/lib/decanter/parser/phone_parser.rb +3 -3
- data/lib/decanter/parser/string_parser.rb +4 -5
- data/lib/decanter/parser/utils.rb +1 -3
- data/lib/decanter/parser/value_parser.rb +3 -4
- data/lib/decanter/railtie.rb +15 -11
- data/lib/decanter/version.rb +1 -3
- data/lib/generators/decanter/install_generator.rb +3 -5
- data/lib/generators/decanter/templates/initializer.rb +1 -4
- data/lib/generators/rails/decanter_generator.rb +5 -7
- data/lib/generators/rails/parser_generator.rb +3 -5
- data/lib/generators/rails/resource_override.rb +0 -2
- data/migration-guides/v3.0.0.md +21 -0
- metadata +47 -20
- data/lib/decanter/decant.rb +0 -11
- data/lib/decanter/parser/date_time_parser.rb +0 -21
- data/lib/decanter/parser/join_parser.rb +0 -14
- data/lib/decanter/parser/key_value_splitter_parser.rb +0 -18
- data/lib/decanter/parser/time_parser.rb +0 -19
data/lib/decanter/version.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Decanter
|
4
2
|
module Generators
|
5
3
|
class InstallGenerator < Rails::Generators::Base
|
6
|
-
source_root File.expand_path('templates',
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
5
|
|
8
|
-
desc
|
6
|
+
desc "Creates a Decanter initializer in your application."
|
9
7
|
|
10
8
|
def copy_initializer
|
11
|
-
copy_file
|
9
|
+
copy_file "initializer.rb", "config/initializers/decanter.rb"
|
12
10
|
end
|
13
11
|
end
|
14
12
|
end
|
@@ -1,15 +1,13 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Rails
|
4
2
|
module Generators
|
5
3
|
class DecanterGenerator < NamedBase
|
6
|
-
source_root File.expand_path('templates',
|
7
|
-
check_class_collision suffix
|
8
|
-
ASSOCIATION_TYPES =
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
check_class_collision :suffix => 'Decanter'
|
6
|
+
ASSOCIATION_TYPES = [:has_many, :has_one, :belongs_to]
|
9
7
|
|
10
|
-
argument :attributes, type
|
8
|
+
argument :attributes, :type => :array, :default => [], :banner => 'field:type field:type'
|
11
9
|
|
12
|
-
class_option :parent, type
|
10
|
+
class_option :parent, :type => :string, :desc => 'The parent class for the generated decanter'
|
13
11
|
|
14
12
|
def create_decanter_file
|
15
13
|
template 'decanter.rb.erb', File.join('app/decanters', class_path, "#{file_name}_decanter.rb")
|
@@ -1,12 +1,10 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Rails
|
4
2
|
module Generators
|
5
3
|
class ParserGenerator < NamedBase
|
6
|
-
source_root File.expand_path('templates',
|
7
|
-
check_class_collision suffix
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
check_class_collision :suffix => 'Parser'
|
8
6
|
|
9
|
-
class_option :parent, type
|
7
|
+
class_option :parent, :type => :string, :desc => 'The parent class for the generated parser'
|
10
8
|
|
11
9
|
def create_parser_file
|
12
10
|
template 'parser.rb.erb', File.join('lib/decanter/parsers', class_path, "#{file_name}_parser.rb")
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# v3.0.0 Migration Guide
|
2
|
+
|
3
|
+
_Note: this guide assumes you are upgrading from decanter v1 to v3. In order to migrate from v2, please downgrade to v1 first._
|
4
|
+
|
5
|
+
This version contains the following breaking changes:
|
6
|
+
|
7
|
+
1. `strict true` mode will now raise exceptions for unhandled keys.
|
8
|
+
|
9
|
+
`strict true` previously displayed warnings rather than raising exceptions. To adapt to the new behavior, replace all instances of `strict true` in your app with `strict false`, and replace all instances of `strict :with_exception` to `strict true`.
|
10
|
+
|
11
|
+
2. `JoinParser` and `KeyValueSplitterParser` default parsers have been removed.
|
12
|
+
|
13
|
+
If you use these parsers in your project, you should include them as custom parsers. Their source code is available on the `v1` branch.
|
14
|
+
|
15
|
+
3. All default parsers (except for `ArrayParser`) now strictly require a single value.
|
16
|
+
|
17
|
+
Default parsers will now raise an exception when passed an array of values. For instance, an attribute declared with `input <name>, :string` will expect to receive a single string rather than an array of strings. Previously, default parsers handled arrays of values in unstable and undocumented ways. In the (unlikely) event that your project was relying on the previous behavior, you can include the legacy version(s) of the parsers as custom parsers in your project.
|
18
|
+
|
19
|
+
4. Decanter exceptions have been renamed from `Decanter::Core::<Exception>` to `Decanter::<Exception>`.
|
20
|
+
|
21
|
+
If your project relies on specific decanter exception names, make sure to rename those instances accordingly.
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decanter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Francis
|
8
8
|
- David Corwin
|
9
9
|
autorequire:
|
10
|
-
bindir:
|
10
|
+
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-10-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -55,6 +55,20 @@ dependencies:
|
|
55
55
|
version: 1.0.4
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.9'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.9'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: dotenv
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
59
73
|
requirements:
|
60
74
|
- - ">="
|
@@ -71,16 +85,16 @@ dependencies:
|
|
71
85
|
name: rake
|
72
86
|
requirement: !ruby/object:Gem::Requirement
|
73
87
|
requirements:
|
74
|
-
- - "
|
88
|
+
- - "~>"
|
75
89
|
- !ruby/object:Gem::Version
|
76
|
-
version: '0'
|
90
|
+
version: '10.0'
|
77
91
|
type: :development
|
78
92
|
prerelease: false
|
79
93
|
version_requirements: !ruby/object:Gem::Requirement
|
80
94
|
requirements:
|
81
|
-
- - "
|
95
|
+
- - "~>"
|
82
96
|
- !ruby/object:Gem::Version
|
83
|
-
version: '0'
|
97
|
+
version: '10.0'
|
84
98
|
- !ruby/object:Gem::Dependency
|
85
99
|
name: rspec-rails
|
86
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,50 +113,62 @@ dependencies:
|
|
99
113
|
name: simplecov
|
100
114
|
requirement: !ruby/object:Gem::Requirement
|
101
115
|
requirements:
|
102
|
-
- - "
|
116
|
+
- - "~>"
|
103
117
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
118
|
+
version: 0.15.1
|
105
119
|
type: :development
|
106
120
|
prerelease: false
|
107
121
|
version_requirements: !ruby/object:Gem::Requirement
|
108
122
|
requirements:
|
109
|
-
- - "
|
123
|
+
- - "~>"
|
110
124
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
125
|
+
version: 0.15.1
|
112
126
|
description: Decanter aims to reduce complexity in Rails controllers by creating a
|
113
127
|
place for transforming data before it hits the model and database.
|
114
128
|
email:
|
115
129
|
- ryan@launchpadlab.com
|
116
|
-
executables:
|
117
|
-
- console
|
118
|
-
- setup
|
130
|
+
executables: []
|
119
131
|
extensions: []
|
120
132
|
extra_rdoc_files: []
|
121
133
|
files:
|
134
|
+
- ".codeclimate.yml"
|
135
|
+
- ".github/ISSUE_TEMPLATE/BUG_REPORT.md"
|
136
|
+
- ".github/ISSUE_TEMPLATE/FEATURE_REQUEST.md"
|
137
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
138
|
+
- ".gitignore"
|
139
|
+
- ".rspec"
|
140
|
+
- ".ruby-version"
|
141
|
+
- ".travis.yml"
|
142
|
+
- CODE_OF_CONDUCT.md
|
143
|
+
- CONTRIBUTING.md
|
144
|
+
- Gemfile
|
145
|
+
- Gemfile.lock
|
146
|
+
- LICENSE.txt
|
147
|
+
- README.md
|
148
|
+
- Rakefile
|
122
149
|
- bin/console
|
123
150
|
- bin/setup
|
151
|
+
- decanter.gemspec
|
124
152
|
- lib/decanter.rb
|
125
153
|
- lib/decanter/base.rb
|
126
154
|
- lib/decanter/configuration.rb
|
127
155
|
- lib/decanter/core.rb
|
128
|
-
- lib/decanter/decant.rb
|
129
156
|
- lib/decanter/exceptions.rb
|
130
157
|
- lib/decanter/extensions.rb
|
131
158
|
- lib/decanter/parser.rb
|
159
|
+
- lib/decanter/parser/array_parser.rb
|
132
160
|
- lib/decanter/parser/base.rb
|
133
161
|
- lib/decanter/parser/boolean_parser.rb
|
162
|
+
- lib/decanter/parser/compose_parser.rb
|
134
163
|
- lib/decanter/parser/core.rb
|
135
164
|
- lib/decanter/parser/date_parser.rb
|
136
|
-
- lib/decanter/parser/
|
165
|
+
- lib/decanter/parser/datetime_parser.rb
|
137
166
|
- lib/decanter/parser/float_parser.rb
|
138
167
|
- lib/decanter/parser/hash_parser.rb
|
139
168
|
- lib/decanter/parser/integer_parser.rb
|
140
|
-
- lib/decanter/parser/join_parser.rb
|
141
|
-
- lib/decanter/parser/key_value_splitter_parser.rb
|
142
169
|
- lib/decanter/parser/pass_parser.rb
|
143
170
|
- lib/decanter/parser/phone_parser.rb
|
144
171
|
- lib/decanter/parser/string_parser.rb
|
145
|
-
- lib/decanter/parser/time_parser.rb
|
146
172
|
- lib/decanter/parser/utils.rb
|
147
173
|
- lib/decanter/parser/value_parser.rb
|
148
174
|
- lib/decanter/railtie.rb
|
@@ -154,6 +180,7 @@ files:
|
|
154
180
|
- lib/generators/rails/resource_override.rb
|
155
181
|
- lib/generators/rails/templates/decanter.rb.erb
|
156
182
|
- lib/generators/rails/templates/parser.rb.erb
|
183
|
+
- migration-guides/v3.0.0.md
|
157
184
|
homepage: https://github.com/launchpadlab/decanter
|
158
185
|
licenses:
|
159
186
|
- MIT
|
@@ -174,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
201
|
- !ruby/object:Gem::Version
|
175
202
|
version: '0'
|
176
203
|
requirements: []
|
177
|
-
rubygems_version: 3.0.
|
204
|
+
rubygems_version: 3.0.3
|
178
205
|
signing_key:
|
179
206
|
specification_version: 4
|
180
207
|
summary: Form Parser for Rails
|
data/lib/decanter/decant.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Decanter
|
4
|
-
module Parser
|
5
|
-
# rubocop:disable Style/DateTime
|
6
|
-
class DateTimeParser < ValueParser
|
7
|
-
allow DateTime
|
8
|
-
|
9
|
-
parser do |val, options|
|
10
|
-
if val.is_a?(Time)
|
11
|
-
val.to_datetime
|
12
|
-
elsif (parse_format = options[:parse_format])
|
13
|
-
::DateTime.strptime(val, parse_format)
|
14
|
-
else
|
15
|
-
::DateTime.parse(val)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
# rubocop:enable Style/DateTime
|
20
|
-
end
|
21
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Decanter
|
4
|
-
module Parser
|
5
|
-
class KeyValueSplitterParser < HashParser
|
6
|
-
ITEM_DELIM = ','
|
7
|
-
PAIR_DELIM = ':'
|
8
|
-
|
9
|
-
parser do |val, options|
|
10
|
-
item_delimiter = options.fetch(:item_delimiter, ITEM_DELIM)
|
11
|
-
pair_delimiter = options.fetch(:pair_delimiter, PAIR_DELIM)
|
12
|
-
val.split(item_delimiter).reduce({}) do |memo, pair|
|
13
|
-
memo.merge(Hash[*pair.split(pair_delimiter)])
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Decanter
|
4
|
-
module Parser
|
5
|
-
class TimeParser < ValueParser
|
6
|
-
allow Time
|
7
|
-
|
8
|
-
parser do |val, options|
|
9
|
-
if val.is_a?(DateTime)
|
10
|
-
val.to_time
|
11
|
-
elsif (parse_format = options[:parse_format])
|
12
|
-
::Time.strptime(val, parse_format)
|
13
|
-
else
|
14
|
-
::Time.parse(val)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|