sanitize_model_attributes 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 +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +2 -0
- data/lib/sanitize_model_attributes.rb +25 -0
- data/lib/sanitize_model_attributes/version.rb +3 -0
- data/sanitize_model_attributes.gemspec +22 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 22b79f12d24ca0e4f9a8876b2735c3ad29824dc3
|
4
|
+
data.tar.gz: f280e2f14e77d514e934759f81f17b69e0f07149
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d338c4452928e2be3725455f5aaf6b26f4e66bb5a7b04b89f303e525b1e50831b87051f0f360912f82d720aa2a1aaff34b7a0db25f41a53e25e98fa059eb7415
|
7
|
+
data.tar.gz: a3f682760feeb87533801d0935a3c899249ffe0551d57046c034a1df50086f8c5de72307bb9c0d4e1bb44d4ea4c9a2fb77edaa1fd58c8b86ffe04471d258a7dc
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Takashi CHIBA
|
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,55 @@
|
|
1
|
+
# SanitizeModelAttributes
|
2
|
+
|
3
|
+
Sanitize ActiveRecord attributes.
|
4
|
+
This gem depends on [sanitize](https://github.com/rgrove/sanitize) gem.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'sanitize_model_attributes'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install sanitize_model_attributes
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Before
|
25
|
+
|
26
|
+
```
|
27
|
+
class Tree < ActiveRecord::Base
|
28
|
+
end
|
29
|
+
|
30
|
+
tree = Tree.new
|
31
|
+
tree.name = '<string>hogehoge</strong>'
|
32
|
+
p tree.name #=> "<string>hogehoge</strong>"
|
33
|
+
```
|
34
|
+
|
35
|
+
### After
|
36
|
+
|
37
|
+
```
|
38
|
+
class Tree < ActiveRecord::Base
|
39
|
+
include SanitizeModelAttributes
|
40
|
+
|
41
|
+
sanitize_attributes :name
|
42
|
+
end
|
43
|
+
|
44
|
+
tree = Tree.new
|
45
|
+
tree.name = '<string>hogehoge</strong>'
|
46
|
+
p tree.name #=> "strong"
|
47
|
+
```
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( https://github.com/tachiba/sanitize_model_attributes/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "sanitize_model_attributes/version"
|
2
|
+
|
3
|
+
module SanitizeModelAttributes
|
4
|
+
def included(base)
|
5
|
+
class << base
|
6
|
+
include ClassMethods
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def sanitize_attributes(*args)
|
12
|
+
args.each do |attribute_name|
|
13
|
+
self.class_eval do
|
14
|
+
define_method "#{attribute_name}=".to_sym do |attribute_value|
|
15
|
+
write_attribute attribute_name.to_sym, Sanitize.fragment(attribute_value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def sanitize_model_attributes(*args)
|
22
|
+
sanitize_attributes(*args)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sanitize_model_attributes/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sanitize_model_attributes"
|
8
|
+
spec.version = SanitizeModelAttributes::VERSION
|
9
|
+
spec.authors = ["Takashi CHIBA"]
|
10
|
+
spec.email = ["mail@takashi.me"]
|
11
|
+
spec.summary = %q{Sanitize ActiveRecord attributes.}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = "https://github.com/tachiba/sanitize_model_attributes"
|
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_development_dependency "sanitize", "~> 3"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sanitize_model_attributes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takashi CHIBA
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sanitize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
description: ''
|
28
|
+
email:
|
29
|
+
- mail@takashi.me
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- lib/sanitize_model_attributes.rb
|
40
|
+
- lib/sanitize_model_attributes/version.rb
|
41
|
+
- sanitize_model_attributes.gemspec
|
42
|
+
homepage: https://github.com/tachiba/sanitize_model_attributes
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.4.3
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Sanitize ActiveRecord attributes.
|
66
|
+
test_files: []
|