Module: FlatMap::BaseMapper::Skipping

Included in:
FlatMap::BaseMapper
Defined in:
lib/flat_map/base_mapper/skipping.rb

Overview

This helper module provides helper functionality that allow to exclude specific mapper from a processing chain.

Instance Method Summary collapse

Instance Method Details

#saveBoolean

Override Persistence#save method to force it to return true if self is marked for skipping.

Returns:

  • (Boolean)


43
44
45
# File 'lib/flat_map/base_mapper/skipping.rb', line 43

def save
  skipped? || super
end

#shallow_saveBoolean

Override Persistence#shallow_save method to make it possible to skip traits.

Returns:

  • (Boolean)


51
52
53
# File 'lib/flat_map/base_mapper/skipping.rb', line 51

def shallow_save
  skipped? || super
end

#skip!Object

Mark self as skipped, i.e. it will not be subject of validation and saving chain.

Returns:

  • (Object)


9
10
11
# File 'lib/flat_map/base_mapper/skipping.rb', line 9

def skip!
  @_skip_processing = true
end

#skipped?Boolean

Return true if self was marked for skipping.

Returns:

  • (Boolean)


24
25
26
# File 'lib/flat_map/base_mapper/skipping.rb', line 24

def skipped?
  !!@_skip_processing
end

#use!Object

Remove “skip” mark from self and “destroyed” flag from the target.

Returns:

  • (Object)


17
18
19
# File 'lib/flat_map/base_mapper/skipping.rb', line 17

def use!
  @_skip_processing = nil
end

#valid?(context = nil) ⇒ Boolean

Override Persistence#valid? to force it to return true if self is marked for skipping.

Parameters:

  • context (Symbol) (defaults to: nil)

    useless context parameter to make it compatible with ActiveRecord models.

Returns:

  • (Boolean)


35
36
37
# File 'lib/flat_map/base_mapper/skipping.rb', line 35

def valid?(context = nil)
  skipped? || super
end

#writeObject

Mark self as used and then delegated to original Persistence#write.



57
58
59
60
# File 'lib/flat_map/base_mapper/skipping.rb', line 57

def write(*)
  use!
  super
end