attr_cleaner 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13fd121c241acea325b5ab89c95aefdaabc91a22
4
- data.tar.gz: f4dd8fca1416c874e971899ab4559a62717a1beb
3
+ metadata.gz: a648298a58351a7c51cdc84c70a7dc82d18d5dba
4
+ data.tar.gz: b95bc98b3b3d6d3d5e9a60afb18d6d5e6bb2a595
5
5
  SHA512:
6
- metadata.gz: 02dbd6aab1d253c9a137e03a6edeed70b0f76242b8c5af4cb737173b4da15cdb7bba2c343fcb1f9fb6c09ecade4651ad0e19de7a52f4d47b11b78d3a4faa7d75
7
- data.tar.gz: b0206eee8379393eb280f870ea2748933483ccfe87c2bb81804d464e89b825dea011abea2ec12566cbd2f7e7a70294c1f99a575bd71f37a87128d3394be98202
6
+ metadata.gz: 3bcae6cf34caa84c58f0a9593ec45d7d5174650a054177537ac2467c7b255ba111988eb6ab23d48552e7eb3e9e31ee58fe503382e79fa53ab6d2c31291e055c7
7
+ data.tar.gz: bc129d4fb179183f7004c9c8c568d7e2afd25f94909cd2feb56382301dcff87bec388704fb47344affd05c6ffd0353450bda879424239d04882d6c7a89324d33
@@ -1 +1 @@
1
- ruby-2.3.3
1
+ ruby-2.4.3
@@ -9,16 +9,20 @@ env:
9
9
 
10
10
  rvm:
11
11
  - 1.9.3
12
- - 2.3.3
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
@@ -1,4 +1,4 @@
1
- ["4.2", "5.0"].each do |rails|
1
+ ["4.2", "5.0", "5.1"].each do |rails|
2
2
  appraise "rails-#{rails}" do
3
3
  gem "activerecord", "~> #{rails}", require: "active_record"
4
4
  end
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.0.
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 add this to any model you want to clean:
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
- You can restrict the cleaning to specific attributes with `:only` and `:except`:
26
+ Child models will inherit the attribute writers from their parent.
41
27
 
42
- ```ruby
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
- Settings are be inherited, so sometimes you may need both `:only` and `:except`:
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
- # Remove :age from the list, add :name
53
- attr_cleaner only: :name, except: :age
35
+ include AttrCleaner::Model
54
36
  ```
55
37
 
56
38
  ## Copyright
57
39
 
58
- Copyright © 2010 Thomas Drake-Brockman
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 => "../"
@@ -1,24 +1,23 @@
1
1
  module AttrCleaner
2
2
  module Model
3
3
  extend ActiveSupport::Concern
4
-
5
- included do
6
- alias_method_chain :write_attribute, :cleaner
7
- class_attribute :attr_cleaners
8
- end
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
- write_attribute_without_cleaner(attr_name, value)
17
- end
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
- module ClassMethods
20
- def attr_cleaner(*columns)
21
- self.attr_cleaners = columns
19
+ super(value)
20
+ end
22
21
  end
23
22
  end
24
23
  end
@@ -1,3 +1,3 @@
1
1
  module AttrCleaner
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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.0.0
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: 2016-12-29 00:00:00.000000000 Z
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.5.2
72
+ rubygems_version: 2.6.14
72
73
  signing_key:
73
74
  specification_version: 4
74
75
  summary: Cleans up model attributes.