Class: Synchronisable::AttributeMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/synchronisable/attribute_mapper.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mappings, options = {}) ⇒ AttributeMapper


9
10
11
12
13
# File 'lib/synchronisable/attribute_mapper.rb', line 9

def initialize(mappings, options = {})
  @mappings = mappings
  @keep = options[:keep] || []
  @only, @except = options[:only], options[: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, options = {})
  new(mappings, options).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