attributes_sanitizer 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/attributes_sanitizer.rb +2 -34
- data/lib/attributes_sanitizer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9b5cdacf4202a91b8cdddfb2e19e2e5eef002fef133e9cb24f7a78156d3123b
|
4
|
+
data.tar.gz: c5f983d0ff25b68db3963bcef1d1b55092de84326e9877a6d06d96bc4ef8b852
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5287f32e464059803785667477d599ebc9fb8017e8ddc9b603697e9349be3c29d38afe35e4227aeba7521dac8082ea761732dfeb81a9621ac2969a3825cfd1c6
|
7
|
+
data.tar.gz: 2192b362fa17029e8559e1fcaba5c37351d5865e577e06c740f24e302e525abc743465dde27fc97723668af9599ffce6ea64e385da163625e6457044ef57c509
|
data/lib/attributes_sanitizer.rb
CHANGED
@@ -4,46 +4,14 @@ require "attributes_sanitizer/concern"
|
|
4
4
|
require "attributes_sanitizer/overrider"
|
5
5
|
require "attributes_sanitizer/predefined"
|
6
6
|
|
7
|
-
#
|
8
|
-
# Attributes sanitizer for Rails
|
9
|
-
#
|
10
|
-
# A simple way to append sanitizers to attributes on Rails.
|
11
|
-
#
|
12
|
-
# ```ruby
|
13
|
-
# class Product < ApplicationRecord
|
14
|
-
# extend AttributesSanitizer::Concern
|
15
|
-
#
|
16
|
-
# sanitize_attribute :title, with: -> (value) {
|
17
|
-
# value.gsub(/[1-9]/, 'X')
|
18
|
-
# }
|
19
|
-
#
|
20
|
-
# sanitize_attributes :title, :description, with: [:downcase, :strip_tags]
|
21
|
-
# end
|
22
|
-
# ```
|
23
|
-
#
|
24
|
-
# It comes with pre-defined sanitizers:
|
25
|
-
# - `:downcase` which downcases a given attribute string
|
26
|
-
# - `:upcase` which upcases a given attribute string
|
27
|
-
# - `:strip_tags` which removes any tags from the given string based on Rails sanitize helper.
|
28
|
-
# - `:strip_emojis` which removes any emoji from the given string
|
29
|
-
# - `:strip_spaces` which removes any white spaces from the beginning and end of given attribute
|
30
|
-
#
|
31
|
-
# You might define your own sanitizers:
|
32
|
-
#
|
33
|
-
# ```ruby
|
34
|
-
# # config/initializers/attribute_sanitizers.rb
|
35
|
-
#
|
36
|
-
# AttributesSanitizer.define_sanitizer :reverse do |value|
|
37
|
-
# value.to_s.reverse
|
38
|
-
# end
|
39
|
-
# ```
|
40
7
|
module AttributesSanitizer
|
41
8
|
EMOJI_REGEX = /[^\u0000-\u00FF]/
|
42
9
|
|
43
|
-
|
10
|
+
mattr_accessor :sanitizers
|
44
11
|
self.sanitizers = {}
|
45
12
|
|
46
13
|
def self.define_sanitizer(sanitizer_name, &block)
|
14
|
+
raise ArgumentError, 'sanitizer needs a block' unless block_given?
|
47
15
|
self.sanitizers[sanitizer_name.to_sym] = block
|
48
16
|
end
|
49
17
|
|