I am parsing a file that exists in either app/components/ui
or in app/components
. If the one in the first dir (app/components/ui
) doesn't exist, then fallback to the app/components
directory. This is what I have currently.
def front_matter
return unless params[:filename].present?
path = Rails.root.join('app', 'components', 'ui', params[:filename])
path = Rails.root.join('app', 'components', params[:filename]) unless File.exist?(path)
@front_matter ||= FrontMatterParser::Parser.parse_file(path)
end
Is there a better way to write this?