Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Use an array of jobs instead of hash
Browse files Browse the repository at this point in the history
Enables support for rendering multiple components with the same name in one request
  • Loading branch information
dpuscher committed Dec 11, 2019
1 parent ce24970 commit 4e28dd5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class HypernovaPlugin
# prepare_request allows you to alter the request object in any way that you
# need.
# Unless manipulated by another plugin, request takes the shape:
# { 'component_name.js': { :name => 'component_name.js', :data => {} } }
# [{ :name => 'component_name.js', :data => {} }, ...]
def prepare_request(current_request, original_request)
current_request.keys.each do |key|
phrase_hash = req[key][:data][:phrases]
Expand Down
14 changes: 6 additions & 8 deletions lib/hypernova/controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,15 @@ def hypernova_batch_after
return if @hypernova_batch.empty?

jobs = @hypernova_batch.jobs
hash = jobs.each_with_object({}) do |job, h|
h[job[:name]] = job
end
hash = prepare_request(hash, hash)
if send_request?(hash)
jobs = prepare_request(jobs, jobs)

if send_request?(jobs)
begin
will_send_request(hash)
will_send_request(jobs)
result = @hypernova_batch.submit!
on_success(result, hash)
on_success(result, jobs)
rescue StandardError => e
on_error(e, nil, hash)
on_error(e, nil, jobs)
result = @hypernova_batch.submit_fallback!
end
else
Expand Down
16 changes: 8 additions & 8 deletions lib/hypernova/plugin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ def prepare_request(current_request, original_request)
end
end

def send_request?(jobs_hash)
def send_request?(jobs)
Hypernova.plugins.all? do |plugin|
if plugin.respond_to?(:send_request?)
plugin.send_request?(jobs_hash)
plugin.send_request?(jobs)
else
true
end
end
end

def will_send_request(jobs_hash)
def will_send_request(jobs)
Hypernova.plugins.each do |plugin|
if plugin.respond_to?(:will_send_request)
plugin.will_send_request(jobs_hash)
plugin.will_send_request(jobs)
end
end
end
Expand All @@ -47,13 +47,13 @@ def after_response(current_response, original_response)
end
end

def on_error(error, job = nil, jobs_hash = nil)
Hypernova.plugins.each { |plugin| plugin.on_error(error, job, jobs_hash) if plugin.respond_to?(:on_error) }
def on_error(error, job = nil, jobs = nil)
Hypernova.plugins.each { |plugin| plugin.on_error(error, job, jobs) if plugin.respond_to?(:on_error) }
end

def on_success(res, jobs_hash)
def on_success(res, jobs)
Hypernova.plugins.each do |plugin|
plugin.on_success(res, jobs_hash) if plugin.respond_to?(:on_success)
plugin.on_success(res, jobs) if plugin.respond_to?(:on_success)
end
end
end
2 changes: 1 addition & 1 deletion lib/hypernova/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Hypernova
VERSION = "1.4.0"
VERSION = "2.0.0"
end

0 comments on commit 4e28dd5

Please sign in to comment.