property 2.3.0 → 2.3.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.
data/History.txt CHANGED
@@ -1,4 +1,9 @@
1
- == 2.3.0
1
+ == 2.3.1 2012-07-02
2
+
3
+ * Major enhancements
4
+ * Added support for hash property merge.
5
+
6
+ == 2.3.0 2012-05-23
2
7
 
3
8
  * Major enhancements
4
9
  * Fixed tests and sources for Ruby 1.9
@@ -6,7 +6,7 @@ module Property
6
6
  # such as name, type and options. It is also used to typecast from strings to
7
7
  # the proper type (date, integer, float, etc).
8
8
  class Column < ::ActiveRecord::ConnectionAdapters::Column
9
- attr_accessor :index
9
+ attr_accessor :index, :caster
10
10
 
11
11
  SAFE_NAMES_REGEXP = %r{\A[a-zA-Z_]+\Z}
12
12
 
@@ -54,7 +54,7 @@ module Property
54
54
  def changed
55
55
  changes.keys
56
56
  end
57
-
57
+
58
58
  def changes
59
59
  return {} unless @original_hash
60
60
  changes = {}
@@ -33,6 +33,18 @@ module Property
33
33
  else
34
34
  delete(key)
35
35
  end
36
+ elsif value.kind_of?(Hash) && column.klass <= Hash && column.caster.respond_to?(:merge_hash)
37
+ # We *MUST* duplicate hash here or Dirty will not function correctly.
38
+ value = column.caster.merge_hash(self[key].dup, value)
39
+ if value.blank?
40
+ if default = column.default_for(@owner)
41
+ super(key, default)
42
+ else
43
+ delete(key)
44
+ end
45
+ else
46
+ super(key, value)
47
+ end
36
48
  else
37
49
  super(key, column.type_cast(value))
38
50
  end
@@ -1,3 +1,3 @@
1
1
  module Property
2
- VERSION = '2.3.0'
2
+ VERSION = '2.3.1'
3
3
  end
data/property.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{property}
8
- s.version = "2.3.0"
8
+ s.version = "2.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Renaud Kern", "Gaspard Bucher"]
12
- s.date = %q{2012-05-23}
12
+ s.date = %q{2012-07-02}
13
13
  s.description = %q{Wrap model properties into a single database column and declare properties from within the model.}
14
14
  s.email = %q{gaspard@teti.ch}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: property
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 3
9
- - 0
10
- version: 2.3.0
9
+ - 1
10
+ version: 2.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Renaud Kern
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-05-23 00:00:00 +02:00
19
+ date: 2012-07-02 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency