class AttributesSanitizer::SanitizerProc
Attributes
id[R]
Public Class Methods
new(sanitizer)
click to toggle source
# File lib/attributes_sanitizer/sanitizer_proc.rb, line 8 def initialize(sanitizer) raise ArgumentError, "No sanitizer given" if sanitizer.nil? if sanitizer.is_a?(Proc) setup_lambda_proc(sanitizer) else setup_defined_proc(sanitizer) end end
Public Instance Methods
<=>(another_proc)
click to toggle source
# File lib/attributes_sanitizer/sanitizer_proc.rb, line 18 def <=>(another_proc) self.id <=> another_proc.id end
call(value)
click to toggle source
# File lib/attributes_sanitizer/sanitizer_proc.rb, line 22 def call(value) @proc.inject(value) do |value, proc| proc.call(value) end end
Private Instance Methods
setup_defined_proc(sanitizer)
click to toggle source
# File lib/attributes_sanitizer/sanitizer_proc.rb, line 35 def setup_defined_proc(sanitizer) @id = sanitizer @proc = AttributesSanitizer.bundle(sanitizer) || Array(AttributesSanitizer.find(sanitizer)) end
setup_lambda_proc(sanitizer)
click to toggle source
# File lib/attributes_sanitizer/sanitizer_proc.rb, line 30 def setup_lambda_proc(sanitizer) @proc = Array(sanitizer) @id = sanitizer.object_id end