dynamic-records-meritfront 3.0.23 → 3.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/dynamic-records-meritfront/version.rb +1 -1
- data/lib/dynamic-records-meritfront.rb +90 -31
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7452d0058119526d1ece08203106f8ae07da51f41e22f764c4d5262d2340e7f4
|
4
|
+
data.tar.gz: 88fc11727ba9a6d016afb22ec03beafc30412e37502daf35e33dce6532ef02b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69eff49f3efbfd1261477cd3b895786a0dc97ca09e2933aab4471eea85c61f4e54651d37a4d3138e4c9d7c64f4802c3fda0d45152d84598e206072a14b828089
|
7
|
+
data.tar.gz: e6a26b39284b4b80891fed68af41d930b1d12e83aaadad45c8d6fee4c9f1bfadbaebd3ff56407a09b5714f2248d3cf39cdb58a37cc4a8835241933294f99a2d9
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dynamic-records-meritfront (3.0.
|
4
|
+
dynamic-records-meritfront (3.0.24)
|
5
5
|
hashid-rails
|
6
6
|
|
7
7
|
GEM
|
@@ -26,7 +26,7 @@ GEM
|
|
26
26
|
concurrent-ruby (~> 1.0)
|
27
27
|
minitest (5.17.0)
|
28
28
|
rake (12.3.3)
|
29
|
-
tzinfo (2.0.
|
29
|
+
tzinfo (2.0.6)
|
30
30
|
concurrent-ruby (~> 1.0)
|
31
31
|
|
32
32
|
PLATFORMS
|
@@ -22,7 +22,7 @@ module DynamicRecordsMeritfront
|
|
22
22
|
#Note we defined here as it breaks early on as Rails.application returns nil
|
23
23
|
PROJECT_NAME = Rails.application.class.to_s.split("::").first.to_s.downcase
|
24
24
|
DYNAMIC_SQL_RAW = true
|
25
|
-
|
25
|
+
attr_accessor :dynamic_reflections
|
26
26
|
end
|
27
27
|
|
28
28
|
class DynamicSqlVariables
|
@@ -86,7 +86,7 @@ module DynamicRecordsMeritfront
|
|
86
86
|
DateTime => ActiveModel::Type::DateTime,
|
87
87
|
Time => ActiveModel::Type::Time,
|
88
88
|
Float => ActiveModel::Type::Float,
|
89
|
-
|
89
|
+
NilClass => ActiveModel::Type::Boolean,
|
90
90
|
Array => Proc.new{ |first_el_class| ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array.new(DB_TYPE_MAPS[first_el_class].new) }
|
91
91
|
}
|
92
92
|
|
@@ -106,11 +106,7 @@ module DynamicRecordsMeritfront
|
|
106
106
|
|
107
107
|
type = DB_TYPE_MAPS[v.class]
|
108
108
|
if type.nil?
|
109
|
-
#
|
110
|
-
# raise StandardError.new("")
|
111
|
-
# else
|
112
|
-
raise StandardError.new("#{name} (of value: #{v}, class: #{v.class}) unsupported class for ApplicationRecord#headache_sql")
|
113
|
-
# end
|
109
|
+
raise StandardError.new("#{name} (of value: #{v}, class: #{v.class}) unsupported class for ApplicationRecord#headache_sql")
|
114
110
|
elsif type.class == Proc
|
115
111
|
a = v[0]
|
116
112
|
# if a.nil?
|
@@ -168,35 +164,86 @@ module DynamicRecordsMeritfront
|
|
168
164
|
|
169
165
|
def questionable_attribute_set(atr, value, as_default: false, push: false)
|
170
166
|
#this is needed on initalization of a new variable after the actual thing has been made already.
|
167
|
+
#this is used for attaching records to other records in one-to-one or one-to-many
|
168
|
+
|
169
|
+
#basically the way this works is by using singletons to paper over the fact that normal reflections
|
170
|
+
#even exist. We dont integrate at all with their patterns as they use some crazy delegation stuff
|
171
|
+
#that messes just about everything up.
|
172
|
+
|
173
|
+
#man i thought i was meta coding, these association people just want to see the world burn.
|
174
|
+
|
175
|
+
#keeping the old code commented for a while because this area keeps breaking and i want a log of what i have tried.
|
176
|
+
|
177
|
+
self.dynamic_reflections ||= []
|
178
|
+
|
179
|
+
unless dynamic_reflections.include?(atr.to_s)
|
180
|
+
self.dynamic_reflections << atr.to_s
|
181
|
+
singleton_class.instance_eval do
|
182
|
+
attr_accessor atr.to_sym
|
183
|
+
end
|
184
|
+
end
|
185
|
+
# # if _reflections.keys.include? atr.to_s
|
186
|
+
# has_method = methods.include?(atr.to_sym)
|
187
|
+
#
|
188
|
+
# DevScript.ping(has_method)
|
189
|
+
# override = (not(has_method) or (
|
190
|
+
# _reflections.keys.include? atr.to_s
|
191
|
+
# and not
|
192
|
+
|
193
|
+
# )
|
194
|
+
# DevScript.ping(override)
|
195
|
+
|
196
|
+
# if override
|
197
|
+
|
198
|
+
|
199
|
+
# end
|
200
|
+
#elsif
|
201
|
+
|
202
|
+
#end
|
171
203
|
|
172
|
-
#note that the below is the value lookup for ActiveModel, but values seems to have all the database columns
|
173
|
-
#in it anyways
|
174
|
-
#
|
175
|
-
# def key?(name)
|
176
|
-
# (values.key?(name) || types.key?(name) || @attributes.key?(name)) && self[name].initialized?
|
177
|
-
# end
|
178
|
-
raise StandardError.new('bad options') if as_default and push
|
179
204
|
if as_default
|
180
|
-
|
181
|
-
#
|
182
|
-
|
183
|
-
if not values.keys.include?(atr)
|
184
|
-
values[atr] = value
|
185
|
-
end
|
205
|
+
if self.method(atr.to_sym).call().nil?
|
206
|
+
self.method("#{atr}=".to_sym).call(value)
|
207
|
+
# DevScript.ping("atr #{atr} def #{value}")
|
186
208
|
end
|
209
|
+
elsif push
|
210
|
+
self.method(atr.to_sym).call().push value
|
211
|
+
# DevScript.ping("atr #{atr} push #{value}")
|
187
212
|
else
|
188
|
-
#
|
189
|
-
#
|
190
|
-
# that seems to be my bread and butter. Hope eval doesnt make it go too slow. Guess everything is evaled
|
191
|
-
# on some level though?
|
192
|
-
s = self #afraid self will be a diffrent self in eval. Possibly depending on parser. IDK. Just seemed risky.
|
193
|
-
if push
|
194
|
-
eval "s.#{atr} << value"
|
195
|
-
else
|
196
|
-
eval "s.#{atr} = value"
|
197
|
-
end
|
213
|
+
self.method("#{atr}=".to_sym).call(value)
|
214
|
+
# DevScript.ping("atr #{atr} set #{value}")
|
198
215
|
end
|
199
216
|
|
217
|
+
# raise StandardError.new('bad options') if as_default and push
|
218
|
+
# if as_default
|
219
|
+
# unless self.respond_to? atr
|
220
|
+
# #make sure its accesible in some way
|
221
|
+
# values = @attributes.instance_variable_get(:@values)
|
222
|
+
# if not values.keys.include?(atr)
|
223
|
+
# values[atr] = value
|
224
|
+
# end
|
225
|
+
# end
|
226
|
+
# else
|
227
|
+
# if self.reflections.keys.include? atr.to_s
|
228
|
+
#
|
229
|
+
# else
|
230
|
+
# values ||= @attributes.instance_variable_get(:@values)
|
231
|
+
# values[atr] << value
|
232
|
+
#
|
233
|
+
#
|
234
|
+
# end
|
235
|
+
# #no getter/setter methodsout, probably catches missing methods and then redirects to attributes. Lots of magic.
|
236
|
+
# # After multiple attempts, I gave up, so now we use eval. I guess I cant be too mad about magic as
|
237
|
+
# # that seems to be my bread and butter. Hope eval doesnt make it go too slow. Guess everything is evaled
|
238
|
+
# # on some level though?
|
239
|
+
# s = self #afraid self will be a diffrent self in eval. Possibly depending on parser. IDK. Just seemed risky.
|
240
|
+
# if push
|
241
|
+
# eval "s.#{atr} << value"
|
242
|
+
# else
|
243
|
+
# eval "s.#{atr} = value"
|
244
|
+
# end
|
245
|
+
# end
|
246
|
+
|
200
247
|
# atr = atr.to_s
|
201
248
|
# setter = "#{atr}="
|
202
249
|
# if respond_to?(setter)
|
@@ -232,6 +279,9 @@ module DynamicRecordsMeritfront
|
|
232
279
|
#basically the same as the upstream active record function (as of october 25 2022 on AR V7.0.4)
|
233
280
|
#except that I changed self.class.attribute_names -> self.attribute_names to pick up our
|
234
281
|
#dynamic insanity. Was this a good idea? Well I guess its better than not doing it
|
282
|
+
|
283
|
+
#I also added dynamic_reflections
|
284
|
+
|
235
285
|
inspection = if defined?(@attributes) && @attributes
|
236
286
|
self.attribute_names.filter_map do |name|
|
237
287
|
if _has_attribute?(name)
|
@@ -242,7 +292,16 @@ module DynamicRecordsMeritfront
|
|
242
292
|
"not initialized"
|
243
293
|
end
|
244
294
|
|
245
|
-
|
295
|
+
self.dynamic_reflections ||= []
|
296
|
+
dyna = dynamic_reflections.map{|dr|
|
297
|
+
self.method(dr.to_sym).call()
|
298
|
+
}
|
299
|
+
|
300
|
+
if dyna.any?
|
301
|
+
"#<#{self.class} #{inspection} | #{dyna.to_s}>"
|
302
|
+
else
|
303
|
+
"#<#{self.class} #{inspection} >"
|
304
|
+
end
|
246
305
|
end
|
247
306
|
|
248
307
|
module ClassMethods
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic-records-meritfront
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Clancy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashid-rails
|