File tree 1 file changed +23
-11
lines changed
1 file changed +23
-11
lines changed Original file line number Diff line number Diff line change @@ -13,11 +13,18 @@ class ArrayResource < Base
13
13
14
14
class << self
15
15
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
19
26
end
20
- end
27
+ )
21
28
end
22
29
end
23
30
@@ -61,16 +68,21 @@ def fetch_records(array_of_records = nil)
61
68
# Dynamically create a class with accessors for all unique keys from the records
62
69
keys = array_of_records . flat_map ( &:keys ) . uniq
63
70
64
- custom_class = Class . new do
65
- include ActiveModel ::Model
71
+ Object . const_set (
72
+ name ,
73
+ Class . new do
74
+ include ActiveModel ::Model
66
75
67
- # Dynamically define accessors
68
- attr_accessor ( *keys )
76
+ # Dynamically define accessors
77
+ attr_accessor ( *keys )
69
78
70
- define_method ( :to_param ) do
71
- id
79
+ define_method ( :to_param ) do
80
+ id
81
+ end
72
82
end
73
- end
83
+ )
84
+
85
+ custom_class = name . constantize
74
86
75
87
# Map the records to instances of the dynamically created class
76
88
array_of_records . map do |item |
You can’t perform that action at this time.
0 commit comments