Class: Goliath::Rack::Types::Base
- Inherits:
-
Object
- Object
- Goliath::Rack::Types::Base
- Includes:
- Validator
- Defined in:
- lib/goliath/rack/types/base.rb
Instance Method Summary collapse
- #coerce(val, opts = {}) ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
Methods included from Validator
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
7 8 9 |
# File 'lib/goliath/rack/types/base.rb', line 7 def initialize @short_name = self.class.name.split("::").last end |
Instance Method Details
#coerce(val, opts = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/goliath/rack/types/base.rb', line 11 def coerce(val, opts={}) begin _coerce(val) rescue => e return opts[:default] if opts[:default] raise Goliath::Rack::Validation::FailedCoerce.new( validation_error(400, opts[:message] || e.) ) end end |