activerecord-define_nils 0.0.2 → 0.0.3
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.
- checksums.yaml +15 -0
- data/README.md +1 -1
- data/lib/activerecord-define_nils/model.rb +21 -27
- data/lib/activerecord-define_nils/version.rb +1 -1
- metadata +5 -9
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjM4MjhjMmRiODg1MzViMmU0ZmJhZTNkNDM0Njk1OTdkN2U2YzY3Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTY1OGFjNzhjNjUwNGY5Yzk5ZGJiMmE2NGM0ZDVkZGM2MGRjNGVkNw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTVmMTk4MTFmY2NhMzk1OWRkMjY4OWI3ZDFmNmNhODRiOTI5Mjk1OGE2YzYx
|
10
|
+
NmUzYTgzZDM1YjcxOWJhOTE1MTM0MDYzZjRiZWEyZmU3OWJlY2RhNzAxZjVj
|
11
|
+
NGNhNmExMjZjZmIyODljNzRkZmI5YjJmZjUxNGI4YzIyOTE1NTU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MWMyNThlNzMxOWE5NWViYmU4OWJhYjBlZTNkNTQ1OTFkNmU5MWEyMGE2NDIy
|
14
|
+
OGRlNTQxNjMwODE3OTlmZDRiZjllZDNkMmM2YTM2MDg0MmYzODcwNDhiZGEw
|
15
|
+
ZjE3NDJmZDIwYTlmMGE3MjgwYjFkMjE0MjJjMGM2MDI0MmNmNGY=
|
data/README.md
CHANGED
@@ -47,6 +47,6 @@ Be sure to place `define_nils` above your `belongs_to` associations in the model
|
|
47
47
|
|
48
48
|
### License
|
49
49
|
|
50
|
-
Copyright (c)
|
50
|
+
Copyright (c) 2013 Gary S. Weaver, released under the [MIT license][lic].
|
51
51
|
|
52
52
|
[lic]: http://github.com/garysweaver/activerecord-define_nils/blob/master/LICENSE
|
@@ -23,7 +23,7 @@ module ActiveRecordDefineNils
|
|
23
23
|
class_eval "def #{attr_name}; value = super(); self.nil_definitions && self.nil_definitions[#{attr_sym.inspect}] && self.nil_definitions[#{attr_sym.inspect}].include?(value) ? nil : value; end"
|
24
24
|
end
|
25
25
|
else
|
26
|
-
raise ArgumentError.new("define_nils
|
26
|
+
raise ArgumentError.new("define_nils takes a hash with :as and :for keys, but got #{options.inspect}")
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -34,7 +34,7 @@ module ActiveRecordDefineNils
|
|
34
34
|
self.nil_definitions.keys.each do |attr_sym|
|
35
35
|
self.reflections.collect {|association_name, reflection|
|
36
36
|
if reflection.macro == :belongs_to && reflection.foreign_key.to_sym == attr_sym
|
37
|
-
class_eval "def #{association_name}; return nil if
|
37
|
+
class_eval "def #{association_name}; return nil if __send__(#{attr_sym.inspect}).nil?; super(); end"
|
38
38
|
end
|
39
39
|
}
|
40
40
|
end
|
@@ -44,45 +44,39 @@ module ActiveRecordDefineNils
|
|
44
44
|
|
45
45
|
def read_attribute(attr_name)
|
46
46
|
value = super(attr_name)
|
47
|
-
|
47
|
+
(@define_nils_no_read_mod ||= false) ? 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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
write_attribute(column.to_s, translated_nil)
|
59
|
-
end
|
53
|
+
@define_nils_no_read_mod = true
|
54
|
+
if self.nil_saved_as
|
55
|
+
self.nil_saved_as.each do |column, translated_nil|
|
56
|
+
if respond_to?(column) && respond_to?("#{column}=") && self.__send__(column).nil?
|
57
|
+
write_attribute(column.to_s, translated_nil)
|
60
58
|
end
|
61
59
|
end
|
62
|
-
|
63
|
-
result = super
|
64
|
-
ensure
|
65
|
-
remove_instance_variable(:@define_nils_no_read_mod)
|
66
60
|
end
|
67
|
-
|
61
|
+
|
62
|
+
super
|
63
|
+
ensure
|
64
|
+
@define_nils_no_read_mod = false
|
68
65
|
end
|
69
66
|
|
70
67
|
def update(*args)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
write_attribute(column.to_s, translated_nil)
|
77
|
-
end
|
68
|
+
@define_nils_no_read_mod = true
|
69
|
+
if self.nil_saved_as
|
70
|
+
self.nil_saved_as.each do |column, translated_nil|
|
71
|
+
if respond_to?(column) && respond_to?("#{column}=") && self.__send__(column).nil?
|
72
|
+
write_attribute(column.to_s, translated_nil)
|
78
73
|
end
|
79
74
|
end
|
80
|
-
|
81
|
-
result = super
|
82
|
-
ensure
|
83
|
-
remove_instance_variable(:@define_nils_no_read_mod)
|
84
75
|
end
|
85
|
-
|
76
|
+
|
77
|
+
super
|
78
|
+
ensure
|
79
|
+
@define_nils_no_read_mod = false
|
86
80
|
end
|
87
81
|
end
|
88
82
|
end
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-define_nils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Gary S. Weaver
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activerecord
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -44,26 +41,25 @@ files:
|
|
44
41
|
homepage: https://github.com/garysweaver/activerecord-define_nils
|
45
42
|
licenses:
|
46
43
|
- MIT
|
44
|
+
metadata: {}
|
47
45
|
post_install_message:
|
48
46
|
rdoc_options: []
|
49
47
|
require_paths:
|
50
48
|
- lib
|
51
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
50
|
requirements:
|
54
51
|
- - ! '>='
|
55
52
|
- !ruby/object:Gem::Version
|
56
53
|
version: '0'
|
57
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
55
|
requirements:
|
60
56
|
- - ! '>='
|
61
57
|
- !ruby/object:Gem::Version
|
62
58
|
version: '0'
|
63
59
|
requirements: []
|
64
60
|
rubyforge_project:
|
65
|
-
rubygems_version:
|
61
|
+
rubygems_version: 2.0.3
|
66
62
|
signing_key:
|
67
|
-
specification_version:
|
63
|
+
specification_version: 4
|
68
64
|
summary: Define nils for ActiveRecord 3.x/4.x.
|
69
65
|
test_files: []
|