Module: Inflect::Responsive

Included in:
AbstractService
Defined in:
lib/inflect/responsive.rb

Overview

Allows services to respond an Inflect::Response instance.

Instance Method Summary collapse

Instance Method Details

#respond(content, options = {}) ⇒ Object

Supply more expressiveness and flexibility to the interface by allowing multiple ways of responding.

Examples:

Only String

respond 'String Response'

As a String with options

respond 'String Response', opt: 'Extra options'

Or as a Hash with options

respond({content: 'Hashed Response'}, {opt: 'Extra options'})


23
24
25
# File 'lib/inflect/responsive.rb', line 23

def respond(content, options = {})
  [content, options]
end

#serve(request) ⇒ Inflect::Response | nil

Method that creates Response instance.

Parameters:

  • words (Array<String>)

    The queried words.

Returns:



9
10
11
12
13
# File 'lib/inflect/responsive.rb', line 9

def serve(request)
  content, options = handle(request)
  opts = merge_options(options, { query_words: request.query_words })
  validate_response(Inflect::Response.new(content, opts))
end