Skip to content

Instantly share code, notes, and snippets.

@equivalent
Last active August 21, 2020 10:06
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 equivalent/06f752d99b0d438759e3de22dbd2e9bd to your computer and use it in GitHub Desktop.
Save equivalent/06f752d99b0d438759e3de22dbd2e9bd to your computer and use it in GitHub Desktop.
Ruby on Rails - Bounded contexts via interface objects - interface objects example 1
teacher = Teacher.find(567)
student = Student.find(123)
student = Student.find(654)
# Lesson creation
lesson = teacher.classroom.create_lesson(students: [student1, student2], title: "Battle of Kursk")
# Student uploads Work file
some_file = File.open('/tmp/some_file.doc')
lesson.classroom.upload_work(student: student1, file: some_file)
# publish lesson
lesson.classroom.publish
# post comment to work
work = Work.find(468)
work.public_board.post_comment(student: student2, title: "Great work mate!")
# Student marks lesson as favorite
lesson.public_board.mark_as_favorite(current_user: student1)