stripper-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.travis.yml +7 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +67 -0
- data/Rakefile +1 -0
- data/lib/stripper-rails.rb +6 -0
- data/lib/stripper/rails.rb +19 -0
- data/lib/stripper/rails/orm/active_record.rb +1 -0
- data/lib/stripper/rails/orm/mongoid.rb +1 -0
- data/lib/stripper/rails/version.rb +13 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/stripper_spec.rb +38 -0
- data/stripper-rails.gemspec +26 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2460b610f96ff1b7b6cc2831264967fe96b1f08c
|
4
|
+
data.tar.gz: 24d55354cfa5059aed62c6d19080dd6fcf659474
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a05e8ce84404394277d757100db752ea9329ce6e984290436340d609ce2e3d0050322085f7cc4166cd458f38ebe86a6e347b3868750295df74926b09f70bc4a1
|
7
|
+
data.tar.gz: eae2be96c290c2bdd4fd3edf7c0fa224048c69c81dda55c50b2f7c6ef20a0f629994d616a0a4234598a28cdc68130fd78b5347cea64774f0409a008e60d150fc
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Kuldeep Aggarwal
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
Stripper::Rails [![Build Status](https://travis-ci.org/kuldeepaggarwal/stripper-rails.png?branch=master)](https://travis-ci.org/kuldeepaggarwal/stripper-rails)
|
2
|
+
-------
|
3
|
+
|
4
|
+
An utility which provides a class method `strip_fields`. It accepts list of fields and removes leading and trailing whitespaces before validation.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
-------
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```shell
|
12
|
+
gem 'stripper-rails', '~> 0.0.1'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```shell
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```shell
|
24
|
+
$ gem install stripper-rails
|
25
|
+
```
|
26
|
+
|
27
|
+
Usage
|
28
|
+
-------
|
29
|
+
|
30
|
+
For _ActiveRecord:_
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
class User < ActiveRecord::Base
|
34
|
+
|
35
|
+
strip_fields :first_name
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
For _Mongoid:_
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
class Article
|
43
|
+
include Mongoid::Document
|
44
|
+
|
45
|
+
strip_fields :name
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
Testing
|
50
|
+
-------
|
51
|
+
|
52
|
+
```shell
|
53
|
+
$ bundle
|
54
|
+
$ bundle exec rspec spec
|
55
|
+
```
|
56
|
+
|
57
|
+
Contributing
|
58
|
+
-------
|
59
|
+
|
60
|
+
```
|
61
|
+
1. Fork it ( https://github.com/kuldeepaggarwal/stripper-rails/fork ).
|
62
|
+
2. Create your feature branch (`git checkout -b my-new-feature`).
|
63
|
+
3. Add test cases and verify all tests are green.
|
64
|
+
4. Commit your changes (`git commit -am 'Add some feature'`).
|
65
|
+
5. Push to the branch (`git push origin my-new-feature`).
|
66
|
+
6. Create new Pull Request.
|
67
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Stripper
|
2
|
+
module Rails
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
# Add before_validation callback for each field passed in field_list
|
7
|
+
# the before_validation callback will remove trailing and preceding spaces upon valid call.
|
8
|
+
def strip_fields(*field_list)
|
9
|
+
before_validation do |object|
|
10
|
+
field_list.each do |field|
|
11
|
+
object.respond_to?(field) &&
|
12
|
+
object.public_send(field).respond_to?(:strip!) &&
|
13
|
+
object.public_send(field).strip!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
ActiveRecord::Base.send :include, ::Stripper::Rails
|
@@ -0,0 +1 @@
|
|
1
|
+
Mongoid::Document.send :include, ::Stripper::Rails
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require_relative '../lib/stripper-rails'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Run specs in random order to surface order dependencies. If you find an
|
6
|
+
# order dependency and want to debug it, you can fix the order by providing
|
7
|
+
# the seed, which is printed after each run.
|
8
|
+
# --seed 1234
|
9
|
+
config.order = 'random'
|
10
|
+
|
11
|
+
# force rspec to raise exception if used old syntax.
|
12
|
+
config.raise_errors_for_deprecations!
|
13
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestStripper
|
4
|
+
include ::ActiveModel::Validations
|
5
|
+
include ::ActiveModel::Validations::Callbacks
|
6
|
+
include ::Stripper::Rails
|
7
|
+
|
8
|
+
attr_accessor :name, :email
|
9
|
+
|
10
|
+
def initialize(attributes = {})
|
11
|
+
attributes.each { |attribute, value| self.public_send("#{ attribute }=", value) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe TestStripper do
|
16
|
+
describe '.strip_fields' do
|
17
|
+
let(:test_stripper) { TestStripper.new(name: 'kd ', email: ' kd.engineer@yahoo.co.in ') }
|
18
|
+
before { TestStripper.reset_callbacks(:validation) }
|
19
|
+
|
20
|
+
context 'when no parameters are passed' do
|
21
|
+
it 'does not strip any attribute' do
|
22
|
+
TestStripper.strip_fields
|
23
|
+
test_stripper.valid?
|
24
|
+
expect(test_stripper.name).to eq 'kd '
|
25
|
+
expect(test_stripper.email).to eq ' kd.engineer@yahoo.co.in '
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when parameters are passed' do
|
30
|
+
it 'strips parameters list' do
|
31
|
+
TestStripper.strip_fields :name, :email
|
32
|
+
test_stripper.valid?
|
33
|
+
expect(test_stripper.name).to eq 'kd'
|
34
|
+
expect(test_stripper.email).to eq 'kd.engineer@yahoo.co.in'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'stripper/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'stripper-rails'
|
8
|
+
spec.version = Stripper::Rails::VERSION
|
9
|
+
spec.authors = ['Kuldeep Aggarwal']
|
10
|
+
spec.email = ['kd.engineer@yahoo.co.in']
|
11
|
+
spec.summary = "An utility which provides a class method `strip_fields`. It accepts list of fields and removes leading and trailing whitespaces before validation."
|
12
|
+
spec.description = "An utility which provides a class method `strip_fields`. It accepts list of fields and removes leading and trailing whitespaces before validation."
|
13
|
+
spec.homepage = 'https://github.com/kuldeepaggarwal/stripper-rails'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'activemodel'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.5.2'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0.0.beta2'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.1.1'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stripper-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kuldeep Aggarwal
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.5.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.5.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0.beta2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0.beta2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 10.1.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 10.1.1
|
69
|
+
description: An utility which provides a class method `strip_fields`. It accepts list
|
70
|
+
of fields and removes leading and trailing whitespaces before validation.
|
71
|
+
email:
|
72
|
+
- kd.engineer@yahoo.co.in
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/stripper-rails.rb
|
84
|
+
- lib/stripper/rails.rb
|
85
|
+
- lib/stripper/rails/orm/active_record.rb
|
86
|
+
- lib/stripper/rails/orm/mongoid.rb
|
87
|
+
- lib/stripper/rails/version.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
- spec/stripper_spec.rb
|
90
|
+
- stripper-rails.gemspec
|
91
|
+
homepage: https://github.com/kuldeepaggarwal/stripper-rails
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.1
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: An utility which provides a class method `strip_fields`. It accepts list
|
115
|
+
of fields and removes leading and trailing whitespaces before validation.
|
116
|
+
test_files:
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- spec/stripper_spec.rb
|