Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
2caa81f
add MY_README.md, add project proposal, and user stories
Jul 27, 2026
1c497d0
Replace README boilerplate with MealTracker app proposal
Jul 27, 2026
6f0f9d5
Merge pull request #1 from dcina023/update-readmes
dcina023 Jul 27, 2026
86bb366
Add Faker gem for seed data
Jul 27, 2026
16bebe1
Add models, associations, and migrations
Jul 27, 2026
ef5c2ff
Use Faker to create mock seed data
Jul 27, 2026
dce8934
Merge pull request #2 from dcina023/setup/custom-layout
dcina023 Jul 27, 2026
b26ab78
Add User meal plan and meal helper methods
Jul 27, 2026
fa0ba5b
Add User meal plan and meal helper methods
Jul 27, 2026
c7fab08
Merge branch 'user-model-methods' of github.com:dcina023/phase-3-ruby…
Jul 27, 2026
934b390
Clean Up User model methods
Jul 27, 2026
a7e9b5b
Add CLI main menu
Jul 27, 2026
22eed25
Add CLI main menu and view users feature
Jul 27, 2026
dd8e5a7
Add select user feature and remove unused User model methods
Jul 27, 2026
c81966a
Merge pull request #3 from dcina023/user-model-methods
dcina023 Jul 28, 2026
73fec49
Add menu options for features
Jul 28, 2026
f558dd7
Add user mealplans when user selects user
Jul 28, 2026
62f7116
Add option to list individual meals in user mealplans
Jul 28, 2026
940ce35
Merge pull request #4 from dcina023/feature-2
dcina023 Jul 28, 2026
3f604da
separated logic in select_user for select_mealplan functionality and …
Jul 28, 2026
455364b
add tty-prompt gem, initialize @prompt variable to use gem functional…
Jul 28, 2026
f5d026b
Merge pull request #5 from dcina023/feature-3
dcina023 Jul 28, 2026
2f7272c
add delete_mealplan method
Jul 28, 2026
1080d28
Merge pull request #6 from dcina023/feature-4
dcina023 Jul 28, 2026
3d4e31c
add update_meal method reusing same logic for update_mealplan
Jul 28, 2026
e96a557
fix PR for feature-5
Jul 28, 2026
94ddcda
Merge pull request #7 from dcina023/feature-5
dcina023 Jul 28, 2026
aa4bbb1
refactor methods to fix menu navigation flow, and add delete_meal met…
Jul 28, 2026
ccecb3c
Merge pull request #8 from dcina023/feature-6
dcina023 Jul 28, 2026
249c637
add menu-selections to support future functionality for adding new us…
Jul 28, 2026
c0a3aae
Create add_user method to add new users into db
Jul 28, 2026
0b348d4
Create add_new_meal_plan method for users
Jul 28, 2026
51d395b
Create add_new_meal method for users to add to meal_plans
Jul 28, 2026
4902296
Merge pull request #9 from dcina023/feature-7
dcina023 Jul 28, 2026
e1bc875
Separate CLI methods into organized files
Jul 28, 2026
00e2228
Merge pull request #10 from dcina023/refactor-1
dcina023 Jul 28, 2026
343bb2d
Add user submenu with meal plan budget summaries
Jul 28, 2026
69fff56
Merge pull request #11 from dcina023/custom-model-methods
dcina023 Jul 28, 2026
57884f6
git commit -m "Refactor CLI menu flow with submenus
Jul 29, 2026
c2f5012
Apply CLI input helpers and add delete user flow
Jul 29, 2026
0a26e49
Merge pull request #12 from dcina023/refactor-CLI-flow
dcina023 Jul 29, 2026
937164a
Add budget check for meal cost
Jul 29, 2026
35f6b33
Merge pull request #13 from dcina023/budget-logic
dcina023 Jul 29, 2026
12a591d
Add ensure block and refactor user menu helpers
Jul 30, 2026
0a91d6a
Refactor meal menu display logic
Jul 30, 2026
6ec5041
Clean up unused business logic in User model
Jul 30, 2026
a12698b
Merge pull request #14 from dcina023/refactor-2
dcina023 Jul 30, 2026
e43160e
Add user stores and CLI usage README
Jul 30, 2026
a6b8b52
fix markdown formatting in user stories
Jul 30, 2026
b0f2d44
fit line 32 in meal_plan_menu
Jul 30, 2026
d20164e
clean up meal plan display and back navigation
Jul 30, 2026
3b1f861
Merge pull request #15 from dcina023/refactor-3
dcina023 Jul 30, 2026
e746ca6
Fix Faker seed data to follow budget rules
Jul 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ gem "require_all", "~> 3.0"

gem "standalone_migrations"

gem "tty-prompt"

gem "tty-font"

gem "pastel"

# Generate mock data for database seeds
gem "faker"

# These gems will only be used when we are running the application locally
group :development do
gem "pry", "~> 0.14.1"
Expand Down
20 changes: 20 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ GEM
drb (2.2.3)
erb (6.0.6)
erubi (1.13.1)
faker (3.8.0)
i18n (>= 1.8.11, < 2)
i18n (1.15.2)
concurrent-ruby (~> 1.0)
io-console (0.8.2)
Expand Down Expand Up @@ -95,6 +97,8 @@ GEM
parser (3.3.11.1)
ast (~> 2.4.1)
racc
pastel (0.8.0)
tty-color (~> 0.5)
pp (0.6.4)
prettyprint
prettyprint (0.2.0)
Expand Down Expand Up @@ -187,12 +191,24 @@ GEM
thor (1.5.0)
timeout (0.6.1)
tsort (0.2.0)
tty-color (0.6.0)
tty-cursor (0.7.1)
tty-font (0.5.0)
tty-prompt (0.23.1)
pastel (~> 0.8)
tty-reader (~> 0.8)
tty-reader (0.9.0)
tty-cursor (~> 0.7)
tty-screen (~> 0.8)
wisper (~> 2.0)
tty-screen (0.8.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.2.0)
useragent (0.16.11)
wisper (2.0.1)
zeitwerk (2.8.2)

PLATFORMS
Expand All @@ -206,13 +222,17 @@ PLATFORMS
DEPENDENCIES
activerecord (~> 7.1)
database_cleaner (~> 2.0)
faker
pastel
pry (~> 0.14.1)
rake (~> 13.0)
require_all (~> 3.0)
rspec (~> 3.10)
rubocop
sqlite3 (~> 1.7)
standalone_migrations
tty-font
tty-prompt

BUNDLED WITH
2.7.2
173 changes: 40 additions & 133 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,165 +1,72 @@
# Phase 3 Project — Single-Script Active Record CLI
# Meal Prep Tracker

## Learning Goals

- Build a database-backed Ruby application using Active Record
- Design and interact with data models using object-oriented Ruby
- Implement a multi-class CLI frontend
- Practice working with migrations, associations, and validations

## Introduction

Congrats on getting through all the material for Phase 3! You've learned how to work with databases, design models with Active Record, and write object-oriented Ruby. Now it's time to bring those skills together into a full project.

This project will focus on building a Ruby command-line application that reads from and writes to a local SQLite3 database using Active Record — no web server required.

By the end of the project, you'll have a functioning CLI that lets users interact with your data by creating, viewing, updating, and deleting records from the terminal.
Meal Prep Tracker is a Ruby CLI application built with ActiveRecord and SQLite3. The app allows users to create and manage meal plans, add meals to meal plans, update meal information, delete records, and view meal plan budget summaries from the terminal.

## Requirements

### Models

- At least two model classes using `ActiveRecord::Base`
- A one-to-many relationship (`has_many` / `belongs_to`)
- At least one model with validations
- Display associated data where appropriate (e.g. listing a parent record's associated children)

### CLI

- At least two Ruby classes (e.g. a `Menu` class and a model-specific helper)
- A loop or menu interface
- Ability to create, view, update, and delete records
- Update prompts should display the current value before asking for a new one

## Planning

- Plan out your features
- Develop user stories
- "As [ a user ], I want [ to perform this action ] so that [ I can accomplish this goal ]."
- Features should not need you there to explain them to users
- Create a `user-stories.md` file and add your user stories there

## Project Pitches

Before you start working on your project, you'll pitch your project idea to your instructors for approval and feedback.

For your project pitch, you should include:

- The basic story of your application
- The core features of your MVP
- The data you plan to persist and how you will structure it
- Challenges you expect to face
- How you are meeting the requirements of the project

**MVP ASAP** — Focus on getting your minimum viable product working first!

## Example Project Domains

You could build a **Book Tracker** app:

- `Author` has many `Books`
- Users can:
- Create a new book
- List all books
- Update book details
- Delete a book
- View books by a specific author

Or a **Workout Log**:
Before running the application, make sure you have:

- `WorkoutSession` has many `Exercises`
- Users can:
- Log a new workout
- Add exercises
- Update reps/weights
- View or delete past workouts
- Ruby installed
- Bundler installed
- SQLite3 installed

## Getting Started
## Installation

**Fork and clone** this repository to get started.
Clone the repository from GitHub:

Install dependencies:
git clone <your-repo-url>

```bash
bundle install
```
Move into the project directory:

Create and migrate the database:
cd <repo-folder-name>

```bash
bundle exec rake db:create
bundle exec rake db:migrate
```
Install the project dependencies:

Optionally seed the database with starter data:
bundle install

```bash
bundle exec rake seed
```
## Database Setup

Run your CLI application:
Create the database:

```bash
ruby cli/main.rb
```
bundle exec rake db:create

## Other Useful Commands
Run the migrations to create the database tables:

Open a Pry console with your models loaded:
bundle exec rake db:migrate

```bash
bundle exec rake console
```
Seed the database with sample data:

Generate a new migration:
bundle exec rake seed

```bash
bundle exec rake db:create_migration NAME=create_books
```
## Running the Application

## Project Structure
Start the CLI from the project root:

```
├── app/
│ └── models/ # Your Active Record model classes go here
├── cli/
│ └── main.rb # Entry point — your CLI menu lives here
├── config/
│ └── environment.rb # Loads gems, DB connection, and models
├── db/
│ ├── config.yml # Database connection settings
│ ├── migrate/ # Migration files
│ └── seeds.rb # Seed data
└── spec/ # RSpec tests (optional)
```
ruby cli/cli.rb

## Project Tips
## Useful Development Commands

- Sketch your domain model first using [dbdiagram.io](https://dbdiagram.io/)
- Use `bundle exec rake console` to test your models before building the CLI
- Use `binding.pry` for debugging
- Use `puts` and `pp` or gems like `tty-table` for formatted CLI output
Open a Pry console with the application environment loaded:

## Sample Project
bundle exec rake console

A complete implementation is available on the `sample-project` branch. It demonstrates:
Create a new migration:

- **Pet Tracker** domain with Owners and Pets
- Full CRUD with Active Record and a clean menu-driven CLI
- Object-oriented design with user-friendly output
- All required features including current value prompts for updates
bundle exec rake db:new_migration name=migration_name

To view the sample:
Example:

```bash
git checkout sample-project
```
bundle exec rake db:new_migration name=create_users

See `SAMPLE_PROJECT_README.md` for detailed documentation.
## Main Features

## Resources
The CLI supports:

- [dbdiagram.io](https://dbdiagram.io/)
- [Active Record Basics](https://guides.rubyonrails.org/active_record_basics.html)
- [Active Record Associations](https://guides.rubyonrails.org/association_basics.html)
- [Active Record Validations](https://guides.rubyonrails.org/active_record_validations.html)
- Viewing users
- Selecting a user
- Adding and deleting users
- Viewing a user’s meal plans and meals
- Adding, updating, and deleting meal plans
- Adding, updating, and deleting meals
- Viewing meal plan budget summaries
- Preventing meals from exceeding a meal plan’s budget
3 changes: 3 additions & 0 deletions app/models/meal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Meal < ActiveRecord:: Base
belongs_to :meal_plan
end
21 changes: 21 additions & 0 deletions app/models/meal_plan.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class MealPlan < ActiveRecord::Base
belongs_to :user
has_many :meals

def total_estimated_cost
meals.sum(:estimated_cost).to_f
end

def remaining_budget
budget.to_f - total_estimated_cost
end

def within_budget?(estimated_cost)
remaining_budget >= estimated_cost.to_f
end

def can_update_meal_cost?(meal, new_cost)
adjusted_total = total_estimated_cost - meal.estimated_cost.to_f + new_cost.to_f
adjusted_total <= budget.to_f
end
end
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class User < ActiveRecord::Base
has_many :meal_plans
has_many :meals, through: :meal_plans
end
57 changes: 57 additions & 0 deletions cli/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env ruby
require_relative "../config/environment"
require_relative "input_helpers"
require_relative "user_menu"
require_relative "meal_plan_menu"
require_relative "meal_menu"
require "tty-prompt"
require "tty-font"
require "pastel"

class CLI
def initialize
@prompt = TTY::Prompt.new
@font = TTY::Font.new(:standard)
@pastel = Pastel.new
end

def run

print "\e[H\e[2J"
puts @pastel.green(@font.write("Meal Prep Tracker"))

main_menu
ensure
ActiveRecord::Base.connection_pool.disconnect! if ActiveRecord::Base.connected?
end

def main_menu
loop do
puts @pastel.dim("—" * 50)
choice = @prompt.select("Main Menu", [
{ name: "View users", value: :view_users },
{ name: "Select user", value: :select_user },
{ name: "Add user", value: :add_user },
{ name: "Delete user", value: :delete_user },
{ name: "Exit", value: :exit },
])

case choice
when :view_users
list_users
when :select_user
user = select_user
user_menu(user) if user
when :add_user
add_new_user
when :delete_user
delete_user
when :exit
puts @pastel.blue(@font.write("Thank you!"))
break
end
end
end
end

CLI.new.run
Loading