-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e5f1cfa
Showing
9 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# A sample Gemfile | ||
source "https://rubygems.org" | ||
|
||
# gem "rails" | ||
gem 'pry-byebug' | ||
gem 'require_all' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
byebug (8.2.2) | ||
coderay (1.1.1) | ||
method_source (0.8.2) | ||
pry (0.10.3) | ||
coderay (~> 1.1.0) | ||
method_source (~> 0.8.1) | ||
slop (~> 3.4) | ||
pry-byebug (3.3.0) | ||
byebug (~> 8.0) | ||
pry (~> 0.10) | ||
require_all (1.3.3) | ||
slop (3.6.0) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
pry-byebug | ||
require_all | ||
|
||
BUNDLED WITH | ||
1.10.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Object Relations Assessment | ||
|
||
For this assignment, we'll be working with a Yelp-style domain. We have three models - Restaurant, Customer, and Review. | ||
For our purposes, a Restaurant has many reviews, a Customer has many reviews, and Restaurant - Customer is a many to many relationship. | ||
|
||
If you are not sketching out your domain, and thinking about single source of truth, | ||
you are doing it wrong :( | ||
|
||
## Topics | ||
|
||
+ Classes vs Instances | ||
+ Variable Scope ( Class, Instance, Local ) | ||
+ Object Relationships | ||
+ Arrays and Array Methods | ||
+ Class Methods | ||
|
||
## Instructions | ||
|
||
Build the following methods on the customer class | ||
+ Customer.all | ||
+ should return all of the customers | ||
+ Customer.find_by_name(name) | ||
+ given a string of a full name, returns the first customer whose full name matches | ||
+ Customer.find_all_by_first_name(name) | ||
+ given a string of a first name, returns an array containing all customers with that first name | ||
+ Customer#add_review | ||
+ given some content and a restaurant, creates a new review and associates it with that customer and that restaurant | ||
|
||
Build out the following methods on the Review class | ||
|
||
+ Review.all | ||
+ returns all of the reviews | ||
+ Review#customer | ||
+ returns the customer for that given review | ||
+ Review#restaurant | ||
+ returns the restaurant for that given review | ||
|
||
Build out the following methods on the restaurant class | ||
|
||
+ Restaurant.all | ||
+ returns an array of all restaurants | ||
+ Restaurant.find_by_name(name) | ||
+ given a string of restaurant name, returns the first restaurant that matches | ||
+ Restaurant#reviews | ||
+ returns an array of all reviews for that restaurant | ||
+ Restaurant#customers | ||
+ should return all of the customers who have written reviews of that restaurant. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Customer | ||
attr_accessor :first_name, :last_name | ||
|
||
@@all = [] | ||
|
||
def self.all | ||
@@all | ||
end | ||
|
||
def initialize(name) | ||
@name = name | ||
@@all << self | ||
end | ||
|
||
def full_name | ||
"#{first_name} #{last_name}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Restaurant | ||
attr_accessor :name | ||
|
||
@@all = [] | ||
|
||
def initialize(name) | ||
self.name=(name) | ||
@@all << self | ||
@reviews = [] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Review | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'bundler/setup' | ||
Bundler.require | ||
require_all 'app' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# We want to add the following methods to each of the classes | ||
# An all method, where each object is added upon initialization of the object | ||
# A find_by_name method for both the customer and the restaurant | ||
|
||
|
||
# If you are not sketching out your domain, and thinking about single source of truth, | ||
# you are doing it wrong :( | ||
|
||
# Build the following methods on the customer class | ||
# Customer.all | ||
# should return all of the customers | ||
# Customer.find_by_name(name) | ||
# given a string of a full name, returns the first customer whose full name matches | ||
# Customer.find_all_by_first_name(name) | ||
# # given a string of a first name, returns an array containing all customers with that first name | ||
# Customer#add_review | ||
# given some content and a restaurant, creates a new review and associates it with that customer and that restaurant | ||
|
||
# Review.all | ||
# returns all of the reviews | ||
# Review#customer | ||
# returns the customer for that given review | ||
# Review#restaurant | ||
# returns the restaurant for that given review | ||
|
||
# Restaurant.all | ||
# returns an array of all restaurants | ||
# Restaurant.find_by_name(name) | ||
# given a string of restaurant name, returns the first restaurant that matches | ||
# Restaurant#reviews | ||
# returns an array of all reviews for that restaurant | ||
# Restaurant#customers | ||
# should return all of the customers who have written reviews of that restaurant. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require_relative '../config/environment.rb' | ||
|
||
def reload | ||
load 'config/environment.rb' | ||
end | ||
|
||
Pry.start |