decanter 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +70 -15
  4. data/lib/decanter.rb +11 -2
  5. data/lib/decanter/configuration.rb +10 -0
  6. data/lib/decanter/core.rb +2 -2
  7. data/lib/decanter/parser.rb +27 -0
  8. data/lib/decanter/parser/base.rb +10 -0
  9. data/lib/decanter/{value_parser → parser}/boolean_parser.rb +3 -3
  10. data/lib/decanter/{value_parser → parser}/core.rb +4 -17
  11. data/lib/decanter/{value_parser → parser}/date_parser.rb +3 -3
  12. data/lib/decanter/parser/datetime_parser.rb +13 -0
  13. data/lib/decanter/{value_parser → parser}/float_parser.rb +3 -3
  14. data/lib/decanter/parser/hash_parser.rb +18 -0
  15. data/lib/decanter/{value_parser → parser}/integer_parser.rb +3 -3
  16. data/lib/decanter/{value_parser → parser}/join_parser.rb +3 -3
  17. data/lib/decanter/{value_parser → parser}/key_value_splitter_parser.rb +2 -4
  18. data/lib/decanter/parser/pass_parser.rb +8 -0
  19. data/lib/decanter/{value_parser → parser}/phone_parser.rb +3 -3
  20. data/lib/decanter/parser/string_parser.rb +12 -0
  21. data/lib/decanter/parser/value_parser.rb +12 -0
  22. data/lib/decanter/railtie.rb +2 -4
  23. data/lib/decanter/version.rb +1 -1
  24. data/lib/generators/decanter/install_generator.rb +13 -0
  25. data/lib/generators/decanter/templates/initializer.rb +4 -0
  26. data/lib/generators/rails/parser_generator.rb +1 -1
  27. metadata +20 -14
  28. data/lib/decanter/value_parser.rb +0 -25
  29. data/lib/decanter/value_parser/base.rb +0 -13
  30. data/lib/decanter/value_parser/datetime_parser.rb +0 -13
  31. data/lib/decanter/value_parser/string_parser.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1cea76ec8e01a183736aeb145f1b58cb8f00298
4
- data.tar.gz: 370986b00b379fc188bc327a76e4411038f0c4b9
3
+ metadata.gz: fcecd146883e6b44658dcee94a7271f552c695cf
4
+ data.tar.gz: 1362e8a5b04500354b60f7530916c487fed7f6c6
5
5
  SHA512:
6
- metadata.gz: 0e17c3aba3e202f20638f80993d73f9a7773b6890eb46006c470a972a8f7cf7a0ce87fd07713097a40fa48482430dfc3b897a9126e14f0c49297ca1e49fa941a
7
- data.tar.gz: af705b120764f79bff09350351830f8908b2fcb73cd74463bde2bd66dc898c63673c30fd361ff71fbbe528d512bace6d2eef4d08d6ee954f60780807ce381507
6
+ metadata.gz: f95eee6b059ac8f0ec596fe74889dfeae1e30392a86d76a9159c07f895b5016300068f945d5e49d30bd9feace6257b28d3ab9f6ff29ec105fc923ff14a147ccf
7
+ data.tar.gz: bcc79760fca3ebfb1fc1d4ce4aa4ae04993d0acff6422be01e0a40a7de4c7556d7269d636fff739a8e90f022d0873c0a83cad0b3fd51ec4931adbda8ec4fe843
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- decanter (0.7.0)
4
+ decanter (0.7.1)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -55,7 +55,7 @@ In your controller:
55
55
 
56
56
  def update
57
57
  @trip = Trip.find(params[:id])
58
-
58
+
59
59
  if @trip.decant_update(params[:trip])
60
60
  redirect_to trips_path
61
61
  else
@@ -139,7 +139,7 @@ end
139
139
  You'll also notice that instead of ```@trip = Trip.new(params[:trip])``` we do ```@trip = Trip.decant_new(params[:trip])```. ```decant_new``` is where the magic happens. It is converting the params from this:
140
140
 
141
141
  ```ruby
142
- {
142
+ {
143
143
  name: "My Trip",
144
144
  start_date: "01/15/2015",
145
145
  end_date: "01/20/2015"
@@ -149,7 +149,7 @@ You'll also notice that instead of ```@trip = Trip.new(params[:trip])``` we do `
149
149
  to this:
150
150
 
151
151
  ```ruby
152
- {
152
+ {
153
153
  name: "My Trip",
154
154
  start_date: Mon, 15 Jan 2015,
155
155
  end_date: Mon, 20 Jan 2015
@@ -163,12 +163,14 @@ Adding Custom Parsers
163
163
 
164
164
  In the above example, start_date and end_date are ran through a DateParser that lives in Decanter. Let's take a look at the DateParser:
165
165
 
166
+ ** Note this changed in version 0.7.2. Now parser must inherit from Decanter::Parser::ValueParser or Decanter::Parser::HashParser instead of Decanter::Parser::Base **
167
+
166
168
  ```ruby
167
- class DateParser < Decanter::ValueParser::Base
169
+ class DateParser < Decanter::Parser::ValueParser
168
170
 
169
171
  allow Date
170
172
 
171
- parser do |name, value, options|
173
+ parser do |value, options|
172
174
  parse_format = options.fetch(:parse_format, '%m/%d/%Y')
173
175
  ::Date.strptime(value, parse_format)
174
176
  end
@@ -182,7 +184,7 @@ You'll notice that the above ```parser do``` block takes a ```:parse_format``` o
182
184
  ```ruby
183
185
  # app/decanters/trip_decanter.rb
184
186
 
185
- class TripDecanter < Decanter::Base
187
+ class TripDecanter < Decanter::ValueParser
186
188
  input :name, :string
187
189
  input :start_date, :date, parse_format: '%Y-%m-%d'
188
190
  input :end_date, :date, parse_format: '%Y-%m-%d'
@@ -198,13 +200,41 @@ rails g parser Date
198
200
  **lib/decanter/parsers/date_parser**
199
201
 
200
202
  ```ruby
201
- class DateParser < Decanter::ValueParser::Base
202
- parser do |name, value, options|
203
+ class DateParser < Decanter::Parser::ValueParser
204
+ parser do |value, options|
203
205
  # your parsing logic here
204
206
  end
205
207
  end
206
208
  ```
207
209
 
210
+
211
+ By inheriting from Decanter::Parser::ValueParser, the assumption is that the value returned from the parser will be the value associated with the provided key. If you need more control over the result, for example, you want a parser that returns multiple key value pairs, you should instead inherit from Decanter::Parser::HashParser. This requires that the value returned is a hash. For example:
212
+
213
+ ```ruby
214
+ class KeyValueSplitterParser < Decanter::Parser::HashParser
215
+ ITEM_DELIM = ','
216
+ PAIR_DELIM = ':'
217
+
218
+ parser do |name, val, options|
219
+ # val = 'color:blue,price:45.31'
220
+
221
+ item_delimiter = options.fetch(:item_delimiter, ITEM_DELIM)
222
+ pair_delimiter = options.fetch(:pair_delimiter, PAIR_DELIM)
223
+
224
+ pairs = val.split(item_delimiter) # ['color:blue', 'price:45.31']
225
+
226
+ hash = {}
227
+ pairs.each do |pair|
228
+ key, value = pair.split(pair_delimiter) # 'color', 'blue'
229
+ hash[key] = value
230
+ end
231
+ return hash
232
+ end
233
+ end
234
+ ```
235
+
236
+ The ```parser``` block takes the 'name' as an additional argument and must return a hash.
237
+
208
238
  Nested Example
209
239
  ---
210
240
 
@@ -273,7 +303,7 @@ Each of the destinations in our params[:trip] are automatically parsed according
273
303
  Non Database-Backed Objects
274
304
  ---
275
305
 
276
- Decanter will work for your non database-backed objects as well. We just need to call ```decant``` to parse our params according to our decanter logic.
306
+ Decanter will work for your non database-backed objects as well. We just need to call ```decant``` to parse our params according to our decanter logic.
277
307
 
278
308
  Let's say we have a search filtering object called ```SearchFilter```. We start by generating our decanter:
279
309
 
@@ -305,9 +335,12 @@ Default Parsers
305
335
  Decanter comes with the following parsers:
306
336
  - boolean
307
337
  - date
308
- - datetime
338
+ - date_time
309
339
  - float
310
340
  - integer
341
+ - join
342
+ - key_value_splitter
343
+ - pass
311
344
  - phone
312
345
  - string
313
346
 
@@ -322,11 +355,11 @@ rails g parser Zip
322
355
  Squashing Inputs
323
356
  ---
324
357
 
325
- Sometimes, you may want to take several inputs and combine them into one finished input prior to sending to your model. For example, if day, month, and year come in as separate parameters, but your database really only cares about start_date.
358
+ Sometimes, you may want to take several inputs and combine them into one finished input prior to sending to your model. For example, if day, month, and year come in as separate parameters, but your database really only cares about start_date.
326
359
 
327
360
  ```ruby
328
361
  class TripDecanter < Decanter::Base
329
- input [:day, :month, :year], :squash_date, key: :start_date
362
+ input [:day, :month, :year], :squash_date, key: :start_date
330
363
  end
331
364
  ```
332
365
 
@@ -337,8 +370,8 @@ rails g parser SquashDate
337
370
  ```ruby
338
371
  # lib/decanter/parsers/squash_date_parser.rb
339
372
 
340
- class SquashDateParser < Decanter::Parser::Base
341
- parser do |name, values, options|
373
+ class SquashDateParser < Decanter::Parser::ValueParser
374
+ parser do |values, options|
342
375
  day, month, year = values.map(&:to_i)
343
376
  Date.new(year, month, day)
344
377
  end
@@ -348,7 +381,7 @@ end
348
381
  No Need for Strong Params
349
382
  ---
350
383
 
351
- Since you are already defining your expected inputs in Decanter, you really don't need strong_params anymore.
384
+ Since you are already defining your expected inputs in Decanter, you really don't need strong params anymore.
352
385
 
353
386
  In order to tell Decanter to ignore the params not defined in your Decanter, just add the ```strict``` flag to your Decanters:
354
387
 
@@ -369,3 +402,25 @@ class TripDecanter < Decanter::Base
369
402
  input :name
370
403
  end
371
404
  ```
405
+
406
+ Configuration
407
+ ---
408
+
409
+ You can generate a local copy of the default configuration with ```rails generate decanter:install```. This will create the initializer ```../config/initializers/decanter.rb```.
410
+
411
+ Starting with version 0.7.2, the default strict mode is ```:with_exception```. If this is what you prefer, you no longer have to set it in every decanter. You can still set this on individual decanters or you can configure it globally in the initializer:
412
+
413
+ ```ruby
414
+ # ../config/initializers/decanter.rb
415
+
416
+ Decanter.config do |config|
417
+ config.strict = true
418
+ end
419
+
420
+ # Or
421
+
422
+ Decanter.configuration.strict = true
423
+ ```
424
+
425
+ Likewise, you can put the above code in a specific environment configuration.
426
+
data/lib/decanter.rb CHANGED
@@ -32,14 +32,23 @@ module Decanter
32
32
 
33
33
  constant
34
34
  end
35
+
36
+ def configuration
37
+ @config ||= Decanter::Configuration.new
38
+ end
39
+
40
+ def config
41
+ yield configuration
42
+ end
35
43
  end
36
44
 
37
45
  ActiveSupport.run_load_hooks(:decanter, self)
38
46
  end
39
47
 
40
48
  require 'decanter/version'
41
- require 'decanter/base'
49
+ require 'decanter/configuration'
42
50
  require 'decanter/core'
51
+ require 'decanter/base'
43
52
  require 'decanter/extensions'
44
- require 'decanter/value_parser'
53
+ require 'decanter/parser'
45
54
  require 'decanter/railtie' if defined?(::Rails)
@@ -0,0 +1,10 @@
1
+ module Decanter
2
+ class Configuration
3
+
4
+ attr_accessor :strict
5
+
6
+ def initialize
7
+ @strict = :with_exception
8
+ end
9
+ end
10
+ end
data/lib/decanter/core.rb CHANGED
@@ -156,7 +156,7 @@ module Decanter
156
156
 
157
157
  def parse(key, parser, values, options)
158
158
  parser ?
159
- ValueParser.value_parser_for(parser)
159
+ Parser.parser_for(parser)
160
160
  .parse(key, values, options)
161
161
  :
162
162
  { key => values }
@@ -167,7 +167,7 @@ module Decanter
167
167
  end
168
168
 
169
169
  def strict_mode
170
- @strict_mode ||= {}
170
+ @strict_mode.nil? ? Decanter.configuration.strict : @strict_mode
171
171
  end
172
172
  end
173
173
  end
@@ -0,0 +1,27 @@
1
+ module Decanter
2
+ module Parser
3
+
4
+ class << self
5
+ def parser_for(klass_or_sym)
6
+ parser_str = case klass_or_sym
7
+ when Class
8
+ klass_or_sym.name
9
+ when Symbol
10
+ klass_or_sym.to_s.singularize.camelize
11
+ else
12
+ raise ArgumentError.new("cannot lookup parser for #{klass_or_sym} with class #{klass_or_sym.class}")
13
+ end.concat('Parser')
14
+
15
+ parser = parser_str.safe_constantize || "Decanter::Parser::".concat(parser_str).safe_constantize
16
+ raise NameError.new("cannot find parser #{parser_str}") unless parser
17
+ parser
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ require "#{File.dirname(__FILE__)}/parser/core.rb"
24
+ require "#{File.dirname(__FILE__)}/parser/base.rb"
25
+ require "#{File.dirname(__FILE__)}/parser/value_parser.rb"
26
+ require "#{File.dirname(__FILE__)}/parser/hash_parser.rb"
27
+ Dir["#{File.dirname(__FILE__)}/parser/*_parser.rb"].each { |f| require f }
@@ -0,0 +1,10 @@
1
+ require_relative 'core'
2
+
3
+ module Decanter
4
+ module Parser
5
+ class Base
6
+ include Core
7
+ end
8
+ end
9
+ end
10
+
@@ -1,10 +1,10 @@
1
1
  module Decanter
2
- module ValueParser
3
- class BooleanParser < Base
2
+ module Parser
3
+ class BooleanParser < ValueParser
4
4
 
5
5
  allow TrueClass, FalseClass
6
6
 
7
- parser do |name, val, options|
7
+ parser do |val, options|
8
8
  [1, '1'].include?(val) || !!/true/i.match(val.to_s)
9
9
  end
10
10
  end
@@ -1,5 +1,5 @@
1
1
  module Decanter
2
- module ValueParser
2
+ module Parser
3
3
  module Core
4
4
 
5
5
  def self.included(base)
@@ -8,6 +8,7 @@ module Decanter
8
8
 
9
9
  module ClassMethods
10
10
 
11
+ # Meant to be overriden and called by child parser
11
12
  def parse(name, values, options={})
12
13
 
13
14
  value_ary = values.is_a?(Array) ? values : [values]
@@ -21,7 +22,7 @@ module Decanter
21
22
  end
22
23
  end
23
24
 
24
- if @allowed && value_ary.all? { |value| @allowed.include?(value.class) }
25
+ if @allowed && value_ary.all? { |value| @allowed.any? { |allowed| value.is_a? allowed } }
25
26
  return { name => values }
26
27
  end
27
28
 
@@ -29,17 +30,7 @@ module Decanter
29
30
  raise ArgumentError.new("No parser for argument: #{name} with types: #{value_ary.map(&:class).join(', ')}")
30
31
  end
31
32
 
32
- case @result
33
- when :raw
34
- # Parser result must be a hash
35
- parsed = @parser.call(name, values, options)
36
- parsed.is_a?(Hash) ?
37
- parsed :
38
- raise(ArgumentError.new("Result of parser #{self.name} with values #{values} was #{parsed} when it must be a hash."))
39
- else
40
- # Parser result will be treated as a single value belonging to the name
41
- { name => @parser.call(name, values, options) }
42
- end
33
+ _parse(name, values, options)
43
34
  end
44
35
 
45
36
  def parser(&block)
@@ -49,10 +40,6 @@ module Decanter
49
40
  def allow(*args)
50
41
  @allowed = args
51
42
  end
52
-
53
- def result(opt)
54
- @result = opt
55
- end
56
43
  end
57
44
  end
58
45
  end
@@ -1,10 +1,10 @@
1
1
  module Decanter
2
- module ValueParser
3
- class DateParser < Base
2
+ module Parser
3
+ class DateParser < ValueParser
4
4
 
5
5
  allow Date
6
6
 
7
- parser do |name, val, options|
7
+ parser do |val, options|
8
8
  parse_format = options.fetch(:parse_format, '%m/%d/%Y')
9
9
  ::Date.strptime(val, parse_format)
10
10
  end
@@ -0,0 +1,13 @@
1
+ module Decanter
2
+ module Parser
3
+ class DateTimeParser < ValueParser
4
+
5
+ allow DateTime
6
+
7
+ parser do |val, options|
8
+ parse_format = options.fetch(:parse_format, '%m/%d/%Y %I:%M:%S %p')
9
+ ::DateTime.strptime(val, parse_format)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,11 +1,11 @@
1
1
  module Decanter
2
- module ValueParser
3
- class FloatParser < Base
2
+ module Parser
3
+ class FloatParser < ValueParser
4
4
  REGEX = /(\d|[.])/
5
5
 
6
6
  allow Float, Fixnum
7
7
 
8
- parser do |name, val, options|
8
+ parser do |val, options|
9
9
  val.scan(REGEX).join.try(:to_f)
10
10
  end
11
11
  end
@@ -0,0 +1,18 @@
1
+ require_relative 'core'
2
+
3
+ module Decanter
4
+ module Parser
5
+ class HashParser < Base
6
+ def self._parse(name, values, options={})
7
+ validate_hash(@parser.call(name, values, options))
8
+ end
9
+
10
+ private
11
+ def self.validate_hash(parsed)
12
+ parsed.is_a?(Hash) ? parsed :
13
+ raise(ArgumentError.new("Result of HashParser #{self.name} was #{parsed} when it must be a hash."))
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -1,11 +1,11 @@
1
1
  module Decanter
2
- module ValueParser
3
- class IntegerParser < Base
2
+ module Parser
3
+ class IntegerParser < ValueParser
4
4
  REGEX = /(\d|[.])/
5
5
 
6
6
  allow Fixnum
7
7
 
8
- parser do |name, val, options|
8
+ parser do |val, options|
9
9
  val.is_a?(Float) ?
10
10
  val.to_i :
11
11
  val.scan(REGEX).join.try(:to_i)
@@ -1,9 +1,9 @@
1
1
  module Decanter
2
- module ValueParser
3
- class JoinParser < Base
2
+ module Parser
3
+ class JoinParser < ValueParser
4
4
  DELIM = ','
5
5
 
6
- parser do |name, val, options|
6
+ parser do |val, options|
7
7
  delimiter = options.fetch(:delimiter, ITEM_DELIM)
8
8
  val.join(DELIM)
9
9
  end
@@ -1,11 +1,9 @@
1
1
  module Decanter
2
- module ValueParser
3
- class KeyValueSplitterParser < Base
2
+ module Parser
3
+ class KeyValueSplitterParser < HashParser
4
4
  ITEM_DELIM = ','
5
5
  PAIR_DELIM = ':'
6
6
 
7
- result :raw
8
-
9
7
  parser do |name, val, options|
10
8
  item_delimiter = options.fetch(:item_delimiter, ITEM_DELIM)
11
9
  pair_delimiter = options.fetch(:pair_delimiter, PAIR_DELIM)
@@ -0,0 +1,8 @@
1
+ module Decanter
2
+ module Parser
3
+ class PassParser < ValueParser
4
+
5
+ allow Object
6
+ end
7
+ end
8
+ end
@@ -1,11 +1,11 @@
1
1
  module Decanter
2
- module ValueParser
3
- class PhoneParser < Base
2
+ module Parser
3
+ class PhoneParser < ValueParser
4
4
  REGEX = /\d/
5
5
 
6
6
  allow Fixnum
7
7
 
8
- parser do |name, val, options|
8
+ parser do |val, options|
9
9
  val.scan(REGEX).join.to_s
10
10
  end
11
11
  end
@@ -0,0 +1,12 @@
1
+ module Decanter
2
+ module Parser
3
+ class StringParser < ValueParser
4
+
5
+ allow String
6
+
7
+ parser do |val, options|
8
+ val.to_s
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require_relative 'core'
2
+
3
+ module Decanter
4
+ module Parser
5
+ class ValueParser < Base
6
+ def self._parse(name, values, options={})
7
+ { name => @parser.call(values, options) }
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -9,10 +9,8 @@ class Decanter::Railtie < Rails::Railtie
9
9
  end
10
10
  end
11
11
 
12
- config.to_prepare do
13
- Dir[
14
- File.expand_path(Rails.root.join("lib/decanter/parsers/*"))
15
- ].each { |file| require file }
12
+ initializer 'decanter.parser.autoload', :before => :set_autoload_paths do |app|
13
+ app.config.autoload_paths << Rails.root.join("lib/decanter/parsers")
16
14
  end
17
15
 
18
16
  generators do |app|
@@ -1,3 +1,3 @@
1
1
  module Decanter
2
- VERSION = '0.7.1'
2
+ VERSION = '0.7.2'
3
3
  end
@@ -0,0 +1,13 @@
1
+ module Decanter
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ desc "Creates a Decanter initializer in your application."
7
+
8
+ def copy_initializer
9
+ copy_file "initializer.rb", "config/initializers/decanter.rb"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ Decanter.config do |config|
2
+ # Possible values are :with_exception, true or false
3
+ config.strict = :with_exception
4
+ end
@@ -13,7 +13,7 @@ module Rails
13
13
  private
14
14
 
15
15
  def parent_class_name
16
- 'Decanter::ValueParser::Base'
16
+ 'Decanter::Parser::Base'
17
17
  end
18
18
  end
19
19
  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: 0.7.1
4
+ version: 0.7.2
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: 2016-03-14 00:00:00.000000000 Z
12
+ date: 2016-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -116,22 +116,28 @@ files:
116
116
  - decanter.gemspec
117
117
  - lib/decanter.rb
118
118
  - lib/decanter/base.rb
119
+ - lib/decanter/configuration.rb
119
120
  - lib/decanter/core.rb
120
121
  - lib/decanter/extensions.rb
122
+ - lib/decanter/parser.rb
123
+ - lib/decanter/parser/base.rb
124
+ - lib/decanter/parser/boolean_parser.rb
125
+ - lib/decanter/parser/core.rb
126
+ - lib/decanter/parser/date_parser.rb
127
+ - lib/decanter/parser/datetime_parser.rb
128
+ - lib/decanter/parser/float_parser.rb
129
+ - lib/decanter/parser/hash_parser.rb
130
+ - lib/decanter/parser/integer_parser.rb
131
+ - lib/decanter/parser/join_parser.rb
132
+ - lib/decanter/parser/key_value_splitter_parser.rb
133
+ - lib/decanter/parser/pass_parser.rb
134
+ - lib/decanter/parser/phone_parser.rb
135
+ - lib/decanter/parser/string_parser.rb
136
+ - lib/decanter/parser/value_parser.rb
121
137
  - lib/decanter/railtie.rb
122
- - lib/decanter/value_parser.rb
123
- - lib/decanter/value_parser/base.rb
124
- - lib/decanter/value_parser/boolean_parser.rb
125
- - lib/decanter/value_parser/core.rb
126
- - lib/decanter/value_parser/date_parser.rb
127
- - lib/decanter/value_parser/datetime_parser.rb
128
- - lib/decanter/value_parser/float_parser.rb
129
- - lib/decanter/value_parser/integer_parser.rb
130
- - lib/decanter/value_parser/join_parser.rb
131
- - lib/decanter/value_parser/key_value_splitter_parser.rb
132
- - lib/decanter/value_parser/phone_parser.rb
133
- - lib/decanter/value_parser/string_parser.rb
134
138
  - lib/decanter/version.rb
139
+ - lib/generators/decanter/install_generator.rb
140
+ - lib/generators/decanter/templates/initializer.rb
135
141
  - lib/generators/rails/decanter_generator.rb
136
142
  - lib/generators/rails/parser_generator.rb
137
143
  - lib/generators/rails/resource_override.rb
@@ -1,25 +0,0 @@
1
- module Decanter
2
- module ValueParser
3
- @@value_parsers = {}
4
-
5
- def self.register(value_parser)
6
- @@value_parsers[value_parser.name.demodulize] = value_parser
7
- end
8
-
9
- def self.value_parser_for(sym)
10
- @@value_parsers["#{sym.to_s.camelize}Parser"] || (raise NameError.new("unknown value parser #{sym.to_s.capitalize}Parser"))
11
- end
12
- end
13
- end
14
-
15
- require_relative 'value_parser/base'
16
- require_relative 'value_parser/core'
17
- require_relative 'value_parser/boolean_parser'
18
- require_relative 'value_parser/date_parser'
19
- require_relative 'value_parser/datetime_parser'
20
- require_relative 'value_parser/string_parser'
21
- require_relative 'value_parser/phone_parser'
22
- require_relative 'value_parser/float_parser'
23
- require_relative 'value_parser/integer_parser'
24
- require_relative 'value_parser/key_value_splitter_parser'
25
- require_relative 'value_parser/join_parser'
@@ -1,13 +0,0 @@
1
- require_relative 'core'
2
-
3
- module Decanter
4
- module ValueParser
5
- class Base
6
- include Core
7
- def self.inherited(subclass)
8
- ValueParser.register(subclass)
9
- end
10
- end
11
- end
12
- end
13
-
@@ -1,13 +0,0 @@
1
- module Decanter
2
- module ValueParser
3
- class DateTimeParser < Base
4
-
5
- allow DateTime
6
-
7
- parser do |name, val, options|
8
- parse_format = options.fetch(:parse_format, '%m/%d/%Y')
9
- ::Date.strptime(val, parse_format)
10
- end
11
- end
12
- end
13
- end
@@ -1,12 +0,0 @@
1
- module Decanter
2
- module ValueParser
3
- class StringParser < Base
4
-
5
- allow String
6
-
7
- parser do |name, val, options|
8
- val.to_s
9
- end
10
- end
11
- end
12
- end