Skip to content

Commit

Permalink
finalize the Model::Find() release.
Browse files Browse the repository at this point in the history
closes #47.
  • Loading branch information
apotonick committed Jun 26, 2024
1 parent eefc20b commit 2dd932e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 2.1.16

* Fix a bug in `patch` where `Subprocess()` was missing in `Macro::Strategy`.
* Introduce `Model::Build` and `Model::Find` macros, which are a replacement for the less
customizable `Model()`. See https://trailblazer.to/2.1/docs/macro/#macro-model-model-find

# 2.1.15

* Use `Macro.id_for` for `Rescue`, meaning IDs will now be consistent à la `Rescue/1` instead of `Rescue(1)`.
Expand Down
16 changes: 8 additions & 8 deletions lib/trailblazer/macro/model/find.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ def self.Find(model_class, positional_method = nil, find_method: nil, id: "model

params_key, block, finder_step_options =
if positional_method
bla_explicit_positional(model_class, positional_method, **keyword_options, &block)
for_explicit_positional(model_class, positional_method, **keyword_options, &block)
elsif find_method.nil? && query.nil? # translate_from_shorthand
bla_shorthand(model_class, **keyword_options, &block)
for_shorthand(model_class, **keyword_options, &block)
else # options passed explicitly, kws. this still means we need to translate find_method to query, or use user's query.
# TODO: sort out query: default it or take user's

if query.nil?
blubb_bla_keywords(model_class, find_method: find_method, **keyword_options, &block)
for_keywords(model_class, find_method: find_method, **keyword_options, &block)
else
# raise "IMPLEMENT ME"
blubb_bla_query(model_class, query, **keyword_options, &block)
for_query(model_class, query, **keyword_options, &block)
end
end

Expand All @@ -48,7 +48,7 @@ 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)
def self.for_shorthand(model_class, **options, &block)
# translate shorthand form.
find_method_name, column_key = options.to_a[0]

Expand All @@ -61,7 +61,7 @@ def self.bla_shorthand(model_class, **options, &block)
]
end

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

[
Expand All @@ -71,15 +71,15 @@ def self.bla_explicit_positional(model_class, positional_method, **options, &blo
]
end

def self.blubb_bla_keywords(model_class, find_method:, **options, &block) # FIXME: defaulting is redundant with bla_explicit_positional.
def self.for_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

def self.blubb_bla_query(model_class, query, column_key: :id, params_key: column_key, **, &block) # FIXME: defaulting is redundant with bla_explicit_positional.
def self.for_query(model_class, query, column_key: :id, params_key: column_key, **, &block) # FIXME: defaulting is redundant with bla_explicit_positional.
query_on_model_class = ->(ctx, **kws) { model_class.instance_exec(ctx, **kws, &query) } # FIXME: we can only use procs here. what about methods, classes etc?

finder = Macro.task_adapter_for_decider(query_on_model_class, variable_name: :model) # FIXME: {:model} is hard-coded.
Expand Down

0 comments on commit 2dd932e

Please sign in to comment.