module Hypernova

Constants

RENDER_TOKEN_REGEX

TODO: more interesting token format?

VERSION

Attributes

configuration[RW]

Public Class Methods

add_plugin!(plugin) click to toggle source
# File lib/hypernova.rb, line 33
def self.add_plugin!(plugin)
  plugins << plugin
end
configure() { |configuration| ... } click to toggle source
# File lib/hypernova.rb, line 17
def self.configure
  self.configuration ||= Hypernova::Configuration.new
  yield(configuration)
end
plugins() click to toggle source
# File lib/hypernova.rb, line 29
def self.plugins
  @plugins ||= []
end
render_token(batch_token) click to toggle source
# File lib/hypernova.rb, line 25
def self.render_token(batch_token)
  "__hypernova_render_token[#{batch_token}]__"
end
replace_tokens_with_result(body, render_token_to_batch_token, batch_result) click to toggle source

replace all hypernova tokens in `body` with the render results given by batch_result, using render_token_to_batch_token to map render tokens into batch tokens @param [String] body @param [Hash] render_token_to_batch_token @param respond_to(:[]) batch_result

# File lib/hypernova.rb, line 43
def self.replace_tokens_with_result(body, render_token_to_batch_token, batch_result)
  # replace all render tokens in the current response body with the
  # hypernova result for that render.
  return body.gsub(RENDER_TOKEN_REGEX) do |render_token|
    batch_token = render_token_to_batch_token[render_token]
    if batch_token.nil?
      next render_token
    end
    render_result = batch_result[batch_token]
    # replace with that render result.
    next render_result
  end
end
verify_job_shape(job) click to toggle source

raises a BadJobError if the job hash is not of the right shape.

# File lib/hypernova.rb, line 59
def self.verify_job_shape(job)
  [:name, :data].each do |key|
    if job[key].nil?
      raise BadJobError.new("Hypernova render jobs must have key #{key}")
    end
  end
end