Skip to content

Instantly share code, notes, and snippets.

@kstevens715
Last active May 2, 2017 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kstevens715/48b48470b6719b6fea7f25b9c54c409e to your computer and use it in GitHub Desktop.
Save kstevens715/48b48470b6719b6fea7f25b9c54c409e to your computer and use it in GitHub Desktop.
module Documents
class Loader
def initialize(current_user_identity, current_organization, applicant, programs)
@current_user_identity = current_user_identity
@current_organization = current_organization
@applicant = applicant
@programs = programs
@panels = {}
end
def load(sub_panel=:documents)
sub_panel = sub_panel.to_sym
@panels[sub_panel] ||= load_for_real(sub_panel)
end
private
attr_reader :applicant, :current_user_identity, :current_organization, :programs
def load_for_real(subpanel)
if sub_panel.to_sym == :admissions_uploaded_documents
if feature?('applicant_attachments')
applicant.attachments.
by_organization(current_organization).
order("applicant_attachments.created_at DESC")
end
else
Documents::DocumentType.current_user_identity = current_user_identity
documents = ::Documents.for_applicant_in_programs(applicant, programs, sub_panel.to_sym) || []
documents.sort_by { |document| document.title }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment