Class: Synchronisable::AttributeMapper
- Defined in:
- lib/synchronisable/attribute_mapper.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(mappings, options = {}) ⇒ AttributeMapper
constructor
A new instance of AttributeMapper.
- #map(source) ⇒ Object
Constructor Details
#initialize(mappings, options = {}) ⇒ AttributeMapper
Returns a new instance of AttributeMapper.
9 10 11 12 13 |
# File 'lib/synchronisable/attribute_mapper.rb', line 9 def initialize(mappings, = {}) @mappings = mappings @keep = [:keep] || [] @only, @except = [:only], [:except] end |
Class Method Details
.map(source, mappings, options = {}) ⇒ Object
4 5 6 |
# File 'lib/synchronisable/attribute_mapper.rb', line 4 def map(source, mappings, = {}) new(mappings, ).map(source) end |
Instance Method Details
#map(source) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/synchronisable/attribute_mapper.rb', line 15 def map(source) result = source.dup apply_mappings(result) if @mappings.present? apply_only(result) if @only.present? apply_except(result) if @except.present? result end |