has_versions 0.6.1 → 0.6.2

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.
data/has_versions.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "has_versions"
4
- s.version = '0.6.1'
4
+ s.version = '0.6.2'
5
5
 
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Grant Rodgers"]
@@ -2,18 +2,20 @@ module HasVersions
2
2
  module Version
3
3
  module Diff
4
4
  def diff(original = parent)
5
- original_snapshot = original.nil? ? {} : original.decoded_snapshot
5
+ diff_fetch(original) do
6
+ original_snapshot = original.nil? ? {} : original.decoded_snapshot
6
7
 
7
- output = {}
8
- decoded_snapshot.each do |attribute, new_value|
9
- original_value = original_snapshot[attribute]
8
+ output = {}
9
+ decoded_snapshot.each do |attribute, new_value|
10
+ original_value = original_snapshot[attribute]
10
11
 
11
- if original_value != new_value
12
- output[attribute] = [original_value, new_value]
12
+ if original_value != new_value
13
+ output[attribute] = [original_value, new_value]
14
+ end
13
15
  end
14
- end
15
16
 
16
- output
17
+ output
18
+ end
17
19
  end
18
20
 
19
21
  def modified_attributes
@@ -35,6 +37,12 @@ module HasVersions
35
37
  decoded
36
38
  end
37
39
  end
40
+
41
+ private
42
+ def diff_fetch(original)
43
+ @diff_cache ||= {}
44
+ @diff_cache[original] ||= yield
45
+ end
38
46
  end
39
47
  end
40
48
  end
@@ -16,7 +16,7 @@ module HasVersions
16
16
  attr_accessor :name
17
17
  versioning_configuration.attribute :name
18
18
  versioning_configuration.associated_versions do
19
- "hola"
19
+ ["hola"]
20
20
  end
21
21
  end.new(name: 'wee')
22
22
 
@@ -24,7 +24,7 @@ module HasVersions
24
24
 
25
25
  assert_kind_of TestVersion, version
26
26
  assert_equal record, version.target
27
- assert_equal "hola", version.associated_versions
27
+ assert_equal ["hola"], version.associated_versions
28
28
  assert_equal record.versioned_attributes, version.snapshot
29
29
  end
30
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_versions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-25 00:00:00.000000000 Z
12
+ date: 2012-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport