Module: FlatMap::OpenMapper::Skipping

Extended by:
ActiveSupport::Autoload
Included in:
FlatMap::OpenMapper
Defined in:
lib/flat_map/open_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)


47
48
49
# File 'lib/flat_map/open_mapper/skipping.rb', line 47

def save
  skipped? || super
end

#shallow_saveBoolean

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

Returns:

  • (Boolean)


55
56
57
# File 'lib/flat_map/open_mapper/skipping.rb', line 55

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)


13
14
15
# File 'lib/flat_map/open_mapper/skipping.rb', line 13

def skip!
  @_skip_processing = true
end

#skipped?Boolean

Return true if self was marked for skipping.

Returns:

  • (Boolean)


28
29
30
# File 'lib/flat_map/open_mapper/skipping.rb', line 28

def skipped?
  !!@_skip_processing
end

#use!Object

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

Returns:

  • (Object)


21
22
23
# File 'lib/flat_map/open_mapper/skipping.rb', line 21

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)


39
40
41
# File 'lib/flat_map/open_mapper/skipping.rb', line 39

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

#writeObject

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



61
62
63
64
# File 'lib/flat_map/open_mapper/skipping.rb', line 61

def write(*)
  use!
  super
end