Module: Hypernova

Defined in:
lib/hypernova.rb,
lib/hypernova/batch.rb,
lib/hypernova/version.rb,
lib/hypernova/controller_helpers.rb

Defined Under Namespace

Modules: ControllerHelpers, PluginHelper Classes: BadJobError, Batch, BatchRenderer, BatchUrlBuilder, BlankRenderer, Configuration, FaradayConnection, FaradayRequest, HttpClientRequest, NilBatchError, ParsedResponse, Request, RequestService, Response

Constant Summary collapse

RENDER_TOKEN_REGEX =

TODO: more interesting token format?

/__hypernova_render_token\[\w+\]__/
VERSION =
"2.0.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



16
17
18
# File 'lib/hypernova.rb', line 16

def configuration
  @configuration
end

Class Method Details

.add_plugin!(plugin) ⇒ Object



35
36
37
# File 'lib/hypernova.rb', line 35

def self.add_plugin!(plugin)
  plugins << plugin
end

.configure {|configuration| ... } ⇒ Object

Yields:



19
20
21
22
# File 'lib/hypernova.rb', line 19

def self.configure
  self.configuration ||= Hypernova::Configuration.new
  yield(configuration)
end

.pluginsObject



31
32
33
# File 'lib/hypernova.rb', line 31

def self.plugins
  @plugins ||= []
end

.render_token(batch_token) ⇒ Object



27
28
29
# File 'lib/hypernova.rb', line 27

def self.render_token(batch_token)
  "__hypernova_render_token[#{batch_token}]__"
end

.replace_tokens_with_result(body, render_token_to_batch_token, batch_result) ⇒ Object

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

Parameters:

  • body (String)
  • render_token_to_batch_token (Hash)
  • respond_to (:[])

    batch_result



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/hypernova.rb', line 45

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) ⇒ Object

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



61
62
63
64
65
66
67
# File 'lib/hypernova.rb', line 61

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