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

Fix NoMethodError at Orthoses::ActiveRecord::Scope middleware #18

Merged
merged 2 commits into from
Nov 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/orthoses/active_record/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def call
name = capture.argument[:name]
body = capture.argument[:body]

definition = "#{name}: #{parameters_to_type(body.parameters)} -> #{base_name}::ActiveRecord_Relation"
definition = "#{name}: #{parameters_to_type(parameters(body))} -> #{base_name}::ActiveRecord_Relation"
store[base_name] << "def self.#{definition}"
store["#{base_name}::GeneratedRelationMethods"].header = "module #{base_name}::GeneratedRelationMethods"
store["#{base_name}::GeneratedRelationMethods"] << "def #{definition}"
Expand Down Expand Up @@ -58,6 +58,16 @@ def parameters_to_type(parameters)
end
"(#{res.join(", ")})#{block}"
end

def parameters(body)
if body.is_a?(Proc)
body.parameters
elsif body.respond_to?(:call)
body.method(:call).parameters
else
raise "unexpected: #{body} passed to scope"
end
sanfrecce-osaka marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
end