Class: Shojiku::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/shojiku/request.rb

Overview

The one JSON envelope every document operation crosses with.

Both entrances build it: sources resolved from a template NAME and sources the application handed over as BYTES produce the same request, because the C surface has one request schema — and that schema rejects unknown keys, so a key the engine may legitimately not receive is dropped rather than sent as null.

Instance Method Summary collapse

Constructor Details

#initialize(sources:, params:, lang: nil, font_dirs: [], locale_dirs: []) ⇒ Request

Returns a new instance of Request.



12
13
14
15
16
17
18
# File 'lib/shojiku/request.rb', line 12

def initialize(sources:, params:, lang: nil, font_dirs: [], locale_dirs: [])
  @sources = sources
  @params = params
  @lang = lang
  @font_dirs = font_dirs
  @locale_dirs = locale_dirs
end

Instance Method Details

#jsonObject

The serialized envelope, turning the one failure JSON generation has into this gem's own exception.

Params that are not valid UTF-8 are programmer misuse — the engine's surface is UTF-8 by contract, so there is nothing to render — but a bare JSON::GeneratorError escaping from generate would make callers rescue a foreign class they never invited into their code.



27
28
29
30
31
# File 'lib/shojiku/request.rb', line 27

def json
  JSON.generate(envelope)
rescue JSON::GeneratorError, Encoding::UndefinedConversionError => e
  raise UsageError, "params could not be serialized as UTF-8 JSON: #{e.message}"
end