2015-12-15 09:51:16 -05:00
|
|
|
module Banzai
|
|
|
|
# Common methods for ReferenceFilters that support an optional cross-project
|
|
|
|
# reference.
|
|
|
|
module CrossProjectReference
|
|
|
|
# Given a cross-project reference string, get the Project record
|
|
|
|
#
|
|
|
|
# Defaults to value of `context[:project]` if:
|
|
|
|
# * No reference is given OR
|
|
|
|
# * Reference given doesn't exist
|
|
|
|
#
|
|
|
|
# ref - String reference.
|
|
|
|
#
|
|
|
|
# Returns a Project, or nil if the reference can't be found
|
2017-12-01 04:21:05 -05:00
|
|
|
def parent_from_ref(ref)
|
2015-12-15 09:51:16 -05:00
|
|
|
return context[:project] unless ref
|
|
|
|
|
2017-02-02 18:43:19 -05:00
|
|
|
Project.find_by_full_path(ref)
|
2015-12-15 09:51:16 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|