Module: JsClientBridge::Responses::Validation

Included in:
JsClientBridge::Responses
Defined in:
lib/js-client-bridge/responses/validation.rb

Instance Method Summary collapse

Instance Method Details

#render_validation(*args) ⇒ String

Generates a validation error status response. If the first parameter is a string is will be used as the _status options. It will also honour custom optionss as long they don’t clash with the standard ones.

Parameters:

  • message (String)

    An optional message.

  • options (Hash)

    Custom optionss.

Returns:

  • (String)

    The response as a String encoded JSON object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/js-client-bridge/responses/validation.rb', line 42

def render_validation(*args)
  obj = args.shift
  options = args.last.is_a?(Hash) ? args.pop : {}

  # Generate our response hash and add the exceptions parameter
  response =  if options.include?(:message)
                options.merge( validation_errors_to_hash(obj, options.delete(:message)) )
              else
                options.merge( validation_errors_to_hash(obj) )
              end

  format_response(response, options)
end

#respond_with_validation_error(*args) ⇒ Hash

Generates a validation error status response. If the first parameter is a string is will be used as the _status options. It will also honour custom optionss as long they don’t clash with the standard ones.

Parameters:

  • message (String)

    An optional message.

  • options (Hash)

    Custom optionss.

Returns:

  • (Hash)

    The response as a Hash



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/js-client-bridge/responses/validation.rb', line 17

def respond_with_validation_error(*args)
  obj = args.shift
  options = args.last.is_a?(Hash) ? args.pop : {}

  # Generate our response hash and add the exceptions parameter
  response =  if options.include?(:message)
                options.merge( validation_errors_to_hash(obj, options.delete(:message)) )
              else
                options.merge( validation_errors_to_hash(obj) )
              end

  response
end