dynamic-records-meritfront 2.0.16 → 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: fa19593097842159f3b5f7b387a3ae2771ac0ce89edfa94ca83a3ca4065418b7
4
- data.tar.gz: e3294816f249639df5bbdc64346cc625c2eeda98c8c12baa9a0c75a451acfd34
3
+ metadata.gz: c23065ffa740c578b38c7311ada210295ad2b876240480109913eff333a7c7b6
4
+ data.tar.gz: e38654aeb1f6e5f3d8a91a334b0489847674bde43451a7bb7f641770f5f061fb
5
5
  SHA512:
6
- metadata.gz: 20307306744813447e04c58df7ed54fce62de160acbda99e0fbe0a7b208572fadf8ef8195600eac292d0cc7684da14a2072ef00a728d1f9d706b8d209aa44382
7
- data.tar.gz: 4de4c710212960930835a7a1cf2a699a8fdbc7931ac57895557affce1b34ac49d505d7cbc7fefc6d82f08e2961e11357c9b00d0afbc57f8101fadf46e4c4e8ce
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.16)
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.16'
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,7 +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
- x.method(default_attach_col).call
501
+ x.attributes[default_attach_col]
535
502
  }
536
503
  end
537
504
  end
@@ -549,21 +516,9 @@ module DynamicRecordsMeritfront
549
516
  #(b=base, a=attach)
550
517
  add_to_base = Proc.new{|b, a|
551
518
  if one_to_one
552
- if base_class_is_hash
553
- b[attach_name] = a
554
- else
555
- b.dynamic ||= OpenStruct.new
556
- b.dynamic[attach_name] = a
557
- #b.instance_variable_set(attach_name_with_at, a)
558
- end
519
+ b[attach_name] = a
559
520
  else
560
- if base_class_is_hash
561
- b[attach_name].push a
562
- else
563
- # o.dynamic o.single
564
- b.dynamic[attach_name].push a
565
- #b.instance_variable_get(attach_name_with_at).push a
566
- end
521
+ b[attach_name].push a
567
522
  end
568
523
  }
569
524
 
@@ -594,12 +549,13 @@ module DynamicRecordsMeritfront
594
549
  if klass.abstract_class
595
550
  return input
596
551
  else
597
- #handle attributes through ar if allowed. Throws an error on unkown variables, except apparently for devise classes? 😡
598
- active_record_handled = input.slice(*(klass.attribute_names & input.keys))
599
- record = klass.instantiate(active_record_handled)
600
- #set those that were not necessarily expected
601
- not_expected = input.slice(*(input.keys - klass.attribute_names))
602
- 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?
603
559
  return record
604
560
  end
605
561
  end
@@ -646,4 +602,4 @@ module DynamicRecordsMeritfront
646
602
  self.class.where(id: self.id).update_all("#{col} = #{col} + #{val}")
647
603
  end
648
604
 
649
- end
605
+ 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.16
4
+ version: 2.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Clancy