dynamic-records-meritfront 3.1.3 → 3.1.33
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +24 -10
- data/README.md +9 -1
- data/bin/update +3 -0
- data/lib/dynamic-records-meritfront/version.rb +1 -1
- data/lib/dynamic-records-meritfront.rb +49 -28
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dfcf5de90cdcac42af2c68794fd94b2d97976edabebc30c7af030b03a4cc26f
|
4
|
+
data.tar.gz: 62d372644b0997607dc8cb73e4c95e0c29b4942b7519bea26cdfc3e960007899
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2eb9f39a73f585d769ac0e65f123f995a19d0129659e18b2d3978eb85668a32754ef859b3bef162d063c2cd720b4684e85247979ab3422485a179314566a2128
|
7
|
+
data.tar.gz: d70133876b5a852d6e3e6d73d9a4d76818e078ef5b46b0dc530a36801a48caa73764f9cc275794c75d6409a96dc4a5a67ad201d72f0741111dbc0f895b93463c
|
data/Gemfile.lock
CHANGED
@@ -1,31 +1,45 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dynamic-records-meritfront (3.1.
|
4
|
+
dynamic-records-meritfront (3.1.33)
|
5
5
|
hashid-rails
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (7.
|
11
|
-
activesupport (= 7.
|
12
|
-
activerecord (7.
|
13
|
-
activemodel (= 7.
|
14
|
-
activesupport (= 7.
|
15
|
-
|
10
|
+
activemodel (7.1.3.2)
|
11
|
+
activesupport (= 7.1.3.2)
|
12
|
+
activerecord (7.1.3.2)
|
13
|
+
activemodel (= 7.1.3.2)
|
14
|
+
activesupport (= 7.1.3.2)
|
15
|
+
timeout (>= 0.4.0)
|
16
|
+
activesupport (7.1.3.2)
|
17
|
+
base64
|
18
|
+
bigdecimal
|
16
19
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
20
|
+
connection_pool (>= 2.2.5)
|
21
|
+
drb
|
17
22
|
i18n (>= 1.6, < 2)
|
18
23
|
minitest (>= 5.1)
|
24
|
+
mutex_m
|
19
25
|
tzinfo (~> 2.0)
|
20
|
-
|
26
|
+
base64 (0.2.0)
|
27
|
+
bigdecimal (3.1.6)
|
28
|
+
concurrent-ruby (1.2.3)
|
29
|
+
connection_pool (2.4.1)
|
30
|
+
drb (2.2.1)
|
21
31
|
hashid-rails (1.4.1)
|
22
32
|
activerecord (>= 4.0)
|
23
33
|
hashids (~> 1.0)
|
24
34
|
hashids (1.0.6)
|
25
|
-
i18n (1.
|
35
|
+
i18n (1.14.3)
|
26
36
|
concurrent-ruby (~> 1.0)
|
27
|
-
|
37
|
+
racc (~> 1.7)
|
38
|
+
minitest (5.22.2)
|
39
|
+
mutex_m (0.2.0)
|
40
|
+
racc (1.7.3)
|
28
41
|
rake (12.3.3)
|
42
|
+
timeout (0.4.1)
|
29
43
|
tzinfo (2.0.6)
|
30
44
|
concurrent-ruby (~> 1.0)
|
31
45
|
|
data/README.md
CHANGED
@@ -532,6 +532,14 @@ v3.0.6
|
|
532
532
|
....
|
533
533
|
- took out undocumented quick_safe_increment and safe_increment as they were not relevant to the gem - and fairly basic.
|
534
534
|
|
535
|
+
3.1.28
|
536
|
+
- warning messages for dynamic_attach. to_s'd any provided table_names for ease-of-use.
|
537
|
+
- logging info for dynamic_attach outside of instaload.
|
538
|
+
- fixed an error where instaload only worked with ApplicationRecord abstract_class. Now works on anything thats a subclass of ActiveRecord::Base
|
539
|
+
|
540
|
+
3.2
|
541
|
+
- Updates so the latest version of the pg gem and rails works with the latest version of postgresql
|
542
|
+
|
535
543
|
|
536
544
|
## Questions
|
537
545
|
- Q: does the name of a sql operation have anything to do with prepared statements?
|
@@ -539,7 +547,7 @@ v3.0.6
|
|
539
547
|
- Q: The default name of my sql statements looks like a stack trace? Whats going on?
|
540
548
|
- 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.
|
541
549
|
- Q: Whats MeritFront?
|
542
|
-
- A: I am making a social media platform.
|
550
|
+
- A: I am making a social media platform. Its called midflip now. See midflip.io
|
543
551
|
- Q: Inspect on user records doesn't seem to work properly
|
544
552
|
- 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:
|
545
553
|
```ruby
|
data/bin/update
CHANGED
@@ -51,5 +51,8 @@ puts `git commit -m 'minor changes to version #{version_new}'`
|
|
51
51
|
puts "_______________________________________________"
|
52
52
|
puts "INSTALL GEM LOCALLY"
|
53
53
|
puts `bundle exec rake install`
|
54
|
+
puts "note if you cant install in your project u prob have different ruby versions for the project and this folder."
|
55
|
+
puts "if in that case and using rbenv, change your global ruby version under ~/.rbenv/version or your local by adding"
|
56
|
+
puts "somthing similar in a .ruby_version file. Not using .rbenv? Add ur instructions here"
|
54
57
|
puts "_______________________________________________"
|
55
58
|
puts "info: write 'bundle exec rake release' to release the current version to the interwebz"
|
@@ -105,7 +105,7 @@ module DynamicRecordsMeritfront
|
|
105
105
|
|
106
106
|
type = DB_TYPE_MAPS[v.class]
|
107
107
|
if type.nil?
|
108
|
-
raise StandardError.new("#{name} (of value: #{v}, class: #{v.class}) unsupported class for
|
108
|
+
raise StandardError.new("#{name} (of value: #{v}, class: #{v.class}) unsupported class for DynamicRecordsMeritfront#headache_sql")
|
109
109
|
elsif type.class == Proc
|
110
110
|
a = v[0]
|
111
111
|
# if a.nil?
|
@@ -400,9 +400,14 @@ module DynamicRecordsMeritfront
|
|
400
400
|
if returns_nil
|
401
401
|
return nil
|
402
402
|
else
|
403
|
-
raise StandardError.new("non-string class passed to
|
403
|
+
raise StandardError.new("non-string class passed to DynamicRecordsMeritfront#locate_hgid as the hgid_string variable")
|
404
404
|
end
|
405
405
|
end
|
406
|
+
if PROJECT_NAME == 'midflip'
|
407
|
+
#should be fine to take out in a month or so, just got lazy and pretty sure I am the only one using this gem.
|
408
|
+
#dont want to kill me jobs.
|
409
|
+
hgid_string = hgid_string.gsub('ApplicationRecord', 'Record')
|
410
|
+
end
|
406
411
|
if hgid_string.include?('@')
|
407
412
|
hgid_string = hgid_string.split('@')
|
408
413
|
hgid_string.pop
|
@@ -438,7 +443,7 @@ module DynamicRecordsMeritfront
|
|
438
443
|
nil
|
439
444
|
else
|
440
445
|
#stops execution as default
|
441
|
-
raise StandardError.new 'Not the expected class
|
446
|
+
raise StandardError.new 'Not the expected class or subclass.'
|
442
447
|
end
|
443
448
|
end
|
444
449
|
def get_hgid_tag(hgid_string)
|
@@ -472,7 +477,6 @@ module DynamicRecordsMeritfront
|
|
472
477
|
# - multi_query allows more than one query (you can seperate an insert and an update with ';' I dont know how else to say it.)
|
473
478
|
# this disables other options (except name_modifiers). Not sure how it effects prepared statements. Its a fairly useless
|
474
479
|
# command as you can do multiple queries anyway with 'WITH' statements and also gain the other options.
|
475
|
-
# - async does what it says but I haven't used it yet so. Probabably doesn't work
|
476
480
|
# - raw switches between using a Hash or a ActiveRecord::Response object when used on a abstract class
|
477
481
|
args << {} unless args[-1].kind_of? Hash
|
478
482
|
if args.length == 3
|
@@ -496,7 +500,6 @@ module DynamicRecordsMeritfront
|
|
496
500
|
name_modifiers ||= []
|
497
501
|
prepare = opts.delete(:prepare) != false
|
498
502
|
multi_query = opts.delete(:multi_query) == true
|
499
|
-
async = opts.delete(:async) == true
|
500
503
|
params = opts
|
501
504
|
|
502
505
|
#unique value hash cuts down on the number of repeated arguments like in an update or insert statement
|
@@ -552,7 +555,7 @@ module DynamicRecordsMeritfront
|
|
552
555
|
end
|
553
556
|
end
|
554
557
|
sql_vals = var_track.get_array_for_exec_query
|
555
|
-
ret = ActiveRecord::Base.connection.exec_query sql, name, sql_vals, prepare: prepare
|
558
|
+
ret = ActiveRecord::Base.connection.exec_query sql, name, sql_vals, prepare: prepare
|
556
559
|
else
|
557
560
|
ret = ActiveRecord::Base.connection.execute sql, name
|
558
561
|
end
|
@@ -562,14 +565,12 @@ module DynamicRecordsMeritfront
|
|
562
565
|
sql ||= ''
|
563
566
|
sql_vals ||= ''
|
564
567
|
prepare ||= ''
|
565
|
-
async ||= ''
|
566
568
|
Rails.logger.error(%Q{
|
567
569
|
DynamicRecords#dynamic_sql debug info.
|
568
570
|
name: #{name.to_s}
|
569
571
|
sql: #{sql.to_s}
|
570
572
|
sql_vals: #{sql_vals.to_s}
|
571
573
|
prepare: #{prepare.to_s}
|
572
|
-
async: #{async.to_s}
|
573
574
|
})
|
574
575
|
raise e
|
575
576
|
end
|
@@ -654,37 +655,31 @@ module DynamicRecordsMeritfront
|
|
654
655
|
insta_array = insta_array.select{|ar| not ar[:dont_return]}
|
655
656
|
ret_hash = insta_array.map{|ar| [ar[:table_name].to_s, []]}.to_h
|
656
657
|
opts[:raw] = true
|
657
|
-
|
658
|
+
|
659
|
+
#annoying bug
|
660
|
+
s = self
|
661
|
+
unless s.abstract_class?
|
662
|
+
s = s.superclass
|
663
|
+
end
|
664
|
+
|
665
|
+
s.dynamic_sql(name, sql, opts).rows.each{|row|
|
658
666
|
#need to pre-parsed as it has a non-normal output.
|
659
667
|
table_name = row[2]
|
660
668
|
klass = row[1].constantize
|
661
669
|
json = row[0]
|
662
670
|
parsed = JSON.parse(json)
|
663
|
-
|
664
671
|
ret_hash[table_name].push dynamic_init(klass, parsed)
|
665
672
|
}
|
666
673
|
|
667
|
-
insta_array
|
674
|
+
insta_array.each{|a| a.delete(:sql)}
|
668
675
|
|
669
676
|
#formatting options
|
670
677
|
for insta in insta_array
|
671
678
|
if insta[:base_name]
|
672
679
|
#in this case, 'as' is meant as to what pseudonym to dynamicly attach it as
|
673
|
-
|
680
|
+
#we are attaching to the base table. Variable could of been less confusing. My bad.
|
681
|
+
dynamic_attach(ret_hash, insta[:base_name], insta[:table_name], base_on: insta[:base_on], attach_on: insta[:attach_on],
|
674
682
|
one_to_one: insta[:one_to_one], as: insta[:as])
|
675
|
-
|
676
|
-
if Rails.logger.level <= 1
|
677
|
-
tn = insta[:table_name]
|
678
|
-
bn = insta[:base_name]
|
679
|
-
tc = ret_hash[tn].count
|
680
|
-
btc = ret_hash[bn].count
|
681
|
-
|
682
|
-
if insta[:as]
|
683
|
-
Rails.logger.debug "#{n_attached} attached from #{tn}(#{tc}) as #{insta[:as]} -> #{bn}(#{btc})"
|
684
|
-
else
|
685
|
-
Rails.logger.debug "#{n_attached} attached from #{tn}(#{tc}) -> #{bn}(#{btc})"
|
686
|
-
end
|
687
|
-
end
|
688
683
|
elsif insta[:as]
|
689
684
|
Rails.logger.debug "#{insta[:table_name]} as #{insta[:as]}"
|
690
685
|
#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
|
@@ -708,7 +703,7 @@ module DynamicRecordsMeritfront
|
|
708
703
|
m = model_with_an_id_column_and_timestamps
|
709
704
|
ar = m.superclass
|
710
705
|
mtname = m.table_name
|
711
|
-
|
706
|
+
transaction do
|
712
707
|
puts 'test recieving columns not normally in the record.'
|
713
708
|
rec = m.dynamic_sql(%Q{
|
714
709
|
SELECT id, 5 AS random_column from #{mtname} LIMIT 10
|
@@ -800,12 +795,23 @@ module DynamicRecordsMeritfront
|
|
800
795
|
def dynamic_attach(instaload_sql_output, base_name, attach_name, base_on: nil, attach_on: nil, one_to_one: false, as: nil)
|
801
796
|
#as just lets it attach us anywhere on the base class, and not just as the attach_name.
|
802
797
|
#Can be useful in polymorphic situations, otherwise may lead to confusion.
|
798
|
+
|
799
|
+
#oh the errors
|
800
|
+
base_name = base_name.to_s
|
801
|
+
attach_name = attach_name.to_s
|
802
|
+
|
803
803
|
as ||= attach_name
|
804
804
|
|
805
805
|
base_arr = instaload_sql_output[base_name]
|
806
806
|
|
807
807
|
#return if there is nothing for us to attach to.
|
808
|
-
|
808
|
+
if base_arr.nil?
|
809
|
+
Rails.logger.error("base table " + base_name + " was not set")
|
810
|
+
return 0
|
811
|
+
elsif not base_arr.any?
|
812
|
+
Rails.logger.debug("no items in base table " + base_name)
|
813
|
+
return 0
|
814
|
+
end
|
809
815
|
|
810
816
|
#set variables for neatness and so we dont compute each time
|
811
817
|
# base class information
|
@@ -830,7 +836,14 @@ module DynamicRecordsMeritfront
|
|
830
836
|
|
831
837
|
#make sure the attach class has something going on. We do this after the default stage
|
832
838
|
attach_arr = instaload_sql_output[attach_name]
|
833
|
-
|
839
|
+
|
840
|
+
if attach_arr.nil?
|
841
|
+
Rails.logger.error("attaching table " + attach_name + " was not set")
|
842
|
+
return 0
|
843
|
+
elsif not attach_arr.any?
|
844
|
+
Rails.logger.debug("no items in attach table " + attach_name)
|
845
|
+
return 0
|
846
|
+
end
|
834
847
|
|
835
848
|
# attach class information
|
836
849
|
attach_class = attach_arr.first.class
|
@@ -934,6 +947,14 @@ module DynamicRecordsMeritfront
|
|
934
947
|
end
|
935
948
|
}
|
936
949
|
|
950
|
+
if Rails.logger.level <= 1
|
951
|
+
if as
|
952
|
+
Rails.logger.debug "#{x}/#{attach_arr.count} attached from #{attach_name} as #{as} -> #{base_name}(#{x}/#{base_arr.count})"
|
953
|
+
else
|
954
|
+
Rails.logger.debug "#{x}/#{attach_arr.count} attached from #{attach_name} -> #{base_name}(#{x}/#{base_arr.count})"
|
955
|
+
end
|
956
|
+
end
|
957
|
+
|
937
958
|
return x
|
938
959
|
end
|
939
960
|
alias swiss_attach dynamic_attach
|
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.1.
|
4
|
+
version: 3.1.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Clancy
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashid-rails
|
@@ -54,7 +54,7 @@ metadata:
|
|
54
54
|
homepage_uri: https://github.com/LukeClancy/dynamic-records-meritfront
|
55
55
|
source_code_uri: https://github.com/LukeClancy/dynamic-records-meritfront
|
56
56
|
changelog_uri: https://github.com/LukeClancy/dynamic-records-meritfront/blob/main/README.md
|
57
|
-
post_install_message:
|
57
|
+
post_install_message:
|
58
58
|
rdoc_options: []
|
59
59
|
require_paths:
|
60
60
|
- lib
|
@@ -69,8 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
|
-
rubygems_version: 3.
|
73
|
-
signing_key:
|
72
|
+
rubygems_version: 3.4.10
|
73
|
+
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: Helpers for active record that allow for more abstract and fine-grained code.
|
76
76
|
test_files: []
|