File tree Expand file tree Collapse file tree 1 file changed +23
-11
lines changed
Expand file tree Collapse file tree 1 file changed +23
-11
lines changed Original file line number Diff line number Diff line change @@ -13,11 +13,18 @@ class ArrayResource < Base
1313
1414 class << self
1515 def model_class
16- @@model_class ||= ActiveSupport ::OrderedOptions . new . tap do |obj |
17- obj . model_name = ActiveSupport ::OrderedOptions . new . tap do |thing |
18- thing . plural = route_key
16+ @@model_class ||= Object . const_set (
17+ name ,
18+ Class . new do
19+ include ActiveModel ::Model
20+
21+ class << self
22+ def primary_key = nil
23+
24+ def all = "Avo::Resources::#{ name } " . constantize . new . fetch_records
25+ end
1926 end
20- end
27+ )
2128 end
2229 end
2330
@@ -61,16 +68,21 @@ def fetch_records(array_of_records = nil)
6168 # Dynamically create a class with accessors for all unique keys from the records
6269 keys = array_of_records . flat_map ( &:keys ) . uniq
6370
64- custom_class = Class . new do
65- include ActiveModel ::Model
71+ Object . const_set (
72+ name ,
73+ Class . new do
74+ include ActiveModel ::Model
6675
67- # Dynamically define accessors
68- attr_accessor ( *keys )
76+ # Dynamically define accessors
77+ attr_accessor ( *keys )
6978
70- define_method ( :to_param ) do
71- id
79+ define_method ( :to_param ) do
80+ id
81+ end
7282 end
73- end
83+ )
84+
85+ custom_class = name . constantize
7486
7587 # Map the records to instances of the dynamically created class
7688 array_of_records . map do |item |
You can’t perform that action at this time.
0 commit comments