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 =
"1.0.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



14
15
16
# File 'lib/hypernova.rb', line 14

def configuration
  @configuration
end

Class Method Details

.add_plugin!(plugin) ⇒ Object



33
34
35
# File 'lib/hypernova.rb', line 33

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

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

Yields:



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

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

.pluginsObject



29
30
31
# File 'lib/hypernova.rb', line 29

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

.render_token(batch_token) ⇒ Object



25
26
27
# 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) ⇒ 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



43
44
45
46
47
48
49
50
51
52
53
54
55
# 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) ⇒ Object

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



59
60
61
62
63
64
65
# 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