attr_cleaner 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +5 -1
- data/Appraisals +1 -1
- data/README.md +12 -30
- data/gemfiles/rails_5.1.gemfile +14 -0
- data/lib/attr_cleaner/model.rb +14 -15
- data/lib/attr_cleaner/version.rb +1 -1
- data/spec/attr_cleaner/model_spec.rb +0 -8
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a648298a58351a7c51cdc84c70a7dc82d18d5dba
|
4
|
+
data.tar.gz: b95bc98b3b3d6d3d5e9a60afb18d6d5e6bb2a595
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bcae6cf34caa84c58f0a9593ec45d7d5174650a054177537ac2467c7b255ba111988eb6ab23d48552e7eb3e9e31ee58fe503382e79fa53ab6d2c31291e055c7
|
7
|
+
data.tar.gz: bc129d4fb179183f7004c9c8c568d7e2afd25f94909cd2feb56382301dcff87bec388704fb47344affd05c6ffd0353450bda879424239d04882d6c7a89324d33
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.4.3
|
data/.travis.yml
CHANGED
@@ -9,16 +9,20 @@ env:
|
|
9
9
|
|
10
10
|
rvm:
|
11
11
|
- 1.9.3
|
12
|
-
- 2.
|
12
|
+
- 2.4.3
|
13
|
+
- 2.5.0
|
13
14
|
|
14
15
|
gemfile:
|
15
16
|
- gemfiles/rails_4.2.gemfile
|
16
17
|
- gemfiles/rails_5.0.gemfile
|
18
|
+
- gemfiles/rails_5.1.gemfile
|
17
19
|
|
18
20
|
matrix:
|
19
21
|
exclude:
|
20
22
|
- rvm: 1.9.3
|
21
23
|
gemfile: gemfiles/rails_5.0.gemfile
|
24
|
+
- rvm: 1.9.3
|
25
|
+
gemfile: gemfiles/rails_5.1.gemfile
|
22
26
|
|
23
27
|
before_install: gem update bundler
|
24
28
|
bundler_args: --without tools
|
data/Appraisals
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# AttrCleaner
|
2
2
|
|
3
|
+
[![Travis CI](https://travis-ci.org/thomasfedb/attr_cleaner.svg?branch=master)](https://travis-ci.org/thomasfedb/attr_cleaner)
|
4
|
+
|
3
5
|
Cleans up your model attributes. Strips leading and trailing space, and turns
|
4
6
|
empty strings into `nil`.
|
5
7
|
|
6
|
-
Tested against Rails 4.2 and 5.
|
7
|
-
|
8
|
-
![Travis CI](https://travis-ci.org/thomasfedb/attr_cleaner.svg?branch=master)
|
8
|
+
Tested against Rails 4.2, 5.0, and 5.1.
|
9
9
|
|
10
10
|
## Install
|
11
11
|
|
@@ -15,44 +15,26 @@ If you're using Rails with ActiveRecord all you need to do is:
|
|
15
15
|
gem "attr_cleaner"
|
16
16
|
```
|
17
17
|
|
18
|
-
AttrCleaner will also work with any ORM that writes attributes via a method
|
19
|
-
called `write_attribute`.
|
20
|
-
|
21
|
-
To get AttrCleaner working with your ORM just include it into your models:
|
22
|
-
|
23
|
-
```ruby
|
24
|
-
include AttrCleaner::Model
|
25
|
-
```
|
26
|
-
|
27
|
-
AttrCleaner can also be used outside of Rails if ActiveSupport 3 is avalable.
|
28
|
-
If you're using AttrCleaner outside of Rails, and it detects ActiveRecord is
|
29
|
-
allready loaded, it will include itself into ActiveRecod. Make sure ActiveRecord
|
30
|
-
is loaded first.
|
31
|
-
|
32
18
|
## Usage
|
33
19
|
|
34
|
-
Simply
|
20
|
+
Simply pass a list of attributes that you want to clean:
|
35
21
|
|
36
22
|
```ruby
|
37
|
-
attr_cleaner
|
23
|
+
attr_cleaner :title, :body
|
38
24
|
```
|
39
25
|
|
40
|
-
|
26
|
+
Child models will inherit the attribute writers from their parent.
|
41
27
|
|
42
|
-
|
43
|
-
attr_cleaner only: :name
|
44
|
-
attr_cleaner only: [:name, :age]
|
45
|
-
attr_cleaner except: :age
|
46
|
-
attr_cleaner except: [:age, :price]
|
47
|
-
```
|
28
|
+
## Other ORMs
|
48
29
|
|
49
|
-
|
30
|
+
AttrCleaner works by generating attribute setters and should work with most ORMs.
|
31
|
+
|
32
|
+
To get AttrCleaner working with your ORM just include it into your models:
|
50
33
|
|
51
34
|
```ruby
|
52
|
-
|
53
|
-
attr_cleaner only: :name, except: :age
|
35
|
+
include AttrCleaner::Model
|
54
36
|
```
|
55
37
|
|
56
38
|
## Copyright
|
57
39
|
|
58
|
-
Copyright ©
|
40
|
+
Copyright © 2018 Thomas Drake-Brockman
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "http://rubygems.org"
|
4
|
+
|
5
|
+
gem "rspec"
|
6
|
+
gem "jamjar"
|
7
|
+
gem "activerecord", "~> 5.1", :require => "active_record"
|
8
|
+
|
9
|
+
group :tools do
|
10
|
+
gem "appraisal"
|
11
|
+
gem "byebug"
|
12
|
+
end
|
13
|
+
|
14
|
+
gemspec :path => "../"
|
data/lib/attr_cleaner/model.rb
CHANGED
@@ -1,24 +1,23 @@
|
|
1
1
|
module AttrCleaner
|
2
2
|
module Model
|
3
3
|
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def write_attribute_with_cleaner(attr_name, value)
|
11
|
-
if Array(attr_cleaners).include?(attr_name.to_sym) && value.is_a?(String)
|
12
|
-
value = value.strip
|
13
|
-
value = nil if value.empty?
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def attr_cleaner(*columns)
|
7
|
+
columns.each do |column|
|
8
|
+
define_attr_cleaner(column)
|
9
|
+
end
|
14
10
|
end
|
15
11
|
|
16
|
-
|
17
|
-
|
12
|
+
def define_attr_cleaner(column)
|
13
|
+
define_method "#{column}=" do |value|
|
14
|
+
if value.is_a?(String)
|
15
|
+
value = value.strip
|
16
|
+
value = nil if value.empty?
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
self.attr_cleaners = columns
|
19
|
+
super(value)
|
20
|
+
end
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
data/lib/attr_cleaner/version.rb
CHANGED
@@ -10,14 +10,6 @@ describe AttrCleaner::Model do
|
|
10
10
|
|
11
11
|
let(:instance) { model.new }
|
12
12
|
|
13
|
-
describe ".attr_cleaner" do
|
14
|
-
context "called with attributes" do
|
15
|
-
before { model.attr_cleaner :title, :body }
|
16
|
-
|
17
|
-
specify { expect(model.attr_cleaners).to eq [:title, :body] }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
13
|
describe "#write_attribute_with_cleaner" do
|
22
14
|
context "with no cleaners" do
|
23
15
|
context "a padding string is assigned" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attr_cleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Drake-Brockman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- attr_cleaner.gemspec
|
44
44
|
- gemfiles/rails_4.2.gemfile
|
45
45
|
- gemfiles/rails_5.0.gemfile
|
46
|
+
- gemfiles/rails_5.1.gemfile
|
46
47
|
- lib/attr_cleaner.rb
|
47
48
|
- lib/attr_cleaner/model.rb
|
48
49
|
- lib/attr_cleaner/railtie.rb
|
@@ -68,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
69
|
version: '0'
|
69
70
|
requirements: []
|
70
71
|
rubyforge_project:
|
71
|
-
rubygems_version: 2.
|
72
|
+
rubygems_version: 2.6.14
|
72
73
|
signing_key:
|
73
74
|
specification_version: 4
|
74
75
|
summary: Cleans up model attributes.
|