scrubby 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -70,9 +70,7 @@ It's pretty straightforward, and there's nothing all that fancy happening behind
70
70
 
71
71
  Scrubbing happens only when attributes are set. That way, no time is wasted scrubbing every time an attribute is retrieved.
72
72
 
73
- For column attributes, the scrubbing is done at the +write_attribute+ level, without stepping on ActiveRecord's toes by creating a bunch of unnecessary setter methods.
74
-
75
- +scrubby+ also works with virtual attributes, simply by adding an +alias_method_chain+ to the corresponding setter method, so the original can still be accessed via <tt>attribute_without_scrub=</tt>.
73
+ Scrubbing is done at the +write_attribute+ level, without stepping on ActiveRecord's toes by creating a bunch of unnecessary setter methods.
76
74
 
77
75
  Inheritance is respected, just as you'd expect, down through model subclasses. Scrubbers are overridden in subclasses with no problem.
78
76
 
@@ -80,7 +78,7 @@ Inheritance is respected, just as you'd expect, down through model subclasses. S
80
78
 
81
79
  Those of you who are familiar with +attribute_normalizer+[http://github.com/mdeering/attribute_normalizer] will recognize the how +scrubby+ looks and feels, and that's no accident! +attribute_normalizer+ has a simple, clean and effective interface.
82
80
 
83
- But +scrubby+ was written to be an improvement on what's happening behind the scenes, particularly with regards to inheritance and avoiding unnecessary method definitions. Basically, the idea was to really clean up and simplify the back-end of an already awesome interface.
81
+ But +scrubby+ was written to be an improvement on what's happening behind the scenes, particularly with regards to inheritance and avoiding unnecessary method definitions. Basically, the idea was to really simplify the back-end of an already awesome interface, and to gear it specifically toward ActiveRecord.
84
82
 
85
83
  == Contributing
86
84
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -63,18 +63,6 @@ module Scrubby
63
63
  def scrub(*attributes, &block)
64
64
  scrubber = block_given? ? block : instance_method(:scrub)
65
65
  self.scrubbers = attributes.inject({}){|s,a| s.merge!(a.to_s => scrubber) }
66
-
67
- attributes.reject{|a| column_names.include?(a.to_s) }.each do |virtual_attribute|
68
- unless instance_methods.include?("#{virtual_attribute}_with_scrub=")
69
- define_method "#{virtual_attribute}_with_scrub=" do |value|
70
- scrubber = scrubbers[virtual_attribute.to_s]
71
- value = scrubber.bind(self).call(value)
72
- send("#{virtual_attribute}_without_scrub=", value)
73
- end
74
-
75
- alias_method_chain "#{virtual_attribute}=", :scrub
76
- end
77
- end
78
66
  end
79
67
  end
80
68
 
@@ -82,9 +70,6 @@ module Scrubby
82
70
  # An alias of the +write_attribute+ method, +write_attribute_with_scrub+ will check whether a
83
71
  # scrubber exists for the given attribute and if so, scrub the given value before passing it
84
72
  # on to the original +write_attribute+ method.
85
- #
86
- # This is used for column-based attributes, while virtual attributes are handled by aliasing
87
- # the corresponding setter methods and scrubbing there.
88
73
  def write_attribute_with_scrub(attribute, value)
89
74
  if scrubber = scrubbers[attribute.to_s]
90
75
  value = scrubber.bind(self).call(value)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{scrubby}
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Steve Richert"]
12
- s.date = %q{2010-01-24}
12
+ s.date = %q{2010-01-26}
13
13
  s.description = %q{Clean up your incoming ActiveRecord model attributes}
14
14
  s.email = %q{steve.richert@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -83,10 +83,16 @@ class TestScrubby < Test::Unit::TestCase
83
83
  @user = User.new
84
84
  end
85
85
 
86
- should 'clean the value' do
87
- middle_name = ' Joel Michael '
88
- @user.middle_name = middle_name
89
- assert_not_equal middle_name, @user.middle_name
86
+ should 'do nothing' do
87
+ assert_nothing_raised do
88
+ middle_name = ' Joel Michael '
89
+ @user.update_attributes(
90
+ :first_name => 'Stephen',
91
+ :middle_name => middle_name,
92
+ :last_name => 'Richert'
93
+ )
94
+ assert_equal middle_name, @user.middle_name
95
+ end
90
96
  end
91
97
  end
92
98
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrubby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.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: 2010-01-24 00:00:00 -05:00
12
+ date: 2010-01-26 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency