attr_cleaner 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +31 -0
- data/lib/attr_cleaner/module_mixin.rb +6 -1
- data/lib/attr_cleaner/version.rb +1 -1
- metadata +4 -2
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Thomas Drake-Brockman
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
= AttrCleaner
|
2
|
+
|
3
|
+
Cleans up your model attributes. Strips leading and trailing space, and turns empty strings into nil. Only supports Rails 3.
|
4
|
+
|
5
|
+
== Installing
|
6
|
+
|
7
|
+
Add this to your Gemfile:
|
8
|
+
|
9
|
+
gem "attr_cleaner"
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
Simply add this to any model you want to clean:
|
14
|
+
|
15
|
+
attr_cleaner
|
16
|
+
|
17
|
+
You can restrict the cleaning to specific attributes with `:only` and `:except`
|
18
|
+
|
19
|
+
attr_cleaner :only => :name
|
20
|
+
attr_cleaner :only => [:name, :age]
|
21
|
+
attr_cleaner :except => :age
|
22
|
+
attr_cleaner :except => [:age, :price]
|
23
|
+
|
24
|
+
Attributes to be cleaned can be inherited, so sometimes you may need both :only and :except
|
25
|
+
|
26
|
+
# Remove :age from the list, add :name
|
27
|
+
attr_cleaner :only => :name, :except => :age
|
28
|
+
|
29
|
+
== Copyright
|
30
|
+
|
31
|
+
Copyright (c) 2010 Thomas Drake-Brockman. See LICENSE for details.
|
@@ -15,7 +15,12 @@ module AttrCleaner
|
|
15
15
|
write_attribute_without_cleaner(attr_name, value)
|
16
16
|
end
|
17
17
|
|
18
|
-
module ClassMethods
|
18
|
+
module ClassMethods
|
19
|
+
# Adds attributes to the list of attributes to be cleaned
|
20
|
+
# Attributes are inherited, but can be removed from :except
|
21
|
+
#
|
22
|
+
# @param [Hash] args options hash, set :only and/or :except
|
23
|
+
# @return [Array] a array of symbols representing the attributes to be cleaned
|
19
24
|
def attr_cleaner(args = {})
|
20
25
|
all_columns = column_names.map(&:to_sym)
|
21
26
|
|
data/lib/attr_cleaner/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Thomas Drake-Brockman
|
@@ -30,6 +30,8 @@ extra_rdoc_files: []
|
|
30
30
|
files:
|
31
31
|
- .gitignore
|
32
32
|
- Gemfile
|
33
|
+
- LICENSE
|
34
|
+
- README.rdoc
|
33
35
|
- Rakefile
|
34
36
|
- attr_cleaner.gemspec
|
35
37
|
- lib/attr_cleaner.rb
|