decanter 2.1.1 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +38 -0
  3. data/.github/ISSUE_TEMPLATE/BUG_REPORT.md +33 -0
  4. data/.github/ISSUE_TEMPLATE/FEATURE_REQUEST.md +18 -0
  5. data/.github/PULL_REQUEST_TEMPLATE.md +8 -0
  6. data/.gitignore +5 -0
  7. data/.rspec +2 -0
  8. data/.ruby-version +1 -0
  9. data/.travis.yml +10 -0
  10. data/CODE_OF_CONDUCT.md +76 -0
  11. data/CONTRIBUTING.md +36 -0
  12. data/Gemfile +4 -0
  13. data/Gemfile.lock +102 -0
  14. data/LICENSE.txt +21 -0
  15. data/README.md +241 -0
  16. data/Rakefile +1 -0
  17. data/bin/console +3 -4
  18. data/decanter.gemspec +39 -0
  19. data/lib/decanter.rb +18 -10
  20. data/lib/decanter/base.rb +0 -2
  21. data/lib/decanter/configuration.rb +2 -3
  22. data/lib/decanter/core.rb +136 -126
  23. data/lib/decanter/exceptions.rb +4 -7
  24. data/lib/decanter/extensions.rb +11 -11
  25. data/lib/decanter/parser.rb +13 -5
  26. data/lib/decanter/parser/array_parser.rb +28 -0
  27. data/lib/decanter/parser/base.rb +1 -2
  28. data/lib/decanter/parser/boolean_parser.rb +4 -3
  29. data/lib/decanter/parser/compose_parser.rb +27 -0
  30. data/lib/decanter/parser/core.rb +8 -16
  31. data/lib/decanter/parser/date_parser.rb +6 -7
  32. data/lib/decanter/parser/datetime_parser.rb +15 -0
  33. data/lib/decanter/parser/float_parser.rb +7 -5
  34. data/lib/decanter/parser/hash_parser.rb +6 -9
  35. data/lib/decanter/parser/integer_parser.rb +8 -4
  36. data/lib/decanter/parser/pass_parser.rb +5 -3
  37. data/lib/decanter/parser/phone_parser.rb +3 -3
  38. data/lib/decanter/parser/string_parser.rb +4 -5
  39. data/lib/decanter/parser/utils.rb +1 -3
  40. data/lib/decanter/parser/value_parser.rb +3 -4
  41. data/lib/decanter/railtie.rb +15 -11
  42. data/lib/decanter/version.rb +1 -3
  43. data/lib/generators/decanter/install_generator.rb +3 -5
  44. data/lib/generators/decanter/templates/initializer.rb +1 -4
  45. data/lib/generators/rails/decanter_generator.rb +5 -7
  46. data/lib/generators/rails/parser_generator.rb +3 -5
  47. data/lib/generators/rails/resource_override.rb +0 -2
  48. data/migration-guides/v3.0.0.md +21 -0
  49. metadata +47 -20
  50. data/lib/decanter/decant.rb +0 -11
  51. data/lib/decanter/parser/date_time_parser.rb +0 -21
  52. data/lib/decanter/parser/join_parser.rb +0 -14
  53. data/lib/decanter/parser/key_value_splitter_parser.rb +0 -18
  54. data/lib/decanter/parser/time_parser.rb +0 -19
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Decanter
4
- VERSION = '2.1.1'.freeze
2
+ VERSION = '3.1.1'.freeze
5
3
  end
@@ -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', __dir__)
4
+ source_root File.expand_path('../templates', __FILE__)
7
5
 
8
- desc 'Creates a Decanter initializer in your application.'
6
+ desc "Creates a Decanter initializer in your application."
9
7
 
10
8
  def copy_initializer
11
- copy_file 'initializer.rb', 'config/initializers/decanter.rb'
9
+ copy_file "initializer.rb", "config/initializers/decanter.rb"
12
10
  end
13
11
  end
14
12
  end
@@ -1,6 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  Decanter.config do |config|
4
- # Possible values are :with_exception, true or false
5
- config.strict = :with_exception
2
+ config.strict = true
6
3
  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', __dir__)
7
- check_class_collision suffix: 'Decanter'
8
- ASSOCIATION_TYPES = %i(has_many has_one belongs_to).freeze
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: :array, default: [], banner: 'field:type field:type'
8
+ argument :attributes, :type => :array, :default => [], :banner => 'field:type field:type'
11
9
 
12
- class_option :parent, type: :string, desc: 'The parent class for the generated decanter'
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', __dir__)
7
- check_class_collision suffix: 'Parser'
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ check_class_collision :suffix => 'Parser'
8
6
 
9
- class_option :parent, type: :string, desc: 'The parent class for the generated parser'
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")
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require 'rails/generators'
4
2
  require 'rails/generators/rails/resource/resource_generator'
5
3
 
@@ -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: 2.1.1
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: bin
10
+ bindir: exe
11
11
  cert_chain: []
12
- date: 2019-11-20 00:00:00.000000000 Z
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: '0'
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: '0'
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/date_time_parser.rb
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.6
204
+ rubygems_version: 3.0.3
178
205
  signing_key:
179
206
  specification_version: 4
180
207
  summary: Form Parser for Rails
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decanter
4
- module Decant
5
- extend ActiveSupport::Concern
6
-
7
- def decant(decanter, params)
8
- Decanter.decanter_for(decanter).decant(params)
9
- end
10
- end
11
- end
@@ -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,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decanter
4
- module Parser
5
- class JoinParser < ValueParser
6
- ITEM_DELIM = ','
7
-
8
- parser do |val, options|
9
- delimiter = options.fetch(:delimiter, ITEM_DELIM)
10
- val.join(delimiter)
11
- end
12
- end
13
- end
14
- 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