Module: FeedTools::GenericHelper

Defined in:
lib/feed_tools/helpers/generic_helper.rb

Overview

Generic methods needed in numerous places throughout FeedTools

Class Method Summary collapse

Class Method Details

.recursion_trap(lock_object, &block) ⇒ Object

Nifty little method that takes a block and returns nil if recursion occurs or the block’s result value if it doesn’t.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/feed_tools/helpers/generic_helper.rb', line 40

def self.recursion_trap(lock_object, &block)
  if @lock_ids.nil?
    @lock_ids = []
  end
  if !@lock_ids.include?(lock_object.object_id)
    @lock_ids << lock_object.object_id
  else
    return nil
  end
  begin
    result = block.call
  rescue SystemStackError
    result = nil
  end
  @lock_ids.delete(lock_object.object_id)
  return result
end

.validate_options(valid_option_keys, supplied_option_keys) ⇒ Object

Raises an exception if an invalid option has been specified to prevent misspellings from slipping through



31
32
33
34
35
36
# File 'lib/feed_tools/helpers/generic_helper.rb', line 31

def self.validate_options(valid_option_keys, supplied_option_keys)
  unknown_option_keys = supplied_option_keys - valid_option_keys
  unless unknown_option_keys.empty?
    raise "Unknown options: #{unknown_option_keys}"
  end
end