Skip to content

Commit

Permalink
move defaulting of params_key and column_key to separate method.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Jun 21, 2024
1 parent 4c7ad16 commit ccbaa2c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/trailblazer/macro/model/find.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ def self.Find(model_class, positional_method = nil, find_method: nil, id: "model
options
end

def self.bla_shorthand(model_class, **keyword_options, &block)
# Defaulting happening.
def self.normalize_keys(column_key: :id, params_key: column_key, **)
return params_key, column_key
end

def self.bla_shorthand(model_class, **options, &block)
# translate shorthand form.
find_method_name, column_key = keyword_options.to_a[0]
find_method_name, column_key = options.to_a[0]

params_key = keyword_options.key?(:params_key) ? keyword_options[:params_key] : column_key # TODO: use method for this.
params_key = options.key?(:params_key) ? options[:params_key] : column_key # TODO: use method for this.

[
params_key,
Expand All @@ -56,16 +61,20 @@ def self.bla_shorthand(model_class, **keyword_options, &block)
]
end

def self.bla_explicit_positional(model_class, positional_method, column_key: :id, params_key: column_key, **, &block)
def self.bla_explicit_positional(model_class, positional_method, **options, &block)
params_key, _ = normalize_keys(**options)

[
params_key,
block,
Find::Positional.new(model_class: model_class, find_method: positional_method), # query
]
end

def self.blubb_bla_keywords(model_class, find_method:, column_key: :id, params_key: column_key, **keyword_options, &block) # FIXME: defaulting is redundant with bla_explicit_positional.
finder = Find::KeywordArguments.new(model_class: model_class, find_method: find_method, column_key: column_key, **keyword_options)
def self.blubb_bla_keywords(model_class, find_method:, **options, &block) # FIXME: defaulting is redundant with bla_explicit_positional.
params_key, column_key = normalize_keys(**options)

finder = Find::KeywordArguments.new(model_class: model_class, find_method: find_method, column_key: column_key)

[params_key, block, finder]
end
Expand Down

0 comments on commit ccbaa2c

Please sign in to comment.