Skip to content

Homework 3 #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
/tmp
/log
/public
/lib/profilers/reports
.rspec
spec/spec_helper.rb
spec/rails_helper.rb
/fixtures
.env
28 changes: 28 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,39 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby file: '.ruby-version'

gem 'rails', '~> 8.0.1'
gem "sprockets-rails"
gem 'pg'
gem 'puma'
gem 'listen'
gem 'bootsnap'
gem 'rack-mini-profiler'

gem 'pry'
gem 'oj'
gem 'activerecord-import'

# PG
gem 'pghero'
gem "pg_query"

group :development, :test do
# ENV
gem "dotenv-rails", require: "dotenv/load", groups: %i[development test]

# RSpec
gem 'rspec-rails'
gem 'capybara'
gem 'selenium-webdriver'
gem 'webdrivers'

# Benchmarking
gem 'ruby-prof'
gem 'stackprof'
gem 'memory_profiler'
gem 'bullet'

gem 'annotaterb'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
98 changes: 98 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ GEM
activemodel (= 8.0.1)
activesupport (= 8.0.1)
timeout (>= 0.4.0)
activerecord-import (2.1.0)
activerecord (>= 4.2)
activestorage (8.0.1)
actionpack (= 8.0.1)
activejob (= 8.0.1)
Expand All @@ -72,21 +74,45 @@ GEM
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
annotaterb (4.14.0)
base64 (0.2.0)
benchmark (0.4.0)
bigdecimal (3.1.9)
bootsnap (1.18.4)
msgpack (~> 1.2)
builder (3.3.0)
bullet (8.0.1)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
capybara (3.40.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.11)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
coderay (1.1.3)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
crass (1.0.6)
date (3.4.1)
diff-lcs (1.6.0)
dotenv (3.1.7)
dotenv-rails (3.1.7)
dotenv (= 3.1.7)
railties (>= 6.1)
drb (2.2.1)
erubi (1.13.1)
ffi (1.17.1-arm64-darwin)
globalid (1.2.1)
activesupport (>= 6.1)
google-protobuf (4.29.3-arm64-darwin)
bigdecimal
rake (>= 13)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
io-console (0.8.0)
Expand All @@ -107,6 +133,9 @@ GEM
net-pop
net-smtp
marcel (1.0.4)
matrix (0.4.2)
memory_profiler (1.1.0)
method_source (1.1.0)
mini_mime (1.1.5)
minitest (5.25.4)
msgpack (1.8.0)
Expand All @@ -122,13 +151,25 @@ GEM
nio4r (2.7.4)
nokogiri (1.18.2-arm64-darwin)
racc (~> 1.4)
oj (3.16.9)
bigdecimal (>= 3.0)
ostruct (>= 0.2)
ostruct (0.6.1)
pg (1.5.9)
pg_query (6.0.0)
google-protobuf (>= 3.25.3)
pghero (3.6.1)
activerecord (>= 6.1)
pp (0.6.2)
prettyprint
prettyprint (0.2.0)
pry (0.15.2)
coderay (~> 1.1)
method_source (~> 1.0)
psych (5.2.3)
date
stringio
public_suffix (6.0.1)
puma (6.6.0)
nio4r (~> 2.0)
racc (1.8.1)
Expand Down Expand Up @@ -177,33 +218,90 @@ GEM
ffi (~> 1.0)
rdoc (6.12.0)
psych (>= 4.0.0)
regexp_parser (2.10.0)
reline (0.6.0)
io-console (~> 0.5)
rexml (3.4.1)
rspec-core (3.13.3)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (7.1.1)
actionpack (>= 7.0)
activesupport (>= 7.0)
railties (>= 7.0)
rspec-core (~> 3.13)
rspec-expectations (~> 3.13)
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.2)
ruby-prof (1.7.1)
rubyzip (2.4.1)
securerandom (0.4.1)
selenium-webdriver (4.10.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.5.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
stackprof (0.2.27)
stringio (3.1.2)
thor (1.3.2)
timeout (0.4.3)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uniform_notifier (1.16.0)
uri (1.0.2)
useragent (0.16.11)
webdrivers (5.3.1)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0, < 4.11)
websocket (1.2.11)
websocket-driver (0.7.7)
base64
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.7.1)

PLATFORMS
arm64-darwin-24

DEPENDENCIES
activerecord-import
annotaterb
bootsnap
bullet
capybara
dotenv-rails
listen
memory_profiler
oj
pg
pg_query
pghero
pry
puma
rack-mini-profiler
rails (~> 8.0.1)
rspec-rails
ruby-prof
selenium-webdriver
sprockets-rails
stackprof
tzinfo-data
webdrivers

RUBY VERSION
ruby 3.4.1p0
Expand Down
8 changes: 5 additions & 3 deletions app/controllers/trips_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class TripsController < ApplicationController
def index
@from = City.find_by_name!(params[:from])
@to = City.find_by_name!(params[:to])
@trips = Trip.where(from: @from, to: @to).order(:start_time)
@from = City.find_by!(name: params[:from])
@to = City.find_by!(name: params[:to])
@trips = Trip.eager_load(bus: :services).where(from: @from, to: @to).order(:start_time).to_a

@count = @trips.size
end
end
8 changes: 8 additions & 0 deletions app/models/bus.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# == Schema Information
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лайк за аннотации

#
# Table name: buses
#
# id :bigint not null, primary key
# model :string
# number :string
#
class Bus < ApplicationRecord
MODELS = [
'Икарус',
Expand Down
11 changes: 11 additions & 0 deletions app/models/city.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# == Schema Information
#
# Table name: cities
#
# id :bigint not null, primary key
# name :string
#
# Indexes
#
# index_cities_on_name (name) UNIQUE
#
class City < ApplicationRecord
validates :name, presence: true, uniqueness: true
validate :name_has_no_spaces
Expand Down
7 changes: 7 additions & 0 deletions app/models/service.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# == Schema Information
#
# Table name: services
#
# id :bigint not null, primary key
# name :string
#
class Service < ApplicationRecord
SERVICES = [
'WiFi',
Expand Down
18 changes: 17 additions & 1 deletion app/models/trip.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# == Schema Information
#
# Table name: trips
#
# id :bigint not null, primary key
# duration_minutes :integer
# price_cents :integer
# start_time :string
# bus_id :integer
# from_id :integer
# to_id :integer
#
# Indexes
#
# index_trips_on_from_id_and_to_id (from_id,to_id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лайк за составной индекс

#
class Trip < ApplicationRecord
HHMM_REGEXP = /([0-1][0-9]|[2][0-3]):[0-5][0-9]/

Expand Down Expand Up @@ -25,7 +41,7 @@ def to_h
bus: {
number: bus.number,
model: bus.model,
services: bus.services.map(&:name),
services: bus.services.pluck(:name),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

},
}
end
Expand Down
Loading