laserlemon-nullify 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -37,9 +37,3 @@ In your controller:
37
37
  In your "show" view:
38
38
 
39
39
  <%=h @user.name %>
40
-
41
- == Tips
42
-
43
- * Performs its nullification before validation, allowing for easy use of +allow_nil+ validation options
44
- * Uses ActiveRecord's dynamic getters and setters, meaning it will also work for your own custom, non-column getters/setters
45
- * Works for non-string attributes that respond to <tt>blank?</tt>
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('nullify', '0.1.0') do |g|
5
+ Echoe.new('nullify', '0.2.0') do |g|
6
6
  g.description = %(Nuke blank values in ActiveRecord models)
7
7
  g.url = 'http://github.com/laserlemon/nullify'
8
8
  g.author = 'Steve Richert'
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 1
3
+ :minor: 2
4
4
  :patch: 0
data/init.rb CHANGED
@@ -1 +1 @@
1
- require 'nullify'
1
+ require 'nullify'
data/lib/nullify.rb CHANGED
@@ -8,16 +8,25 @@ module LaserLemon
8
8
  def nullify(*columns)
9
9
  write_inheritable_array :nullified_columns, columns.map(&:to_sym)
10
10
  class_inheritable_reader :nullified_columns
11
+
12
+ columns.each do |column|
13
+ define_method "#{column}=" do |value|
14
+ write_attribute(column, value.blank? ? nil : value)
15
+ end
16
+ end
17
+
11
18
  include InstanceMethods
19
+
12
20
  before_validation :nullify_columns
21
+ before_save :nullify_columns
13
22
  end
14
23
  end
15
24
 
16
25
  module InstanceMethods
17
26
  def nullify_columns
18
27
  self.class.nullified_columns.each do |column|
19
- value = send(column)
20
- send("#{column}=", nil) if value.blank? && !value.nil?
28
+ value = read_attribute(column)
29
+ write_attribute(column, nil) if !value.nil? && value.blank?
21
30
  end
22
31
  end
23
32
  end
data/nullify.gemspec CHANGED
@@ -2,27 +2,26 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{nullify}
5
- s.version = "0.1.0"
5
+ s.version = "0.2.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Steve Richert"]
9
- s.date = %q{2009-04-28}
9
+ s.date = %q{2009-06-16}
10
10
  s.description = %q{Nuke blank values in ActiveRecord models}
11
11
  s.email = %q{steve@laserlemon.com}
12
12
  s.extra_rdoc_files = ["lib/nullify.rb", "README.rdoc", "tasks/nullify_tasks.rake"]
13
13
  s.files = ["init.rb", "lib/nullify.rb", "Manifest", "MIT-LICENSE", "nullify.gemspec", "Rakefile", "README.rdoc", "tasks/nullify_tasks.rake", "test/nullify_test.rb", "test/test_helper.rb", "VERSION.yml"]
14
- s.has_rdoc = true
15
14
  s.homepage = %q{http://github.com/laserlemon/nullify}
16
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Nullify", "--main", "README.rdoc"]
17
16
  s.require_paths = ["lib"]
18
17
  s.rubyforge_project = %q{nullify}
19
- s.rubygems_version = %q{1.3.1}
18
+ s.rubygems_version = %q{1.3.4}
20
19
  s.summary = %q{Nuke blank values in ActiveRecord models}
21
20
  s.test_files = ["test/nullify_test.rb", "test/test_helper.rb"]
22
21
 
23
22
  if s.respond_to? :specification_version then
24
23
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
- s.specification_version = 2
24
+ s.specification_version = 3
26
25
 
27
26
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
27
  else
@@ -18,8 +18,8 @@ task :nullify => :environment do
18
18
  get_class and get_columns
19
19
  @class.all.each do |instance|
20
20
  @columns.each do |column|
21
- value = instance.send(column)
22
- instance.send("#{column}=", nil) if value.blank? && !value.nil?
21
+ value = instance[column]
22
+ instance[column] = nil if !value.nil? && value.blank?
23
23
  end
24
24
  instance.save
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: laserlemon-nullify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Richert
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-28 00:00:00 -07:00
12
+ date: 2009-06-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -35,7 +35,7 @@ files:
35
35
  - test/nullify_test.rb
36
36
  - test/test_helper.rb
37
37
  - VERSION.yml
38
- has_rdoc: true
38
+ has_rdoc: false
39
39
  homepage: http://github.com/laserlemon/nullify
40
40
  post_install_message:
41
41
  rdoc_options:
@@ -64,7 +64,7 @@ requirements: []
64
64
  rubyforge_project: nullify
65
65
  rubygems_version: 1.2.0
66
66
  signing_key:
67
- specification_version: 2
67
+ specification_version: 3
68
68
  summary: Nuke blank values in ActiveRecord models
69
69
  test_files:
70
70
  - test/nullify_test.rb