Class: Schema::ModelNormalizer
- Inherits:
-
Object
- Object
- Schema::ModelNormalizer
- Defined in:
- lib/schema/model_normalizer.rb
Overview
Normalize all attributes of a model
Instance Method Summary collapse
- #add(attribute, method, options = {}) ⇒ Object
-
#initialize ⇒ ModelNormalizer
constructor
A new instance of ModelNormalizer.
- #normalize(model) ⇒ Object
Constructor Details
#initialize ⇒ ModelNormalizer
Returns a new instance of ModelNormalizer.
6 7 8 |
# File 'lib/schema/model_normalizer.rb', line 6 def initialize @attribute_normalizers = {} end |
Instance Method Details
#add(attribute, method, options = {}) ⇒ Object
10 11 12 13 |
# File 'lib/schema/model_normalizer.rb', line 10 def add(attribute, method, = {}) @attribute_normalizers[attribute] ||= AttributeNormalizer.new @attribute_normalizers[attribute].add(method, ) end |
#normalize(model) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/schema/model_normalizer.rb', line 15 def normalize(model) @attribute_normalizers.each do |attribute, attribute_normalizer| attribute_normalizer.normalize_model_attribute(model, attribute) end model end |