Skip to content
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

Code review #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Code review #1

wants to merge 1 commit into from

Conversation

ivanovaolga
Copy link

No description provided.

Frondit supports Ruby 2.2+, Rails. 4.1+

## FIXME
- Tests coverage is poor
Copy link
Author

Choose a reason for hiding this comment

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

Надо либо добавить тесты, либо написать что в инпрогресс либо не упоминать тесты вообще.

@@ -1,30 +0,0 @@
# frozen_string_literal: true
Copy link
Author

Choose a reason for hiding this comment

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

Везде где можно нужны одинарные кавычки

before_action action_list do
policies = gon.policies
policies ||= {}
policies[policy_class.to_s.camelize] = Frondit::Extractor.new(self, current_user, policy_class, config).call
Copy link
Author

Choose a reason for hiding this comment

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

Слишком длинная строка, 80 символов

Copy link
Author

Choose a reason for hiding this comment

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

Интересно про current_user: он всегда есть там, куда миксуется модуль?


EXCEPT_POLICY_METHODS = %i[user record].freeze

def initialize(controller_instance, user, policy_class, config)
Copy link
Author

@ivanovaolga ivanovaolga Jul 3, 2019

Choose a reason for hiding this comment

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

Здесь бы подошли keyword arguments, например, так
initialize(controller_instance:, user:, policy_class:, config: {})
или
initialize(controller_instance:, user:, policy_class:, **config)

я считаю, так код нагляднее и более гибок для изменений.
Например, вот здесь мы не знаем, что значит первый аргумент:

Frondit::Extractor.new(self, current_user, policy_class, config).call

а так знаем:

extractor = Frondit::Extractor.new(
  controller_instance: self,
  user:                current_user,
  policy_class:        policy_class,
  config:              config
)
policies[policy_class.to_s.camelize] = extractor.call


private

attr_reader :controller_instance, :user, :policy_class_path, :rules_to_check, :record_variable_name
Copy link
Author

@ivanovaolga ivanovaolga Jul 3, 2019

Choose a reason for hiding this comment

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

Я считаю, что объявления аттрибутов и аксессоров более читабельны, когда расположены наверху класса. Мы открываем класс и не листаем его в поисках аттрибутов. При этом видим сразу и паблик и приватные.
rubocop/ruby-style-guide#538 (comment)

attr_reader :controller_instance, :user, :policy_class_path, :rules_to_check, :record_variable_name
private  :controller_instance, :user, :policy_class_path, :rules_to_check, :record_variable_name

@policy_rules ||= policy_class.ancestors.map! do |klass|
next unless klass.to_s.include? "Policy"
klass.instance_methods(false).reject { |method| EXCEPT_POLICY_METHODS.include? method }
end.flatten.compact.uniq
Copy link
Author

Choose a reason for hiding this comment

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

@ivanovaolga ivanovaolga changed the title Remove Code review Jul 3, 2019
action_list[:only] = config[:on] if config[:on].present?
before_action action_list do
policies = gon.policies
policies ||= {}
Copy link
Author

Choose a reason for hiding this comment

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

Можно сократить

policies = gon.policies
policies ||= {}

до

policies = gon.policies || {}

before_action action_list do
policies = gon.policies
policies ||= {}
policies[policy_class.to_s.camelize] = Frondit::Extractor.new(self, current_user, policy_class, config).call
Copy link
Author

Choose a reason for hiding this comment

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

Интересно про current_user: он всегда есть там, куда миксуется модуль?

script_content = <<-SCRIPT
#{Gon::Base.render_data(need_tag: false)}
window.policies = function() { return window.gon.policies }
window.policy = function(name) { return window.gon.policies[name] }
Copy link
Author

Choose a reason for hiding this comment

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

я бы здесь выровняла отступы у =

@user = user
@policy_class_path = policy_class
@rules_to_check = config[:only]
@record_variable_name = config[:record].to_sym if config[:record]
Copy link
Author

Choose a reason for hiding this comment

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

Это можно упростить @record_variable_name = config[:record].try(:to_sym)

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.

1 participant