Class: Goliath::Rack::Types::Base

Inherits:
Object
  • Object
show all
Includes:
Validator
Defined in:
lib/goliath/rack/types/base.rb

Direct Known Subclasses

Boolean, Symbol

Instance Method Summary collapse

Methods included from Validator

safely, validation_error

Constructor Details

#initializeBase

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.message)
    )
  end
end