activerecord-define_nils 0.0.1 → 0.0.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.
@@ -44,33 +44,45 @@ module ActiveRecordDefineNils
44
44
 
45
45
  def read_attribute(attr_name)
46
46
  value = super(attr_name)
47
- self.nil_definitions && self.nil_definitions[attr_name.to_sym] && self.nil_definitions[attr_name.to_sym].include?(value) ? nil : value
47
+ defined?(@define_nils_no_read_mod) ? value : (self.nil_definitions && self.nil_definitions[attr_name.to_sym] && self.nil_definitions[attr_name.to_sym].include?(value) ? nil : value)
48
48
  end
49
49
 
50
50
  private
51
51
 
52
52
  def create
53
- if self.nil_saved_as
54
- self.nil_saved_as.each do |column, translated_nil|
55
- if respond_to?(column) && respond_to?("#{column}=") && self.send(column).nil?
56
- write_attribute(column.to_s, translated_nil)
53
+ instance_variable_set(:@define_nils_no_read_mod, true)
54
+ begin
55
+ if self.nil_saved_as
56
+ self.nil_saved_as.each do |column, translated_nil|
57
+ if respond_to?(column) && respond_to?("#{column}=") && self.send(column).nil?
58
+ write_attribute(column.to_s, translated_nil)
59
+ end
57
60
  end
58
61
  end
59
- end
60
62
 
61
- super
63
+ result = super
64
+ ensure
65
+ remove_instance_variable(:@define_nils_no_read_mod)
66
+ end
67
+ result
62
68
  end
63
69
 
64
70
  def update(*args)
65
- if self.nil_saved_as
66
- self.nil_saved_as.each do |column, translated_nil|
67
- if respond_to?(column) && respond_to?("#{column}=") && self.send(column).nil?
68
- write_attribute(column.to_s, translated_nil)
71
+ instance_variable_set(:@define_nils_no_read_mod, true)
72
+ begin
73
+ if self.nil_saved_as
74
+ self.nil_saved_as.each do |column, translated_nil|
75
+ if respond_to?(column) && respond_to?("#{column}=") && self.send(column).nil?
76
+ write_attribute(column.to_s, translated_nil)
77
+ end
69
78
  end
70
79
  end
80
+
81
+ result = super
82
+ ensure
83
+ remove_instance_variable(:@define_nils_no_read_mod)
71
84
  end
72
-
73
- super
85
+ result
74
86
  end
75
87
  end
76
88
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordDefineNils
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-define_nils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.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-11-27 00:00:00.000000000 Z
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord