class Riddler::ContextDirector

Attributes

headers[R]
params[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/riddler/context_director.rb, line 6
def initialize options={}
  options = {} if options.nil?
  @params = options[:params] || options["params"]
  @headers = options[:headers] || options["headers"]
  @ctx = ::Riddler::Context.new params: params, headers: headers
  @ids_extracted = false
  @builders_applied = false
end

Public Instance Methods

context() click to toggle source

Create a new context and use registered builders to fill it in

# File lib/riddler/context_director.rb, line 22
def context
  extract_ids
  apply_builders
  @ctx
end
simple_context() click to toggle source

Return the context with only IDs extracted

# File lib/riddler/context_director.rb, line 16
def simple_context
  extract_ids
  @ctx
end

Private Instance Methods

apply_builders() click to toggle source
# File lib/riddler/context_director.rb, line 45
def apply_builders
  return if @builders_applied

  builders.each do |builder|
    unless builder.data_available?
      ::Riddler.logger.debug "data not available for builder", context_builder: builder.class.name
      next
    end
    ::Riddler.logger.debug "processing context builder", context_builder: builder.class.name
    builder.process
  end

  @builders_applied = true
end
builders() click to toggle source
# File lib/riddler/context_director.rb, line 60
def builders
  @builders ||= ::Riddler.configuration.context_builders.map do |builder_class|
    builder_class.new @ctx
  end
end
extract_ids() click to toggle source
# File lib/riddler/context_director.rb, line 30
def extract_ids
  return if @ids_extracted

  builders.each do |builder|
    unless builder.data_available?
      ::Riddler.logger.debug "data not available for builder", context_builder: builder.class.name
      next
    end
    ::Riddler.logger.debug "extracting ids", context_builder: builder.class.name
    builder.extract_ids
  end

  @ids_extracted = true
end