active_record_sanitize_attributes 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 842f30a922ff91ee62e39a58b9cf2c74821d033f
4
+ data.tar.gz: 95c9a31746e69cfd5fd364775c321c46c1dc7989
5
+ SHA512:
6
+ metadata.gz: 26a0b6906eb2a1afcc3f31bf9996f87b73aeb52778a98559dd83dbfa6e40c6287604cf0a6931be0400b18c44d78af29900f83e4ea9a46a83940b27be9b39f61c
7
+ data.tar.gz: 7e586060b3303832b5f287993ab08b067de6ef32eb355166ad42ced3b705b7971e6ef2f59cfec7a16f2b8df0fa9e94b09762172e9523e61c63a5367b92b56c9b
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Prokop Simek
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.
@@ -0,0 +1,47 @@
1
+ # SanitizeAttributes
2
+ Rails gem to sanitize attributes in write & read methods.
3
+
4
+ ## Usage
5
+ In your model do e.g.:
6
+ ```ruby
7
+ sanitize_attributes :short_description
8
+ ```
9
+ and from attribute `short_description` will be removed tags as defined in your config
10
+
11
+ ## Installation
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'active_record_sanitize_attributes'
16
+ ```
17
+
18
+ And then execute:
19
+ ```bash
20
+ $ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+ ```bash
25
+ $ gem install active_record_sanitize_attributes
26
+ ```
27
+
28
+ ## Configuration
29
+
30
+ You don't need to configure anything, but if you want to customize the behaviour, use the following snippet:
31
+
32
+ create file `initializers/sanitize_attributes.rb`
33
+
34
+ ```ruby
35
+ SanitizeAttributes.configure do |config|
36
+ config.keep_elements = %w(h1 h2 h3 p pre b i u br) # default value
37
+ end
38
+ ```
39
+
40
+ ## Using
41
+ [gem Sanitize](https://github.com/rgrove/sanitize)
42
+
43
+ ## Contributing
44
+ Contribution directions go here.
45
+
46
+ ## License
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,26 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
3
+
4
+ begin
5
+ require 'bundler/setup'
6
+ rescue LoadError
7
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
8
+ end
9
+
10
+ require 'rdoc/task'
11
+
12
+ RDoc::Task.new(:rdoc) do |rdoc|
13
+ rdoc.rdoc_dir = 'rdoc'
14
+ rdoc.title = 'SanitizeAttributes'
15
+ rdoc.options << '--line-numbers'
16
+ rdoc.rdoc_files.include('README.md')
17
+ rdoc.rdoc_files.include('lib/**/*.rb')
18
+ end
19
+
20
+
21
+
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
@@ -0,0 +1,39 @@
1
+ require 'active_record'
2
+ require 'active_record/version'
3
+ require 'active_support/core_ext/module'
4
+
5
+ require 'sanitize'
6
+ require 'sanitize_attributes/version'
7
+ require 'sanitize_attributes/configuration'
8
+ require 'sanitize_attributes/sanitizable'
9
+
10
+ begin
11
+ require 'rails/engine'
12
+ require 'sanitize_attributes/engine'
13
+ rescue LoadError
14
+ end
15
+
16
+ module SanitizeAttributes
17
+
18
+ extend ActiveSupport::Autoload
19
+
20
+ autoload :Sanitizable
21
+
22
+ class << self
23
+ def configuration
24
+ @configuration ||= Configuration.new
25
+ end
26
+
27
+ def reset
28
+ @configuration = Configuration.new
29
+ end
30
+
31
+ def configure
32
+ yield(configuration)
33
+ end
34
+ end
35
+
36
+ ActiveSupport.on_load(:active_record) do
37
+ extend SanitizeAttributes::Sanitizable
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ module SanitizeAttributes
2
+ class Configuration
3
+ attr_accessor :keep_elements
4
+
5
+ def initialize
6
+ @keep_elements = %w(h1 h2 h3 p pre b i u br)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ module SanitizeAttributes
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,25 @@
1
+ module SanitizeAttributes
2
+ module Sanitizable
3
+
4
+ class_eval do
5
+ def sanitize_attributes(*attrs)
6
+ attrs.each do |attr|
7
+ define_method attr do
8
+ safe_sanitize attribute(attr)
9
+ end
10
+
11
+ define_method "#{attr}=" do |val|
12
+ write_attribute attr, safe_sanitize(val)
13
+ end
14
+
15
+ define_method "safe_sanitize" do |text|
16
+ Sanitize
17
+ .fragment(text, elements: SanitizeAttributes.configuration.keep_elements)
18
+ .strip
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module SanitizeAttributes
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_record_sanitize_attributes
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Prokop Simek
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Rails gem to sanitize attributes in write & read methods.
98
+ email:
99
+ - prokop.simek@applifting.cz
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - MIT-LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - lib/sanitize_attributes.rb
108
+ - lib/sanitize_attributes/configuration.rb
109
+ - lib/sanitize_attributes/engine.rb
110
+ - lib/sanitize_attributes/sanitizable.rb
111
+ - lib/sanitize_attributes/version.rb
112
+ homepage: https://github.com/prokopsimek/sanitize_attributes
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 2.0.0
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.5.1
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Rails gem to sanitize attributes in write & read methods.
136
+ test_files: []