Module: DataCleansing
- Includes:
- SemanticLogger::Loggable
- Defined in:
- lib/data_cleansing.rb,
lib/data_cleansing/cleanse.rb,
lib/data_cleansing/version.rb,
lib/data_cleansing/data_cleansing.rb
Defined Under Namespace
Modules: Cleanse
Constant Summary collapse
- VERSION =
"1.0.3"
- @@global_cleaners =
Global Data Cleansers
Concurrent::Hash.new
- @@masked_attributes =
Concurrent::Array.new
Class Method Summary collapse
-
.clean(name, value, params = nil, binding = nil) ⇒ Object
Run the specified cleanser against the supplied value.
-
.cleaner(cleaner_name) ⇒ Object
Returns the cleaner matching the supplied cleaner name.
-
.masked_attributes ⇒ Object
Returns the Global list of attributes to mask in any log output.
-
.register_cleaner(name, cleaner = nil, &block) ⇒ Object
Register a new cleaner Replaces any existing cleaner with the same name.
-
.register_masked_attributes(*attributes) ⇒ Object
Register Attributes to be masked out in any log output.
Class Method Details
.clean(name, value, params = nil, binding = nil) ⇒ Object
Run the specified cleanser against the supplied value
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/data_cleansing/data_cleansing.rb', line 32 def self.clean(name, value, params = nil, binding = nil) # Cleaner itself could be a custom Proc, otherwise do a global lookup for it proc = name.is_a?(Proc) ? name : DataCleansing.cleaner(name.to_sym) raise(ArgumentError, "No cleaner defined for #{name.inspect}") unless proc if proc.is_a?(Proc) if binding # Call the cleaner proc within the scope (binding) of the binding proc.arity == 1 ? binding.instance_exec(value, &proc) : binding.instance_exec(value, params, &proc) else proc.arity == 1 ? proc.call(value) : proc.call(value, params) end else (proc.method(:call).arity == 1 ? proc.call(value) : proc.call(value, params)) end end |
.cleaner(cleaner_name) ⇒ Object
Returns the cleaner matching the supplied cleaner name
17 18 19 |
# File 'lib/data_cleansing/data_cleansing.rb', line 17 def self.cleaner(cleaner_name) @@global_cleaners[cleaner_name.to_sym] end |
.masked_attributes ⇒ Object
Returns the Global list of attributes to mask in any log output
27 28 29 |
# File 'lib/data_cleansing/data_cleansing.rb', line 27 def self.masked_attributes @@masked_attributes.freeze end |
.register_cleaner(name, cleaner = nil, &block) ⇒ Object
Register a new cleaner Replaces any existing cleaner with the same name
10 11 12 13 14 |
# File 'lib/data_cleansing/data_cleansing.rb', line 10 def self.register_cleaner(name, cleaner = nil, &block) raise "Must supply a Proc with the cleaner" unless block || cleaner @@global_cleaners[name.to_sym] = cleaner || block end |
.register_masked_attributes(*attributes) ⇒ Object
Register Attributes to be masked out in any log output
22 23 24 |
# File 'lib/data_cleansing/data_cleansing.rb', line 22 def self.register_masked_attributes(*attributes) attributes.each { |attr| @@masked_attributes << attr.to_sym } end |