Class: DbSeeder::Sanitizer
- Inherits:
-
Object
- Object
- DbSeeder::Sanitizer
- Defined in:
- lib/db_seeder/sanitizer.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ Sanitizer
constructor
A new instance of Sanitizer.
- #sanitize(model, attributes) ⇒ Object
Constructor Details
#initialize(config) ⇒ Sanitizer
Returns a new instance of Sanitizer.
7 8 9 |
# File 'lib/db_seeder/sanitizer.rb', line 7 def initialize(config) @rules = config.sanitize_rules || {} end |
Instance Method Details
#sanitize(model, attributes) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/db_seeder/sanitizer.rb', line 11 def sanitize(model, attributes) model_key = model_config_key(model) model_rules = @rules[model_key] || {} attributes.each_with_object({}) do |(key, value), result| rule = model_rules[key.to_sym] result[key] = apply_rule(rule, value) end end |