Sha256: 578736273717dacedbce69811fce1ded9499d6a09ddafc8f6f147d172900e112
Contents?: true
Size: 1.52 KB
Versions: 13
Compression:
Stored size: 1.52 KB
Contents
module Actions module Middleware class KeepCurrentTaxonomies < Dynflow::Middleware def delay(*args) pass(*args).tap { store_current_taxonomies } end def plan(*args) with_current_taxonomies do pass(*args).tap { store_current_taxonomies } end end def run(*args) restore_current_taxonomies { pass(*args) } end def finalize restore_current_taxonomies { pass } end def hook(*args) restore_current_taxonomies { pass(*args) } end private def with_current_taxonomies if current_taxonomies? yield else restore_current_taxonomies { yield } end end def store_current_taxonomies action.input[:current_organization_id] = Organization.current.try(:id) action.input[:current_location_id] = Location.current.try(:id) end def restore_current_taxonomies Organization.current = Organization.unscoped.find(action.input[:current_organization_id]) if action.input[:current_organization_id].present? Location.current = Location.unscoped.find(action.input[:current_location_id]) if action.input[:current_location_id].present? yield ensure Organization.current = nil Location.current = nil end def current_taxonomies? (Organization.current || action.input[:current_organization_id].nil?) && (Location.current || action.input[:current_location_id].nil?) end end end end
Version data entries
13 entries across 13 versions & 1 rubygems