Conversation
app.rb
Outdated
|
|
||
| false | ||
| end | ||
| end No newline at end of file |
There was a problem hiding this comment.
Пора уже научиться избегать No new lina at end of file
app.rb
Outdated
| private | ||
|
|
||
| def headers | ||
| { 'Content-Type' => 'text/plain' } |
There was a problem hiding this comment.
Для настройки ContentType по умолчанию можно воспользоваться настройкой через Rack::ContentType
https://www.rubydoc.info/gems/rack/Rack/ContentType
и этот код будет не нужным
| end | ||
|
|
||
| def body | ||
| return ["404\n"] unless format_exist? |
There was a problem hiding this comment.
404 надо отдавать не от отсутствие какого-то параметра, а от отсутствия запрашиваемого ресурса
There was a problem hiding this comment.
так же в rack есть инструмент для путе Rack::URLMap
format_time.rb
Outdated
| end | ||
|
|
||
| def params_valid? | ||
| return false unless (format_params - VALID_FORMAT.keys).empty? |
There was a problem hiding this comment.
метод .empty? предикатный. Он и так вернёт тру или фолс.
Дополнительные проверки типа return false лишние
получается какая-то тавтология
app.rb
Outdated
|
|
||
| def status | ||
| return 404 unless format_exist? | ||
|
|
There was a problem hiding this comment.
тут пустая строка лишняя.
м/у retrurn пустые строки не оставляют
app.rb
Outdated
|
|
||
| class App | ||
| def call(env) | ||
| Rack::URLMap.new( |
There was a problem hiding this comment.
Rack::URLMap уже объявлен в config.ru
time_handler.rb
Outdated
| end | ||
|
|
||
| def headers | ||
| { 'Content-Type' => 'text/plain' } |
There was a problem hiding this comment.
как то много Content-Type по коду. Достаточно 1 раз указать в config.ru, так как другой тим не планируется передавать
time_handler.rb
Outdated
| @@ -0,0 +1,23 @@ | |||
| class TimeHandler | |||
There was a problem hiding this comment.
этот классвремя не обрабатывает, а служит контроллером запроса. Название класса как App более подходило. А вот текущий app.rb очень сомнительный файл
| private | ||
|
|
||
| def status | ||
| return 404 unless @request.path_info == '/time' |
There was a problem hiding this comment.
Это условие ни когда не будет true. так как в конфиге уже прописан Rack::URLMap.
No description provided.