nilify_blanks 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzNlZTg1MTRiOGE2OTllOTYyZWNkYTU5NGJlMDJiOTQ5Mjg2MTQ0MA==
5
+ data.tar.gz: !binary |-
6
+ NWY2MDA4NzljZjVhN2VkNDlmMzIyOTMyYTljYzZhMDFlY2E5MTUwZg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YmIyZTQzNzllM2YzMzJiNGUyNzI3OGM5MDlhM2Q1N2QwMjE2YzkxNDhhN2Qx
10
+ ZWNiZWIzMDM4ZDc4ZGIyYzY1YjY1MDA0NmEwZDk1OGEwZTc1OTI1YmI0Njkz
11
+ YzAwMDY2ZjczZGM4NTYzNDQ4ZmE4YmYxYWQ2NjRhNDlkOWQ2ZTc=
12
+ data.tar.gz: !binary |-
13
+ OGI4Y2VhMzkwMDFlZjdmMDM2ODMwM2Q0YmM1ZDhlYTM5NWMxNWQwNzVhZjMx
14
+ ODFlNjQzNTg0MjAzN2UxOTI2NTIzYzlmMjI4NDVkZjQyMWFkNDc3MWNkYThj
15
+ ZmY1NThjOWU3YjIwNWU1MjQ5NWJiNzk5YWRlNzlkYThhNDc1MGU=
data/Appraisals CHANGED
@@ -11,5 +11,5 @@ appraise "3.2" do
11
11
  end
12
12
 
13
13
  appraise "4.0" do
14
- gem "rails", "~> 4.0.0.beta1"
14
+ gem "rails", "~> 4.0.0"
15
15
  end
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,7 @@
1
+ == [2013-08-25] 1.0.2
2
+
3
+ * Hook on AR::Base.define_attribute_methods in order to prevent eager load of models [byroot]
4
+
1
5
  == [2010-10-15] 1.0.0 Major Updates
2
6
 
3
7
  * Finally updated to be a Gem
data/Gemfile.lock CHANGED
@@ -1,32 +1,38 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nilify_blanks (1.0.0)
4
+ nilify_blanks (1.0.2)
5
5
  activerecord (>= 3.0.0)
6
6
  activesupport (>= 3.0.0)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- activemodel (3.2.12)
12
- activesupport (= 3.2.12)
13
- builder (~> 3.0.0)
14
- activerecord (3.2.12)
15
- activemodel (= 3.2.12)
16
- activesupport (= 3.2.12)
17
- arel (~> 3.0.2)
18
- tzinfo (~> 0.3.29)
19
- activesupport (3.2.12)
20
- i18n (~> 0.6)
21
- multi_json (~> 1.0)
22
- appraisal (0.5.1)
11
+ activemodel (4.0.0)
12
+ activesupport (= 4.0.0)
13
+ builder (~> 3.1.0)
14
+ activerecord (4.0.0)
15
+ activemodel (= 4.0.0)
16
+ activerecord-deprecated_finders (~> 1.0.2)
17
+ activesupport (= 4.0.0)
18
+ arel (~> 4.0.0)
19
+ activerecord-deprecated_finders (1.0.3)
20
+ activesupport (4.0.0)
21
+ i18n (~> 0.6, >= 0.6.4)
22
+ minitest (~> 4.2)
23
+ multi_json (~> 1.3)
24
+ thread_safe (~> 0.1)
25
+ tzinfo (~> 0.3.37)
26
+ appraisal (0.5.2)
23
27
  bundler
24
28
  rake
25
- arel (3.0.2)
26
- builder (3.0.4)
29
+ arel (4.0.0)
30
+ atomic (1.0.1)
31
+ builder (3.1.4)
27
32
  diff-lcs (1.2.1)
28
- i18n (0.6.4)
29
- multi_json (1.6.1)
33
+ i18n (0.6.5)
34
+ minitest (4.7.5)
35
+ multi_json (1.7.9)
30
36
  rake (10.0.3)
31
37
  rspec (2.13.0)
32
38
  rspec-core (~> 2.13.0)
@@ -37,13 +43,15 @@ GEM
37
43
  diff-lcs (>= 1.1.3, < 2.0)
38
44
  rspec-mocks (2.13.0)
39
45
  sqlite3 (1.3.7)
40
- tzinfo (0.3.35)
46
+ thread_safe (0.1.0)
47
+ atomic
48
+ tzinfo (0.3.37)
41
49
 
42
50
  PLATFORMS
43
51
  ruby
44
52
 
45
53
  DEPENDENCIES
46
- appraisal (~> 0.5.1)
54
+ appraisal (~> 0.5.2)
47
55
  nilify_blanks!
48
56
  rake (~> 10.0.3)
49
57
  rspec (~> 2.13)
data/lib/nilify_blanks.rb CHANGED
@@ -2,46 +2,54 @@ module NilifyBlanks
2
2
  def self.included(base)
3
3
  base.extend ClassMethods
4
4
  end
5
-
5
+
6
6
  module ClassMethods
7
+
8
+ def define_attribute_methods
9
+ super
10
+ define_nilify_blank_methods
11
+ end
12
+
7
13
  def nilify_blanks(options = {})
8
14
  return if self.included_modules.include?(NilifyBlanks::InstanceMethods)
9
- return unless self.table_exists?
10
-
15
+
11
16
  include NilifyBlanks::InstanceMethods
12
-
13
- if options[:only]
14
- options[:only] = [options[:only]] unless options[:only].is_a?(Array)
15
- options[:only] = options[:only].map(&:to_s)
16
- end
17
-
18
- if options[:except]
19
- options[:except] = [options[:except]] unless options[:except].is_a?(Array)
20
- options[:except] = options[:except].map(&:to_s)
21
- end
22
-
17
+
18
+ @_nilify_blanks_options = options
19
+ end
20
+
21
+ private
22
+
23
+ def define_nilify_blank_methods
24
+ return unless @_nilify_blanks_options
25
+
26
+ options = @_nilify_blanks_options
27
+ options[:only] = Array.wrap(options[:only]).map(&:to_s) if options[:only]
28
+ options[:except] = Array.wrap(options[:except]).map(&:to_s) if options[:except]
29
+
23
30
  cattr_accessor :nilify_blanks_columns
24
-
31
+
25
32
  if options[:only]
26
33
  self.nilify_blanks_columns = options[:only].clone
27
34
  else
28
- self.nilify_blanks_columns = self.content_columns.reject {|c| !c.null }.map {|c| c.name.to_s }
35
+ self.nilify_blanks_columns = self.content_columns.select(&:null).map(&:name).map(&:to_s)
29
36
  end
30
37
  self.nilify_blanks_columns -= options[:except] if options[:except]
31
38
  self.nilify_blanks_columns = self.nilify_blanks_columns.map(&:to_s)
32
-
39
+
33
40
  options[:before] ||= :save
34
- class_eval "before_#{options[:before]} :nilify_blanks"
41
+ send("before_#{options[:before]}", :nilify_blanks)
35
42
  end
43
+
36
44
  end
37
-
45
+
38
46
  module InstanceMethods
39
47
  def nilify_blanks
40
48
  (self.nilify_blanks_columns || []).each do |column|
41
49
  value = read_attribute(column)
42
50
  next unless value.is_a?(String)
43
- next unless value.nil? or !value.respond_to?(:blank)
44
-
51
+ next unless value.respond_to?(:blank?)
52
+
45
53
  write_attribute(column, nil) if value.blank?
46
54
  end
47
55
  end
@@ -1,3 +1,3 @@
1
1
  module NilifyBlanks
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
data/spec/db/test.sqlite3 CHANGED
Binary file
metadata CHANGED
@@ -1,82 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nilify_blanks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
5
- prerelease:
4
+ version: 1.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ben Hughes
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-21 00:00:00.000000000 Z
11
+ date: 2013-08-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
- requirement: &70350387392160 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.0.0
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70350387392160
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: activerecord
27
- requirement: &70350387391160 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ! '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: 3.0.0
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *70350387391160
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: rake
38
- requirement: &70350387390600 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
45
  - - ~>
42
46
  - !ruby/object:Gem::Version
43
47
  version: 10.0.3
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *70350387390600
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 10.0.3
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: rspec
49
- requirement: &70350387390060 !ruby/object:Gem::Requirement
50
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
59
  - - ~>
53
60
  - !ruby/object:Gem::Version
54
61
  version: '2.13'
55
62
  type: :development
56
63
  prerelease: false
57
- version_requirements: *70350387390060
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.13'
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: appraisal
60
- requirement: &70350387389540 !ruby/object:Gem::Requirement
61
- none: false
71
+ requirement: !ruby/object:Gem::Requirement
62
72
  requirements:
63
73
  - - ~>
64
74
  - !ruby/object:Gem::Version
65
- version: 0.5.1
75
+ version: 0.5.2
66
76
  type: :development
67
77
  prerelease: false
68
- version_requirements: *70350387389540
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.5.2
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: sqlite3
71
- requirement: &70350387389040 !ruby/object:Gem::Requirement
72
- none: false
85
+ requirement: !ruby/object:Gem::Requirement
73
86
  requirements:
74
87
  - - ~>
75
88
  - !ruby/object:Gem::Version
76
89
  version: 1.3.6
77
90
  type: :development
78
91
  prerelease: false
79
- version_requirements: *70350387389040
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.6
80
97
  description: Often times you'll end up with empty strings where you really want nil
81
98
  at the database level. This plugin automatically converts blanks to nil and is
82
99
  configurable.
@@ -103,27 +120,26 @@ files:
103
120
  - init.rb
104
121
  homepage: http://github.com/rubiety/nilify_blanks
105
122
  licenses: []
123
+ metadata: {}
106
124
  post_install_message:
107
125
  rdoc_options: []
108
126
  require_paths:
109
127
  - lib
110
128
  required_ruby_version: !ruby/object:Gem::Requirement
111
- none: false
112
129
  requirements:
113
130
  - - ! '>='
114
131
  - !ruby/object:Gem::Version
115
132
  version: '0'
116
133
  required_rubygems_version: !ruby/object:Gem::Requirement
117
- none: false
118
134
  requirements:
119
135
  - - ! '>='
120
136
  - !ruby/object:Gem::Version
121
137
  version: 1.3.4
122
138
  requirements: []
123
139
  rubyforge_project: nilify_blanks
124
- rubygems_version: 1.8.16
140
+ rubygems_version: 2.0.6
125
141
  signing_key:
126
- specification_version: 3
142
+ specification_version: 4
127
143
  summary: Auto-convert blank fields to nil.
128
144
  test_files: []
129
145
  has_rdoc: