Sha256: 8c3f3bc99de361c02564b54077aebbd9749ae7d9e5944a9009a798ca857a9903

Contents?: true

Size: 677 Bytes

Versions: 2

Compression:

Stored size: 677 Bytes

Contents

require "soar_flow/version"
require 'rack'
require 'securerandom'

module SoarFlow
  class ID
    attr_reader :app

    def initialize(app)
      @app = app
    end

    def call(env)
      request = Rack::Request.new(env)
      request = generate_or_honor_flow_id(request)
      request.update_param('flow_identifier', request.params['flow_identifier'])
      @app.call(env)
    end

    def self.generate_flow_id
      "#{SecureRandom.hex(32)}"
    end

    private

    def generate_or_honor_flow_id(request)
      if request.params['flow_identifier'].nil?
        request.params['flow_identifier'] = SoarFlow::ID::generate_flow_id
      end
      request
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
soar_flow-0.1.1 lib/soar_flow.rb
soar_flow-0.1.0 lib/soar_flow.rb