dynamic-records-meritfront 2.0.17 → 2.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/dynamic-records-meritfront/version.rb +1 -1
- data/lib/dynamic-records-meritfront.rb +21 -67
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c23065ffa740c578b38c7311ada210295ad2b876240480109913eff333a7c7b6
|
4
|
+
data.tar.gz: e38654aeb1f6e5f3d8a91a334b0489847674bde43451a7bb7f641770f5f061fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63eb8b2cf1342d742e77140091583201dea03dccad9edb8aa78201d663eec39a352e9741978e967ba5fe8b0bfc461478328fe1e0dde46bba434b36495e3842fc
|
7
|
+
data.tar.gz: 35cd5e867cd6853b7614ce0d67c2253794f31b03af59c0e7189a66bca30c4e8f7eaa984858a2bb659607c60b8dc8b4a29ed9ba9bc5d944435ab38a425283db01
|
data/Gemfile.lock
CHANGED
@@ -19,7 +19,6 @@ module DynamicRecordsMeritfront
|
|
19
19
|
#Note we defined here as it breaks early on as Rails.application returns nil
|
20
20
|
PROJECT_NAME = Rails.application.class.to_s.split("::").first.to_s.downcase
|
21
21
|
DYNAMIC_SQL_RAW = true
|
22
|
-
attr_accessor :dynamic
|
23
22
|
end
|
24
23
|
|
25
24
|
class MultiRowExpression
|
@@ -66,48 +65,8 @@ module DynamicRecordsMeritfront
|
|
66
65
|
end
|
67
66
|
end
|
68
67
|
|
69
|
-
RecordForPrint = Struct.new(:class, :attributes, :dynamic)
|
70
68
|
module ClassMethods
|
71
69
|
|
72
|
-
def dynamic_print_h(v)
|
73
|
-
v = v.dup
|
74
|
-
return v.to_h.transform_values{|x|
|
75
|
-
dynamic_print(x, print: false)
|
76
|
-
}
|
77
|
-
end
|
78
|
-
|
79
|
-
def dynamic_print_arr(v)
|
80
|
-
v = v.dup
|
81
|
-
return v.map{|x|
|
82
|
-
dynamic_print(x, print: false)
|
83
|
-
}
|
84
|
-
end
|
85
|
-
|
86
|
-
def dynamic_print_obj(v)
|
87
|
-
if v.class < ActiveRecord::Base
|
88
|
-
#return v.dynamic
|
89
|
-
return RecordForPrint.new(v.class.to_s, v.attributes, dynamic_print(v.dynamic, print: false))
|
90
|
-
else
|
91
|
-
v
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def dynamic_print(v, print: true)
|
96
|
-
return if Rails.env.production?
|
97
|
-
if v.class == Hash || v.class == OpenStruct
|
98
|
-
ret = dynamic_print_h v
|
99
|
-
elsif v.class == Array
|
100
|
-
ret = dynamic_print_arr v
|
101
|
-
else
|
102
|
-
ret = dynamic_print_obj v
|
103
|
-
end
|
104
|
-
if print
|
105
|
-
pp ret
|
106
|
-
else
|
107
|
-
return ret
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
70
|
def has_run_migration?(nm)
|
112
71
|
#put in a string name of the class and it will say if it has allready run the migration.
|
113
72
|
#good during enum migrations as the code to migrate wont run if enumerate is there
|
@@ -492,9 +451,17 @@ module DynamicRecordsMeritfront
|
|
492
451
|
|
493
452
|
#variable accessors and defaults.
|
494
453
|
base_arr.each{ |o|
|
495
|
-
|
496
|
-
|
497
|
-
|
454
|
+
#
|
455
|
+
# there is no way to set an attribute after instantiation I tried I looked
|
456
|
+
# I dealt with silent breaks on symbol keys, I have wasted time, its fine.
|
457
|
+
cancer = o.instance_variable_get(:@attributes).instance_variable_get(:@values)
|
458
|
+
if not base_class_is_hash
|
459
|
+
if one_to_one
|
460
|
+
#attach name must be a string
|
461
|
+
cancer[attach_name] = nil
|
462
|
+
else
|
463
|
+
cancer[attach_name] = []
|
464
|
+
end
|
498
465
|
end
|
499
466
|
# o.dynamic o.singleton_class.public_send(:attr_accessor, attach_name_sym) unless base_class_is_hash
|
500
467
|
# o.instance_variable_set(attach_name_with_at, []) unless one_to_one
|
@@ -531,9 +498,7 @@ module DynamicRecordsMeritfront
|
|
531
498
|
attach_on = Proc.new{|x| x[default_attach_col]}
|
532
499
|
else
|
533
500
|
attach_on = Proc.new{|x|
|
534
|
-
|
535
|
-
ret ||= x.dynamic[default_attach_col]
|
536
|
-
ret
|
501
|
+
x.attributes[default_attach_col]
|
537
502
|
}
|
538
503
|
end
|
539
504
|
end
|
@@ -551,21 +516,9 @@ module DynamicRecordsMeritfront
|
|
551
516
|
#(b=base, a=attach)
|
552
517
|
add_to_base = Proc.new{|b, a|
|
553
518
|
if one_to_one
|
554
|
-
|
555
|
-
b[attach_name] = a
|
556
|
-
else
|
557
|
-
b.dynamic ||= OpenStruct.new
|
558
|
-
b.dynamic[attach_name] = a
|
559
|
-
#b.instance_variable_set(attach_name_with_at, a)
|
560
|
-
end
|
519
|
+
b[attach_name] = a
|
561
520
|
else
|
562
|
-
|
563
|
-
b[attach_name].push a
|
564
|
-
else
|
565
|
-
# o.dynamic o.single
|
566
|
-
b.dynamic[attach_name].push a
|
567
|
-
#b.instance_variable_get(attach_name_with_at).push a
|
568
|
-
end
|
521
|
+
b[attach_name].push a
|
569
522
|
end
|
570
523
|
}
|
571
524
|
|
@@ -596,12 +549,13 @@ module DynamicRecordsMeritfront
|
|
596
549
|
if klass.abstract_class
|
597
550
|
return input
|
598
551
|
else
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
#
|
603
|
-
|
604
|
-
|
552
|
+
record = klass.instantiate(input.stringify_keys ) #trust me they need to be stringified
|
553
|
+
# #handle attributes through ar if allowed. Throws an error on unkown variables, except apparently for devise classes? 😡
|
554
|
+
# active_record_handled = input.slice(*(klass.attribute_names & input.keys))
|
555
|
+
# record = klass.instantiate(active_record_handled)
|
556
|
+
# #set those that were not necessarily expected
|
557
|
+
# not_expected = input.slice(*(input.keys - klass.attribute_names))
|
558
|
+
# record.dynamic = OpenStruct.new(not_expected.transform_keys{|k|k.to_sym}) if not_expected.keys.any?
|
605
559
|
return record
|
606
560
|
end
|
607
561
|
end
|