dynamic-records-meritfront 3.0.26 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e61d44017d347ec7083448f67c2a3db1994f49b2a63c21d27c976c8a06c6b777
4
- data.tar.gz: bbc308253515c6db53e9964701745fbbee832aee9acd7d4c1d64812b532955f3
3
+ metadata.gz: 187dd89025805fae04c8f188a900f6373cfd84584a720787dec852c0281a2060
4
+ data.tar.gz: 778e0e23ede44cc3fbb304e7216d4846745c25cb0e9fc1d87c8871375b21efcb
5
5
  SHA512:
6
- metadata.gz: f5a7ae8e89825cf74e31e99e4e422087f3eacc9bb290c727c49ec272c8a40f507d932d3e64f85ee43edf8366c6b2fe6121f3303204ff759e838aaa435ea46c55
7
- data.tar.gz: d70bb9d0a4ab3972ad2f940f0606a1cad2b492ad5fc8daafa892d6014800513ae4d54d2d1d3d1f47d62c3b3bcd5f89c9100173e773cb042dceef4d0b5af4fbd4
6
+ metadata.gz: e1071cf066822a8da8b1bf522c51c80e012b7e8c8c137aa3c7666a2965952d254bd863d4fbb9df4d77192458ff0b744a96e01e7485f2be6a94fc1faa37b1fe7f
7
+ data.tar.gz: eebfbac3a6a3c0202255f15bad0ced512d8c60c79f601aaada4706790a5af518c06b7413dce5ffb38e6f5e9e8318de7221ae12049ec4129f1ed23a7efb55b1d4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dynamic-records-meritfront (3.0.26)
4
+ dynamic-records-meritfront (3.1.0)
5
5
  hashid-rails
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -526,6 +526,39 @@ v3.0.6
526
526
  - A: We set the location of where you called the function as the default name for easy debugging. Its not an error, we just take some info from the stacktrace. It also includes the method name which can provide some insite into what the query is doing. Makes logs alot nicer to look at.
527
527
  - Q: Whats MeritFront?
528
528
  - A: I am making a social media platform
529
+ - Q: Inspect on user records doesn't seem to work properly
530
+ - A: inspect is overwritten by many diffrent libraries, in terms of devise for example, they override our override of active record's inspect. The best way to deal with this is to look at the source location of these methods and bring them together (user.method(:inspect).source_location). In my case with devise, i ended up with this in the user record:
531
+ ```ruby
532
+ def inspect
533
+ #this is the same as the dynamic records inspect execpt i also melded together some of the
534
+ #devise stuff to keep passwords etc safe
535
+
536
+ inspection = if defined?(@attributes) && @attributes
537
+ self.attribute_names.filter_map do |name|
538
+ if _has_attribute?(name)
539
+ if UNSAFE_ATTRIBUTES_FOR_SERIALIZATION.include? name.to_sym
540
+ "#{name}: [redacted]"
541
+ else
542
+ "#{name}: #{attribute_for_inspect(name)}"
543
+ end
544
+ end
545
+ end.join(", ")
546
+ else
547
+ "not initialized"
548
+ end
549
+
550
+ self.dynamic_reflections ||= []
551
+ dyna = self.dynamic_reflections.map{|dr|
552
+ [dr, self.method(dr.to_sym).call()]
553
+ }.to_h
554
+
555
+ if dyna.keys.any?
556
+ "#<#{self.class} #{inspection} | #{dyna.to_s}>"
557
+ else
558
+ "#<#{self.class} #{inspection}>"
559
+ end
560
+ end
561
+ ```
529
562
 
530
563
  ## Contributing
531
564
 
@@ -1,5 +1,5 @@
1
1
 
2
2
  module DynamicRecordsMeritfront
3
- VERSION = '3.0.26'
3
+ VERSION = '3.1.0'
4
4
  end
5
5
  #this file gets overwritten automatically on minor updates, major ones need to be manually changed
@@ -199,18 +199,25 @@ module DynamicRecordsMeritfront
199
199
 
200
200
  #end
201
201
 
202
+ # pi = atr.to_sym == :current_user_follow
203
+ #DevScript.ping(self.inspect) if pi
202
204
  if as_default
203
205
  if self.method(atr.to_sym).call().nil?
204
206
  self.method("#{atr}=".to_sym).call(value)
205
- # DevScript.ping("atr #{atr} def #{value}")
207
+ # Rails.logger.info "Y #{value.followable_type if value.respond_to? :followable_type}" if pi
206
208
  end
209
+ # Rails.logger.info "#{atr} ||= #{value}" if pi
207
210
  elsif push
208
211
  self.method(atr.to_sym).call().push value
212
+ # Rails.logger.info #{atr} << #{value}" if pi
209
213
  # DevScript.ping("atr #{atr} push #{value}")
210
214
  else
215
+ #out =
211
216
  self.method("#{atr}=".to_sym).call(value)
217
+ # Rails.logger.info "[#{self.class.to_s} #{self.id}].#{atr} -> #{out.inspect}" if pi
212
218
  # DevScript.ping("atr #{atr} set #{value}")
213
219
  end
220
+ #Rails.logger.info self.inspect if pi
214
221
 
215
222
  # raise StandardError.new('bad options') if as_default and push
216
223
  # if as_default
@@ -291,14 +298,14 @@ module DynamicRecordsMeritfront
291
298
  end
292
299
 
293
300
  self.dynamic_reflections ||= []
294
- dyna = dynamic_reflections.map{|dr|
301
+ dyna = self.dynamic_reflections.map{|dr|
295
302
  [dr, self.method(dr.to_sym).call()]
296
303
  }.to_h
297
304
 
298
- if dyna.any?
305
+ if dyna.keys.any?
299
306
  "#<#{self.class} #{inspection} | #{dyna.to_s}>"
300
307
  else
301
- "#<#{self.class} #{inspection} >"
308
+ "#<#{self.class} #{inspection}>"
302
309
  end
303
310
  end
304
311
 
@@ -661,14 +668,22 @@ module DynamicRecordsMeritfront
661
668
  #formatting options
662
669
  for insta in insta_array
663
670
  if insta[:base_name]
664
- if insta[:as]
665
- Rails.logger.debug "#{insta[:table_name]} as #{insta[:as]} -> #{insta[:base_name]}"
666
- else
667
- Rails.logger.debug "#{insta[:table_name]} -> #{insta[:base_name]}"
668
- end
669
671
  #in this case, 'as' is meant as to what pseudonym to dynamicly attach it as
670
- dynamic_attach(ret_hash, insta[:base_name], insta[:table_name], base_on: insta[:base_on], attach_on: insta[:attach_on],
672
+ n_attached = dynamic_attach(ret_hash, insta[:base_name], insta[:table_name], base_on: insta[:base_on], attach_on: insta[:attach_on],
671
673
  one_to_one: insta[:one_to_one], as: insta[:as])
674
+
675
+ if Rails.logger.level <= 1
676
+ tn = insta[:table_name]
677
+ bn = insta[:base_name]
678
+ tc = ret_hash[tn].count
679
+ btc = ret_hash[bn].count
680
+
681
+ if insta[:as]
682
+ Rails.logger.debug "#{n_attached} attached from #{tn}(#{tc}) as #{insta[:as]} -> #{bn}(#{btc})"
683
+ else
684
+ Rails.logger.debug "#{n_attached} attached from #{tn}(#{tc}) -> #{bn}(#{btc})"
685
+ end
686
+ end
672
687
  elsif insta[:as]
673
688
  Rails.logger.debug "#{insta[:table_name]} as #{insta[:as]}"
674
689
  #in this case, the idea is more polymorphic in nature. unless they are confused and just want to rename the table (this can be done with
@@ -789,7 +804,7 @@ module DynamicRecordsMeritfront
789
804
  base_arr = instaload_sql_output[base_name]
790
805
 
791
806
  #return if there is nothing for us to attach to.
792
- return if base_arr.nil? or not base_arr.any?
807
+ return 0 if base_arr.nil? or not base_arr.any?
793
808
 
794
809
  #set variables for neatness and so we dont compute each time
795
810
  # base class information
@@ -814,7 +829,7 @@ module DynamicRecordsMeritfront
814
829
 
815
830
  #make sure the attach class has something going on. We do this after the default stage
816
831
  attach_arr = instaload_sql_output[attach_name]
817
- return if attach_arr.nil? or not attach_arr.any?
832
+ return 0 if attach_arr.nil? or not attach_arr.any?
818
833
 
819
834
  # attach class information
820
835
  attach_class = attach_arr.first.class
@@ -833,9 +848,16 @@ module DynamicRecordsMeritfront
833
848
  end
834
849
 
835
850
  #return an id->object hash for the base table for better access
836
- h = base_arr.map{|o|
837
- [base_on.call(o), o]
838
- }.to_h
851
+ h = {}
852
+ duplicates_base = Set[]
853
+ for base_rec in base_arr
854
+ bo = base_on.call(base_rec)
855
+ if h[bo]
856
+ duplicates_base << bo
857
+ else
858
+ h[bo] = base_rec
859
+ end
860
+ end
839
861
 
840
862
  #decide on the method of getting the matching id for the attach table
841
863
  unless attach_on
@@ -880,20 +902,38 @@ module DynamicRecordsMeritfront
880
902
  # 1. match base id to the attach id (both configurable)
881
903
  # 2. cancel out if there is no match
882
904
  # 3. otherwise add to the base object.
883
- attach_arr.each{|attach|
884
- out = attach_on.call(attach) #you can use null to escape the vals
885
- if out.nil?
905
+ x = 0
906
+
907
+ attach_arr.each{|attach_rec|
908
+ #we have it plural in case it attaches to multiple, for example a user can belong to many post-cards. Yes, this
909
+ #was a bug. In order to solve it you have to do some sort of 'distinct' or 'group' sql.
910
+
911
+ attachment_keys = attach_on.call(attach_rec) #you can use null to escape the vals
912
+
913
+ if attachment_keys.nil?
886
914
  Rails.logger.debug "attach_on proc output (which compares to the base_on proc) is outputting nil, this could be a problem depending on your use-case."
915
+ elsif not attachment_keys.kind_of? Array
916
+ attachment_keys = [attachment_keys]
887
917
  end
888
- if out
889
- base = h[out] #it is also escaped if no base element is found
890
- if base
891
- add_to_base.call(base, attach)
918
+
919
+ if attachment_keys and attachment_keys.any?
920
+ for ak in attachment_keys
921
+ base_rec = h[ak] #it is also escaped if no base element is found
922
+ if base_rec
923
+ dupl = duplicates_base.include? ak
924
+ if dupl
925
+ Rails.logger.warn "WARNING in #{attach_name} -> #{base_name}. Duplicate base_on key being utilized (this is usually in error). Only one base record will have an attachment. For the base table, consider using GROUP BY for your id and ARRAY_AGG for the base_on column."
926
+ Rails.logger.warn "base_on key: #{ak.to_s}"
927
+ end
928
+
929
+ x += 1 unless dupl
930
+ add_to_base.call(base_rec, attach_rec)
931
+ end
892
932
  end
893
933
  end
894
934
  }
895
935
 
896
- return attach_arr
936
+ return x
897
937
  end
898
938
  alias swiss_attach dynamic_attach
899
939
 
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.26
4
+ version: 3.1.0
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-10 00:00:00.000000000 Z
11
+ date: 2023-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashid-rails