Sha256: e7f1a9c91c7c61146169aac2a54e409ff7d4c3236115e59378b29f573b454b3b
Contents?: true
Size: 970 Bytes
Versions: 2
Compression:
Stored size: 970 Bytes
Contents
module Trice module ControllerMethods class ReferenceTimeAssignment QUERY_STUB_KEY = '_requested_at'.freeze HEADER_STUB_KEY = 'X-REQUESTED-AT'.freeze def initialize(config) @stub_configuration = config end def around(controller, &action) t = determine_requested_at(controller) controller.request.env['trice.reference_time'] = t Trice.with_reference_time(t, &action) end private def determine_requested_at(controller) if @stub_configuration.stubbable?(controller) extract_requested_at(controller.request) || Time.now else Time.now end end def extract_requested_at(request) if request.params[QUERY_STUB_KEY] Time.zone.parse(request.params[QUERY_STUB_KEY]) elsif request.headers[HEADER_STUB_KEY] Time.zone.parse(request.headers[HEADER_STUB_KEY]) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
trice-0.1.1 | lib/trice/controller_methods/reference_time_assignment.rb |
trice-0.1.0 | lib/trice/controller_methods/reference_time_assignment.rb |