strip_attributes 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,6 @@
1
1
  module StripAttributes
2
- VERSION = "0.9.0"
3
-
4
2
  # Strips whitespace from model fields and converts blank values to nil.
5
- def strip_attributes!(options = nil)
3
+ def strip_attributes(options = nil)
6
4
  before_validation do |record|
7
5
  attributes = StripAttributes.narrow(record.attributes, options)
8
6
  attributes.each do |attr, value|
@@ -13,6 +11,13 @@ module StripAttributes
13
11
  end
14
12
  end
15
13
 
14
+ # <b>DEPRECATED:</b> Please use <tt>strip_attributes</tt> (non-bang method)
15
+ # instead.
16
+ def strip_attributes!(options = nil)
17
+ warn "[DEPRECATION] `strip_attributes!` is deprecated. Please use `strip_attributes` (non-bang method) instead."
18
+ strip_attributes(options)
19
+ end
20
+
16
21
  # Necessary because Rails has removed the narrowing of attributes using :only
17
22
  # and :except on Base#attributes
18
23
  def self.narrow(attributes, options)
@@ -31,3 +36,5 @@ module StripAttributes
31
36
  end
32
37
  end
33
38
  end
39
+
40
+ require "strip_attributes/active_model"
@@ -0,0 +1,6 @@
1
+ require "strip_attributes"
2
+ require "active_model"
3
+
4
+ module ActiveModel::Validations::HelperMethods
5
+ include StripAttributes
6
+ end
@@ -0,0 +1,3 @@
1
+ module StripAttributes
2
+ VERSION = "1.0.0"
3
+ end
@@ -12,27 +12,27 @@ end
12
12
 
13
13
  class StripAllMockRecord < ActiveRecord::Base
14
14
  include MockAttributes
15
- strip_attributes!
15
+ strip_attributes
16
16
  end
17
17
 
18
18
  class StripOnlyOneMockRecord < ActiveRecord::Base
19
19
  include MockAttributes
20
- strip_attributes! :only => :foo
20
+ strip_attributes :only => :foo
21
21
  end
22
22
 
23
23
  class StripOnlyThreeMockRecord < ActiveRecord::Base
24
24
  include MockAttributes
25
- strip_attributes! :only => [:foo, :bar, :biz]
25
+ strip_attributes :only => [:foo, :bar, :biz]
26
26
  end
27
27
 
28
28
  class StripExceptOneMockRecord < ActiveRecord::Base
29
29
  include MockAttributes
30
- strip_attributes! :except => :foo
30
+ strip_attributes :except => :foo
31
31
  end
32
32
 
33
33
  class StripExceptThreeMockRecord < ActiveRecord::Base
34
34
  include MockAttributes
35
- strip_attributes! :except => [:foo, :bar, :biz]
35
+ strip_attributes :except => [:foo, :bar, :biz]
36
36
  end
37
37
 
38
38
  class StripAttributesTest < Test::Unit::TestCase
@@ -1,12 +1,6 @@
1
- require 'test/unit'
2
- require 'rubygems'
3
- require 'active_record'
4
- begin require 'redgreen' if ENV['TM_FILENAME'].nil?; rescue LoadError; end
5
-
6
- PLUGIN_ROOT = File.expand_path(File.join(File.dirname(__FILE__), ".."))
7
-
8
- $LOAD_PATH.unshift "#{PLUGIN_ROOT}/lib"
9
- load "#{PLUGIN_ROOT}/rails/init.rb"
1
+ require "test/unit"
2
+ require "active_record"
3
+ require "strip_attributes/active_model"
10
4
 
11
5
  class ActiveRecord::Base
12
6
  alias_method :save, :valid?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strip_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,16 +12,27 @@ cert_chain: []
12
12
  date: 2011-08-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: activerecord
16
- requirement: &70312180321220 !ruby/object:Gem::Requirement
15
+ name: activemodel
16
+ requirement: &70147633737260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '2.0'
21
+ version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70312180321220
24
+ version_requirements: *70147633737260
25
+ - !ruby/object:Gem::Dependency
26
+ name: activerecord
27
+ requirement: &70147633736480 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70147633736480
25
36
  description: StripAttributes automatically strips all ActiveRecord model attributes
26
37
  of leading and trailing whitespace before validation. If the attribute is blank,
27
38
  it strips the value to nil.
@@ -31,10 +42,11 @@ executables: []
31
42
  extensions: []
32
43
  extra_rdoc_files: []
33
44
  files:
45
+ - lib/strip_attributes/active_model.rb
34
46
  - lib/strip_attributes/shoulda/macros.rb
35
47
  - lib/strip_attributes/shoulda.rb
48
+ - lib/strip_attributes/version.rb
36
49
  - lib/strip_attributes.rb
37
- - rails/init.rb
38
50
  - test/strip_attributes_test.rb
39
51
  - test/test_helper.rb
40
52
  homepage: https://github.com/rmm5t/strip_attributes
@@ -51,7 +63,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
63
  version: '0'
52
64
  segments:
53
65
  - 0
54
- hash: 1913689736864890134
66
+ hash: -1674557352655608459
55
67
  required_rubygems_version: !ruby/object:Gem::Requirement
56
68
  none: false
57
69
  requirements:
@@ -60,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
72
  version: '0'
61
73
  segments:
62
74
  - 0
63
- hash: 1913689736864890134
75
+ hash: -1674557352655608459
64
76
  requirements: []
65
77
  rubyforge_project: strip_attributes
66
78
  rubygems_version: 1.8.7
@@ -1,2 +0,0 @@
1
- require 'strip_attributes'
2
- ActiveRecord::Base.extend(StripAttributes)