CSC/ECE 517 Spring 2024 - E2418. Reimplement of due date.rb: Difference between revisions
No edit summary |
No edit summary |
||
Line 56: | Line 56: | ||
== Improvements in the New Implementation of DueDate Class == | == Improvements in the New Implementation of DueDate Class == | ||
=== Renamed methods to describe their responsibility === | === Renamed methods to describe their responsibility === | ||
Line 70: | Line 72: | ||
[[File:DueDateRename5.png|1000px|thumb|none|]] | [[File:DueDateRename5.png|1000px|thumb|none|]] | ||
=== Refactored each method according to DRY, SRP, and other Ruby conventions === | === Refactored each method according to DRY, SRP, and other Ruby conventions === | ||
Line 82: | Line 86: | ||
[[File:DueDateRuby4.png|1000px|thumb|none|]] | [[File:DueDateRuby4.png|1000px|thumb|none|]] | ||
=== Utilized Rails built-in APIs for tasks such as validation, scoping, and database access === | === Utilized Rails built-in APIs for tasks such as validation, scoping, and database access === | ||
Line 88: | Line 95: | ||
[[File:DueDateRails2.png|1000px|thumb|none|]] | [[File:DueDateRails2.png|1000px|thumb|none|]] | ||
Revision as of 22:18, 23 March 2024
E2368. Reimplement due_date.rb
This page provides a description of the Expertiza based OSS project.
About Expertiza
Expertiza is an open source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.
Project Changes
In this project, the following specific changes were implemented:
- Renamed methods and variables to accurately describe their responsibilities.
- Refactored each method to comply with DRY (Don't Repeat Yourself), SRP (Single Responsibility Principle), and other Ruby conventions.
- Overrode the comparator operator for the DueDate class and replace the `deadline_sort` class method.
- Utilized Rails built-in APIs for tasks such as validation, scoping, and database access.
- Conducted code smell checks using Code Climate
These changes aimed to enhance code quality, organization, and adherence to best practices in the Expertiza project.
Current Implementation of DueDate Class
The current implementation of the `DueDate` class can be summarized in a few key points:
Validation of Due Date Format
The class includes a validation method due_at_is_valid_datetime to ensure that the due date is in a valid datetime format. It checks if the due_at attribute is present and attempts to parse it using DateTime.strptime. If parsing fails and raises an ArgumentError, the method adds an error to the due_at attribute indicating that it must be a valid datetime.
Default Permission Handling
The class provides a default_permission method, which retrieves the default permission for a given deadline type and permission type. It accesses the DEFAULT_PERMISSION constant defined in the DeadlineRight module and returns the corresponding permission value.
Current Due Date Retrieval
It offers functionality through the current_due_date method to retrieve the current due date from a list of due dates. This method iterates over the provided due dates and checks if any due date lies in the future compared to the current time. It returns the first future due date encountered, indicating the current due date.
Flag Setting
It includes a set_flag method to set the flag attribute to true for a DueDate instance. This method updates the flag attribute and saves the record to the database.
Due Date Copying
The class implements functionality to copy due dates from one assignment to another using the copy method. It retrieves due dates associated with a given assignment ID, duplicates each due date record, assigns the new parent ID, and saves the duplicated records for the new assignment.
Due Date Setting
Provides a set_duedate method to set due dates for assignments with specified parameters. It creates a new DueDate instance with the provided parameters, including the deadline type, parent assignment ID, round, and saves the record to the database.
Sorting of Due Dates
Implements a method deadline_sort to sort due dates based on the due date attribute. This method sorts the provided list of due dates in ascending order of their due dates, ensuring that due dates without due_at values are placed at the end.
Assignment Round Calculation
Calculates the round of the response within an assignment based on due dates using the done_in_assignment_round method. It retrieves due dates associated with the given assignment ID, sorts them by due date, and iterates over them to determine the round based on the response's creation time.
Next Due Date Retrieval
Offers functionality through the get_next_due_date method to retrieve the next due date for an assignment or topic. Depending on whether the assignment has staggered deadlines, it queries either AssignmentDueDate or TopicDueDate records and returns the next due date after the current time.
The DueDate class in the Expertiza project serves as a pivotal component responsible for managing, validating, and retrieving due dates associated with assignments, encompassing functionalities such as validation of datetime formats, permission handling, and determining the current and next due dates for assignments and topics.
Improvements in the New Implementation of DueDate Class
Renamed methods to describe their responsibility
- Problem: Method names might not have accurately described their functionality, leading to confusion for developers.
- Solution: Method renaming with descriptive names clarified their purpose, improving code readability and comprehension for developers to understand method functionalities without deep code inspection.
![](/images/1/10/DueDateRename1.png)
![](/images/7/74/DueDateRename2.png)
![](/images/2/2b/DueDateRename3.png)
![](/images/7/70/DueDateRename4.png)
![](/images/e/e8/DueDateRename5.png)
Refactored each method according to DRY, SRP, and other Ruby conventions
- Problem: Methods were potentially repetitive, non-optimized, or didn't adhere to best practices, causing inefficiencies and confusion.
- Solution: Method refactoring according to DRY, SRP, and Ruby conventions optimized the code for clarity, efficiency, and maintainability, ensuring each method has a clear purpose and follows standard practices.
![](/images/5/5d/DueDateRuby1.png)
![](/images/f/fa/DueDateRuby2.png)
![](/images/7/77/DueDateRuby3.png)
![](/images/4/48/DueDateRuby4.png)
Utilized Rails built-in APIs for tasks such as validation, scoping, and database access
![](/images/7/7e/DueDateRails1.png)
![](/images/3/37/DueDateRails2.png)
Overrode the comparator operator for the DueDate class and replaced the `deadline_sort` class method
- Problem: Existing code had a dedicated method for sorting due dates, which violated Ruby conventions.
- Solution: Overrode the <=> operator and defined a new function for sorting due_dates and called that instead.
![](/images/7/73/DueDateOverride1.png)
![](/images/d/d1/DueDateOverride2.png)
![](/images/8/8b/DueDateOverride3.png)
Test Plan for DueDateHelper Specs
The following outlines the scenarios and cases to be tested for the DueDateHelper functionality within the system.
References
- Expertiza on GitHub
- GitHub Project Repository Fork
- The live Expertiza website
- Expertiza project documentation wiki
- Rspec Documentation
- Clean Code: A handbook of agile software craftsmanship. Author: Robert C Martin