Class: Audiences::Scim::FieldMapping

Inherits:
Object
  • Object
show all
Defined in:
lib/audiences/scim/field_mapping.rb

Instance Method Summary collapse

Constructor Details

#initialize(mapping) ⇒ FieldMapping

Returns a new instance of FieldMapping.



6
7
8
# File 'lib/audiences/scim/field_mapping.rb', line 6

def initialize(mapping)
  @map = mapping
end

Instance Method Details

#add(object, path, val) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/audiences/scim/field_mapping.rb', line 22

def add(object, path, val)
  return unless @map.key?(path)

  case @map[path]
  in { to: to, find: find }
    add_to_association(object, to, find, val)
  else
    current = object.send to(path)
    _set object, path, current + value(path, val)
  end
end

#remove(object, path, val) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/audiences/scim/field_mapping.rb', line 10

def remove(object, path, val)
  return unless @map.key?(path)

  case @map[path]
  in { to: to, find: find }
    remove_from_association(object, to, find, val)
  else
    current = object.send to(path)
    _set object, path, current - value(path, val)
  end
end

#replace(object, path, val) ⇒ Object



34
35
36
# File 'lib/audiences/scim/field_mapping.rb', line 34

def replace(object, path, val)
  _set object, path, value(path, val)
end