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: correctly handle multi-word class names in array resource adapter #3684

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Changes from all commits
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
10 changes: 5 additions & 5 deletions lib/avo/resources/array_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class ArrayResource < Base
class << self
def model_class
@@model_class ||= Object.const_set(
name,
class_name,
Class.new do
include ActiveModel::Model

class << self
def primary_key = nil

def all = "Avo::Resources::#{name}".constantize.new.fetch_records
def all = "Avo::Resources::#{class_name}".constantize.new.fetch_records
end
end
)
Expand All @@ -40,7 +40,7 @@ def find_record(id, query: nil, params: nil)

def fetch_records(array_of_records = nil)
array_of_records ||= records
raise "Unable to fetch any #{name}" if array_of_records.nil?
raise "Unable to fetch any #{class_name}" if array_of_records.nil?

# When the array of records is declared in a field's block, we need to get that block from the parent resource
# If there is no block try to pick those from the parent_record
Expand Down Expand Up @@ -69,7 +69,7 @@ def fetch_records(array_of_records = nil)
keys = array_of_records.flat_map(&:keys).uniq

Object.const_set(
name,
class_name,
Class.new do
include ActiveModel::Model

Expand All @@ -82,7 +82,7 @@ def fetch_records(array_of_records = nil)
end
)

custom_class = name.constantize
custom_class = class_name.constantize

# Map the records to instances of the dynamically created class
array_of_records.map do |item|
Expand Down
Loading