Sha256: 9b44caa36841c18c97d087078a681836fd663aaef4eeb6f9e2ef10f4312fe0c6

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 KB

Contents

module Hypernova::PluginHelper
  def get_view_data(name, data)
    Hypernova.plugins.reduce(data) do |data, plugin|
      if plugin.respond_to?(:get_view_data)
        plugin.get_view_data(name, data)
      else
        data
      end
    end
  end

  def prepare_request(current_request, original_request)
    Hypernova.plugins.reduce(current_request) do |req, plugin|
      if plugin.respond_to?(:prepare_request)
        plugin.prepare_request(req, original_request)
      else
        req
      end
    end
  end

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

  def will_send_request(jobs_hash)
    Hypernova.plugins.each do |plugin|
      if plugin.respond_to?(:will_send_request)
        plugin.will_send_request(jobs_hash)
      end
    end
  end

  def after_response(current_response, original_response)
    Hypernova.plugins.reduce(current_response) do |response, plugin|
      if plugin.methods.include?(:after_response)
        plugin.after_response(response, original_response)
      else
        response
      end
    end
  end

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

  def on_success(res, jobs_hash)
    Hypernova.plugins.each do |plugin|
      plugin.on_success(res, jobs_hash) if plugin.respond_to?(:on_success)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hypernova-1.2.0 lib/hypernova/plugin_helper.rb
hypernova-1.1.0 lib/hypernova/plugin_helper.rb
hypernova-1.0.3 lib/hypernova/plugin_helper.rb
hypernova-1.0.2 lib/hypernova/plugin_helper.rb
hypernova-1.0.1 lib/hypernova/plugin_helper.rb
hypernova-1.0.0 lib/hypernova/plugin_helper.rb