Skip to content

Commit 9f81a6c

Browse files
authored
fix: array resource adapter (#3684)
1 parent 6fef8ba commit 9f81a6c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/avo/resources/array_resource.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ class ArrayResource < Base
1414
class << self
1515
def model_class
1616
@@model_class ||= Object.const_set(
17-
name,
17+
class_name,
1818
Class.new do
1919
include ActiveModel::Model
2020

2121
class << self
2222
def primary_key = nil
2323

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

4141
def fetch_records(array_of_records = nil)
4242
array_of_records ||= records
43-
raise "Unable to fetch any #{name}" if array_of_records.nil?
43+
raise "Unable to fetch any #{class_name}" if array_of_records.nil?
4444

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

7171
Object.const_set(
72-
name,
72+
class_name,
7373
Class.new do
7474
include ActiveModel::Model
7575

@@ -82,7 +82,7 @@ def fetch_records(array_of_records = nil)
8282
end
8383
)
8484

85-
custom_class = name.constantize
85+
custom_class = class_name.constantize
8686

8787
# Map the records to instances of the dynamically created class
8888
array_of_records.map do |item|

0 commit comments

Comments
 (0)