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

Commit 4e28dd5

Browse files
committed
Use an array of jobs instead of hash
Enables support for rendering multiple components with the same name in one request
1 parent ce24970 commit 4e28dd5

4 files changed

Lines changed: 16 additions & 18 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class HypernovaPlugin
150150
# prepare_request allows you to alter the request object in any way that you
151151
# need.
152152
# Unless manipulated by another plugin, request takes the shape:
153-
# { 'component_name.js': { :name => 'component_name.js', :data => {} } }
153+
# [{ :name => 'component_name.js', :data => {} }, ...]
154154
def prepare_request(current_request, original_request)
155155
current_request.keys.each do |key|
156156
phrase_hash = req[key][:data][:phrases]

lib/hypernova/controller_helpers.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,15 @@ def hypernova_batch_after
7878
return if @hypernova_batch.empty?
7979

8080
jobs = @hypernova_batch.jobs
81-
hash = jobs.each_with_object({}) do |job, h|
82-
h[job[:name]] = job
83-
end
84-
hash = prepare_request(hash, hash)
85-
if send_request?(hash)
81+
jobs = prepare_request(jobs, jobs)
82+
83+
if send_request?(jobs)
8684
begin
87-
will_send_request(hash)
85+
will_send_request(jobs)
8886
result = @hypernova_batch.submit!
89-
on_success(result, hash)
87+
on_success(result, jobs)
9088
rescue StandardError => e
91-
on_error(e, nil, hash)
89+
on_error(e, nil, jobs)
9290
result = @hypernova_batch.submit_fallback!
9391
end
9492
else

lib/hypernova/plugin_helper.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ def prepare_request(current_request, original_request)
1919
end
2020
end
2121

22-
def send_request?(jobs_hash)
22+
def send_request?(jobs)
2323
Hypernova.plugins.all? do |plugin|
2424
if plugin.respond_to?(:send_request?)
25-
plugin.send_request?(jobs_hash)
25+
plugin.send_request?(jobs)
2626
else
2727
true
2828
end
2929
end
3030
end
3131

32-
def will_send_request(jobs_hash)
32+
def will_send_request(jobs)
3333
Hypernova.plugins.each do |plugin|
3434
if plugin.respond_to?(:will_send_request)
35-
plugin.will_send_request(jobs_hash)
35+
plugin.will_send_request(jobs)
3636
end
3737
end
3838
end
@@ -47,13 +47,13 @@ def after_response(current_response, original_response)
4747
end
4848
end
4949

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

54-
def on_success(res, jobs_hash)
54+
def on_success(res, jobs)
5555
Hypernova.plugins.each do |plugin|
56-
plugin.on_success(res, jobs_hash) if plugin.respond_to?(:on_success)
56+
plugin.on_success(res, jobs) if plugin.respond_to?(:on_success)
5757
end
5858
end
5959
end

lib/hypernova/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Hypernova
2-
VERSION = "1.4.0"
2+
VERSION = "2.0.0"
33
end

0 commit comments

Comments
 (0)