Module: Nexaas::Async::Collector::ApplicationHelper

Defined in:
app/helpers/nexaas/async/collector/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#nexaas_async_collect(opts = {}) ⇒ Object

Helper to enqueue AsyncResourceJob and include the JavaScript code to request the result

  • scope_id: an ID that is unique (maybe user.id, account.id, organization.id, etc)

  • klass_name: The name of the class responsible for generate the content to be stored in the memory

  • klass_method: The name of the class method to be called

  • args: The arguments to be passed in the call of the class method

  • instrumentation_context: Custom context for instrumentatio with ActiveSupport::Notifications

  • file: Argument to pass file informations. This will be used to generated file for the user

    • conten_type: Content type of the file

    • name: Basename of the file to be generated

Example: <%= nexaas_async_collect({

scope_id: current_user.id, class_name: ReportGenerator,
class_method: :generate, args: [],
file: { content_type: 'application/json', name: 'data' }

}) %>



24
25
26
27
28
29
30
31
# File 'app/helpers/nexaas/async/collector/application_helper.rb', line 24

def nexaas_async_collect(opts={})
  async_resource = Nexaas::Async::Collector::AsyncResource.new(opts)
  async_resource.save!
  render(partial: 'nexaas/async/collector/async_resource/show', locals: {
    unique_id: SecureRandom.hex,
    collect_id: async_resource.collect_id
  })
end

#nexaas_async_collectorObject

Rails 4.x does not add this helper automatically as Rails 5.X and 3.X does. So we had to created it to keep the same interface.



35
36
37
# File 'app/helpers/nexaas/async/collector/application_helper.rb', line 35

def nexaas_async_collector
  @@nexaas_async_collector ||= Nexaas::Async::Collector::Engine.routes.url_helpers
end