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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a0c3bafdd04afef4a778d991247d32bd27537fde4c0b005b2ad0ddaee8bbbe3
4
- data.tar.gz: 9fe53322bee091b4e7a6df4e6e3fa8efe4f759c8dae69a125003450ae7ee3bbf
3
+ metadata.gz: d9b5cdacf4202a91b8cdddfb2e19e2e5eef002fef133e9cb24f7a78156d3123b
4
+ data.tar.gz: c5f983d0ff25b68db3963bcef1d1b55092de84326e9877a6d06d96bc4ef8b852
5
5
  SHA512:
6
- metadata.gz: 5c081ce4dedf43daa64700455d7fcb1e705ac6e1701bf4c3f6a575904b0e566874f5804f04c9dad7c53293ceb1eb08caba5a863562c6f27c3538f8850fefa885
7
- data.tar.gz: 3b7574ce20365ac239cfefc1ad33021f66c952e3a7b39e6e6d5caa71cc545dca08bc790a4be8800508fc1dd94fba5d8c63e4102e58e4843155fa36f33ee1c14e
6
+ metadata.gz: 5287f32e464059803785667477d599ebc9fb8017e8ddc9b603697e9349be3c29d38afe35e4227aeba7521dac8082ea761732dfeb81a9621ac2969a3825cfd1c6
7
+ data.tar.gz: 2192b362fa17029e8559e1fcaba5c37351d5865e577e06c740f24e302e525abc743465dde27fc97723668af9599ffce6ea64e385da163625e6457044ef57c509
@@ -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
- cattr_accessor :sanitizers
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
 
@@ -1,3 +1,3 @@
1
1
  module AttributesSanitizer
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attributes_sanitizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anderson Dias