Class: Sanitizable::AttributeSanitizer
- Inherits:
-
Object
- Object
- Sanitizable::AttributeSanitizer
- Defined in:
- lib/sanitizable/attribute_sanitizer.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sanitizer_procs ⇒ Object
readonly
Returns the value of attribute sanitizer_procs.
-
#sanitizers ⇒ Object
readonly
Returns the value of attribute sanitizers.
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ AttributeSanitizer
constructor
A new instance of AttributeSanitizer.
- #inspect ⇒ Object
- #sanitize(value) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ AttributeSanitizer
Returns a new instance of AttributeSanitizer.
5 6 7 8 9 10 |
# File 'lib/sanitizable/attribute_sanitizer.rb', line 5 def initialize(name, = {}) @name = name @sanitizers = Array([:with]) @sanitizer_procs = @sanitizers.map(&:to_proc) @context = [:on] end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/sanitizable/attribute_sanitizer.rb', line 3 def context @context end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/sanitizable/attribute_sanitizer.rb', line 3 def name @name end |
#sanitizer_procs ⇒ Object (readonly)
Returns the value of attribute sanitizer_procs.
3 4 5 |
# File 'lib/sanitizable/attribute_sanitizer.rb', line 3 def sanitizer_procs @sanitizer_procs end |
#sanitizers ⇒ Object (readonly)
Returns the value of attribute sanitizers.
3 4 5 |
# File 'lib/sanitizable/attribute_sanitizer.rb', line 3 def sanitizers @sanitizers end |
Instance Method Details
#inspect ⇒ Object
12 13 14 |
# File 'lib/sanitizable/attribute_sanitizer.rb', line 12 def inspect "#<#{self.class.name} name: #{name.inspect}, sanitizers: #{sanitizers.inspect}, context: #{context.inspect}>" end |
#sanitize(value) ⇒ Object
16 17 18 19 20 |
# File 'lib/sanitizable/attribute_sanitizer.rb', line 16 def sanitize(value) @sanitizer_procs.inject(value) do |prev_value, sanitizer_proc| sanitizer_proc.call(prev_value) end end |