Skip to content

Commit c321c1d

Browse files
fix: Resolve remaining RuboCop offenses
- Refactors the model processing line in `_prepare_setter_logic_options` within `lib/controller_setter_pattern/action_controller.rb` to use an `if` condition, resolving conflicting `Style/SafeNavigationChainLength` and `Lint/SafeNavigationChain` RuboCop offenses. - Re-wraps RDoc comment lines in the same file to fix `Layout/LineLength` offenses. - Applies minor auto-corrections from RuboCop after these changes. RuboCop now reports no offenses in the codebase (aside from an environmental warning for gemspec Ruby version).
1 parent 40cc46f commit c321c1d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/controller_setter_pattern/action_controller.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ module ClassMethods
4343
#
4444
# * +:scope+ (<tt>Symbol</tt> or <tt>Array<Symbol></tt>): One or more scopes to apply to the model
4545
# or association before finding the record.
46-
# Example: <tt>set :user, scope: :active, finder_params: :email</tt> (calls <tt>User.active.find_by_email(...)</tt>)
46+
# Example: <tt>set :user, scope: :active, finder_params: :email</tt>
47+
# (calls <tt>User.active.find_by_email(...)</tt>)
4748
# Example: <tt>set :article, scope: [:published, :featured]</tt>
4849
#
4950
# * Standard +before_action+ options: Options like +:only+, +:except+, +:if+, +:unless+
@@ -62,7 +63,8 @@ module ClassMethods
6263
#
6364
# class CommentsController < ApplicationController
6465
# set :post # Sets @post = Post.find(params[:post_id])
65-
# set :comment, ancestor: :post, except: [:index, :new, :create] # Sets @comment = @post.comments.find(params[:id])
66+
# set :comment, ancestor: :post, except: [:index, :new, :create]
67+
# # Sets @comment = @post.comments.find(params[:id])
6668
# end
6769
#
6870
def set(*names)
@@ -103,8 +105,12 @@ def build_finder_method(params_keys)
103105
# Hash: A structured options hash for internal use.
104106
def _prepare_setter_logic_options(custom_opts)
105107
normalized_finder_params = _normalize_finder_params(custom_opts.fetch(:finder_params, []))
108+
109+
model_class = nil
110+
model_class = custom_opts[:model].to_s.camelize.constantize if custom_opts[:model]
111+
106112
{
107-
model: custom_opts[:model]&.to_s&.camelize&.constantize,
113+
model: model_class,
108114
finder_params: normalized_finder_params,
109115
finder_method: build_finder_method(normalized_finder_params), # Call new helper
110116
ancestor: custom_opts[:ancestor],

0 commit comments

Comments
 (0)