Skip to content

Commit

Permalink
rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
ermolaev committed Jul 4, 2024
1 parent 60219ec commit 31930e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ Gp/OptArgParameters:
Style/SingleLineMethods:
Exclude:
- lib/active_dry_form/builder.rb

Style/StringLiterals:
EnforcedStyle: single_quotes

AllCops:
NewCops: enable
TargetRubyVersion: 2.7
18 changes: 9 additions & 9 deletions lib/active_dry_form/base_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def errors_full_messages
end

def t(*keys)
str_keys = keys.join(".")
I18n.t("helpers.label.#{str_keys}", default: "activerecord.attributes.#{str_keys}".to_sym)
str_keys = keys.join('.')
I18n.t("helpers.label.#{str_keys}", default: :"activerecord.attributes.#{str_keys}")
end

def persisted?
Expand Down Expand Up @@ -95,7 +95,7 @@ def params=(params)

if form_params.is_a?(::ActionController::Parameters)
unless ActiveDryForm.config.allow_action_controller_params
message = "in `params` use `request.parameters` instead of `params` or set `allow_action_controller_params` to `true` in config"
message = 'in `params` use `request.parameters` instead of `params` or set `allow_action_controller_params` to `true` in config'
raise ParamsNotAllowedError, message
end

Expand Down Expand Up @@ -146,9 +146,9 @@ def self.define_methods
self::FIELDS_INFO[:properties].each do |key, value|
nested_from_key = {}
nested_type =
if value[:type] == "object"
if value[:type] == 'object'
self::CURRENT_CONTRACT.schema.schema_dsl.types[key].type.primitive
elsif value.dig(:items, :type) == "object"
elsif value.dig(:items, :type) == 'object'
nested_from_key[:is_array] = true
self::CURRENT_CONTRACT.schema.schema_dsl.types[key].type.member.type.primitive
end
Expand All @@ -175,18 +175,18 @@ def self.define_methods
attributes[key] = _deep_transform_values_in_params!(v)
end

define_method :"[]=" do |key, v|
define_method :'[]=' do |key, v|
attributes[key] = _deep_transform_values_in_params!(v)
end

if nested_namespace && value[:type] == "object"
if nested_namespace && value[:type] == 'object'
define_method nested_namespace do
attributes[nested_namespace] = sub_klass.wrap(attributes[nested_namespace])
attributes[nested_namespace].record = record.try(nested_namespace)
attributes[nested_namespace].parent_form = self
attributes[nested_namespace]
end
elsif nested_namespace && value[:type] == "array"
elsif nested_namespace && value[:type] == 'array'
define_method nested_namespace do
nested_records = record.try(nested_namespace) || []
if attributes.key?(nested_namespace)
Expand Down Expand Up @@ -271,7 +271,7 @@ def persisted?
end

def id
self[:id] || self["id"]
self[:id] || self['id']
end

def define_methods
Expand Down
2 changes: 1 addition & 1 deletion lib/active_dry_form/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def show_error(field)

def button(value = nil, options = {}, &block)
options[:class] = [options[:class], 'button'].compact
super(value, options, &block)
super
end

def fields_for(association_name, fields_options = {}, &block)
Expand Down

0 comments on commit 31930e4

Please sign in to comment.