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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 122854ead22d0622151522249d115b088dc1ecd4d21fe9a794a23126ab105d65
4
- data.tar.gz: 216371aab9c74e6a9a0c3638d0436cfc0f83e72f7668c7c57a3f73dc20876c19
3
+ metadata.gz: c23065ffa740c578b38c7311ada210295ad2b876240480109913eff333a7c7b6
4
+ data.tar.gz: e38654aeb1f6e5f3d8a91a334b0489847674bde43451a7bb7f641770f5f061fb
5
5
  SHA512:
6
- metadata.gz: d4d2ab247cf4cff13fad1f772cc437585aeb28a59686b4ff0046a7bffd2466c944749c1ab22fdc058b02150043d4e05515e0d5b5d962c78b84c02d9b8985618f
7
- data.tar.gz: 6f962c2213eedc0441a38002e5ce5770ec932e6ee0c36faa2ff9c965abfa56502ad8e56accade17d94216b8c6025883e6276f65515d6886aa09681ec11f713e4
6
+ metadata.gz: 63eb8b2cf1342d742e77140091583201dea03dccad9edb8aa78201d663eec39a352e9741978e967ba5fe8b0bfc461478328fe1e0dde46bba434b36495e3842fc
7
+ data.tar.gz: 35cd5e867cd6853b7614ce0d67c2253794f31b03af59c0e7189a66bca30c4e8f7eaa984858a2bb659607c60b8dc8b4a29ed9ba9bc5d944435ab38a425283db01
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dynamic-records-meritfront (2.0.17)
4
+ dynamic-records-meritfront (2.0.19)
5
5
  hashid-rails
6
6
 
7
7
  GEM
@@ -1,5 +1,5 @@
1
1
 
2
2
  module DynamicRecordsMeritfront
3
- VERSION = '2.0.17'
3
+ VERSION = '2.0.19'
4
4
  end
5
5
  #this file gets overwritten automatically on minor updates, major ones need to be manually 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
- unless one_to_one or base_class_is_hash
496
- o.dynamic ||= OpenStruct.new
497
- o.dynamic[attach_name_sym] = []
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
- ret = x.attributes[default_attach_col]
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
- if base_class_is_hash
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
- if base_class_is_hash
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
- #handle attributes through ar if allowed. Throws an error on unkown variables, except apparently for devise classes? 😡
600
- active_record_handled = input.slice(*(klass.attribute_names & input.keys))
601
- record = klass.instantiate(active_record_handled)
602
- #set those that were not necessarily expected
603
- not_expected = input.slice(*(input.keys - klass.attribute_names))
604
- record.dynamic = OpenStruct.new(not_expected.transform_keys{|k|k.to_sym}) if not_expected.keys.any?
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic-records-meritfront
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.17
4
+ version: 2.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Clancy