Skip to content

first try - #1

Open
histfak wants to merge 1 commit into
masterfrom
part1
Open

first try#1
histfak wants to merge 1 commit into
masterfrom
part1

Conversation

@histfak

@histfak histfak commented Jun 7, 2019

Copy link
Copy Markdown
Owner

No description provided.

Comment thread lib/simpler.rb
@@ -1,4 +1,5 @@
require 'pathname'
require_relative 'simpler/middleware/logger'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Лучше подключить это сразу в config.ru, поскольку middleware там же подключается.

Comment thread lib/simpler/controller.rb
end

def set_default_headers
return @response['Content-Type'] = 'text/plain' if @request.env['simpler.template'].is_a?(Hash)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

На самом деле, не факт что мы обязательно будет рендерить plain text. Может потребоваться рендеринг json, xml или pdf, например.

Comment thread lib/simpler/view.rb

def render(binding)
template = File.read(template_path)
template = template_path.is_a?(Hash) ? template_path.first[1] : File.read(template_path)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Здесь лучше разделить логику рендеринга ответов разных типов между отдельными классами. Для каждого типа ответа может быть свой собственный класс с методом render. Тогда в обязанности View будет входить выбор нужного класса рендеринга и делегирование ему метода render.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants