dynamini 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dynamini/base.rb +13 -1
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b2c47d2bbbe481f882f553c5be6bbd19e55c3ea
4
- data.tar.gz: 896d9cf814087ab94a553b6442544b08736d4936
3
+ metadata.gz: 1cfd29b26d58f37ee6bf6e073e47f229fc8590aa
4
+ data.tar.gz: 747642490e8b3ad5318fd66380539fc859ee8d14
5
5
  SHA512:
6
- metadata.gz: 1fa38ebcab26e62bc0b8096d1aacf64d067589f50a4ddd37dce1fb6a3566d8201ea4a81719672c6c18531e02891c871fe590105b09f34b401aee3cf5aabfa9b1
7
- data.tar.gz: 0430d5c20bd42e61bb99c9ce7765aae89eb05899aaa08e9248ef0b9d87c9f6d118049d8d273f6d4e4ac7f1be2c13fd80ab125c3d4b92c558e1166ff3b8b4f5df
6
+ metadata.gz: 8c8e6686bf978250c59332eb9386fcf08687ffa29283b1b8c546b905b53c207463ac68c011d0e90ddffb7d0044bfdec9642e09a8ee97558d3aa22f8f1edd6c2b
7
+ data.tar.gz: ff60046e52efc340c90982c4c7a44bf43ce9a3ada72be5668d1c8431d9046861d4a92e558cc2bfb992221675b7fea1167afc2a270014b8023a27bb204422625a
@@ -433,6 +433,8 @@ module Dynamini
433
433
  attribute = name[0..-2].to_sym
434
434
  new_value = args.first
435
435
  write_attribute(attribute, new_value)
436
+ elsif was_method?(name)
437
+ __was(name)
436
438
  elsif read_method?(name)
437
439
  read_attribute(name)
438
440
  else
@@ -448,6 +450,10 @@ module Dynamini
448
450
  name =~ /^([a-zA-Z][-_\w]*)=.*$/
449
451
  end
450
452
 
453
+ def was_method?(name)
454
+ read_method?(name.to_s) && name.to_s.end_with?('_was')
455
+ end
456
+
451
457
  def self.define_handled_getter(column, format_class, options = {})
452
458
  proc = GETTER_PROCS[format_class]
453
459
  fail 'Unsupported data type: ' + format_class.to_s if proc.nil?
@@ -467,7 +473,7 @@ module Dynamini
467
473
  end
468
474
 
469
475
  def respond_to_missing?(name, include_private = false)
470
- @attributes.keys.include?(name) || write_method?(name) || super
476
+ @attributes.keys.include?(name) || write_method?(name) || was_method?(name) || super
471
477
  end
472
478
 
473
479
  def write_attribute(attribute, new_value, record_change = true)
@@ -497,6 +503,12 @@ module Dynamini
497
503
  value.is_a?(Array) ? value.map { |e| callback.call(e) } : callback.call(value)
498
504
  end
499
505
 
506
+ def __was(name)
507
+ attr_name = name[0..-5].to_sym
508
+ raise ArgumentError unless (@attributes[attr_name] || handles[attr_name])
509
+ @changes[attr_name].compact.present? ? @changes[attr_name][0] : read_attribute(attr_name)
510
+ end
511
+
500
512
  def handles
501
513
  self.class.handles
502
514
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamini
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Ward
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2015-12-10 00:00:00.000000000 Z
18
+ date: 2015-12-14 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activemodel