class Gravaty::Parsers::Default

This class is an implementation of the Parsable duck type that checks the default option. The only needed parameter is a valid default option.

Author

Marco Bresciani

rubocop:disable Style/AsciiComments

Copyright

Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Marco Bresciani

rubocop:enable Style/AsciiComments

License

GNU General Public License version 3

Public Instance Methods

parse(value = nil) click to toggle source

The parsable duck type interface to every parser usage.

   # File lib/gravaty/parsers/default.rb
46 def parse(value = nil)
47   unless value.nil? || value.empty?
48     unless DEFAULT_OPTIONS.include? value
49       valid = %w[http https].index { |scheme| valid?(value, scheme) }
50 
51       raise ArgumentError, I18n.t('error.uri', value: value) if valid.nil?
52     end
53 
54     return "d=#{CGI.escape(value)}"
55   end
56   ''
57 end